Skip to content

Commit

Permalink
Merge pull request #1499 from ydb-platform/traceparent
Browse files Browse the repository at this point in the history
* Added `meta.WithTraceParent` context modifier for explicit putting traceparent header into grpc calls
  • Loading branch information
asmyasnikov authored Oct 8, 2024
2 parents 74e831e + fe2b776 commit 1cbd70c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Added `meta.WithTraceParent` context modifier for explicit putting traceparent header into grpc calls

## v3.83.0
* Supported `db.Table().BulkUpsert()` from scv, arrow and ydb rows formats

Expand Down
5 changes: 5 additions & 0 deletions internal/meta/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ func WithAllowFeatures(ctx context.Context, features ...string) context.Context

return metadata.AppendToOutgoingContext(ctx, kv...)
}

// WithTraceParent returns a copy of parent context with traceparent header
func WithTraceParent(ctx context.Context, traceparent string) context.Context {
return metadata.AppendToOutgoingContext(ctx, HeaderTraceParent, traceparent)
}
1 change: 1 addition & 0 deletions internal/meta/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
HeaderApplicationName = "x-ydb-application-name"
HeaderClientCapabilities = "x-ydb-client-capabilities"
HeaderClientPid = "x-ydb-client-pid"
HeaderTraceParent = "traceparent"

// outgoing hints
HintSessionBalancer = "session-balancer"
Expand Down
5 changes: 5 additions & 0 deletions meta/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ func WithTrailerCallback(
) context.Context {
return meta.WithTrailerCallback(ctx, callback)
}

// WithTraceParent returns a copy of parent context with traceparent header
func WithTraceParent(ctx context.Context, traceparent string) context.Context {
return meta.WithTraceParent(ctx, traceparent)
}
15 changes: 13 additions & 2 deletions tests/integration/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestConnection(sourceTest *testing.T) {
var (
userAgent = "connection user agent"
requestType = "connection request type"
traceParentID = "test-traceparent-id"
checkMetadata = func(ctx context.Context) {
md, has := metadata.FromOutgoingContext(ctx)
if !has {
Expand All @@ -66,10 +67,20 @@ func TestConnection(sourceTest *testing.T) {
t.Fatalf("no traceIDs")
}
if len(traceIDs[0]) == 0 {
t.Fatalf("no traceID")
t.Fatalf("empty traceID header")
}
traceParent := md.Get(meta.HeaderTraceParent)
if len(traceParent) == 0 {
t.Fatalf("no traceparent header")
}
if len(traceParent[0]) == 0 {
t.Fatalf("empty traceparent header")
}
if traceParent[0] != traceParentID {
t.Fatalf("unexpected traceparent header")
}
}
ctx = xtest.Context(t)
ctx = meta.WithTraceParent(xtest.Context(t), traceParentID)
)

t.RunSynced("ydb.New", func(t *xtest.SyncedTest) {
Expand Down

0 comments on commit 1cbd70c

Please sign in to comment.