Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/extension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
DdParentId ddTraceContext = "x-datadog-parent-id"
DdSpanId ddTraceContext = "x-datadog-span-id"
DdSamplingPriority ddTraceContext = "x-datadog-sampling-priority"
DdOrigin ddTraceContext = "x-datadog-origin"
DdInvocationError ddTraceContext = "x-datadog-invocation-error"
DdInvocationErrorMsg ddTraceContext = "x-datadog-invocation-error-msg"
DdInvocationErrorType ddTraceContext = "x-datadog-invocation-error-type"
Expand Down
1 change: 1 addition & 0 deletions internal/trace/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
traceIDHeader = "x-datadog-trace-id"
parentIDHeader = "x-datadog-parent-id"
samplingPriorityHeader = "x-datadog-sampling-priority"
originHeader = "x-datadog-origin"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see in this PR this header is created but could you please help me understand how this originHeader is used in the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used to set the origin in the trace context. as mentioned in this issue If the header isnt set for synthetic tests, it is missing for the check in extractTextMap in dd-trace-go (no origin, thus ErrSpanContextNotFound)

)

const (
Expand Down
7 changes: 7 additions & 0 deletions internal/trace/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ func getTraceContext(ctx context.Context, headers map[string]string) (TraceConte
samplingPriority = "1" //sampler-keep
}

// try to pull datadog origin from either headers or context
if origin, ok := headers[originHeader]; ok {
tc[originHeader] = origin
} else if origin, ok := ctx.Value(extension.DdOrigin).(string); ok {
tc[originHeader] = origin
}

tc[samplingPriorityHeader] = samplingPriority
tc[traceIDHeader] = traceID
tc[parentIDHeader] = parentID
Expand Down
27 changes: 24 additions & 3 deletions internal/trace/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func mockLambdaXRayTraceContext(ctx context.Context, traceID, parentID string, s
return context.WithValue(ctx, xray.LambdaTraceHeaderKey, headerString)
}

func mockTraceContext(traceID, parentID, samplingPriority string) context.Context {
func mockTraceContext(traceID, parentID, samplingPriority, origin string) context.Context {
ctx := context.Background()
if traceID != "" {
ctx = context.WithValue(ctx, extension.DdTraceId, traceID)
Expand All @@ -55,6 +55,9 @@ func mockTraceContext(traceID, parentID, samplingPriority string) context.Contex
if samplingPriority != "" {
ctx = context.WithValue(ctx, extension.DdSamplingPriority, samplingPriority)
}
if origin != "" {
ctx = context.WithValue(ctx, extension.DdOrigin, origin)
}
return ctx
}

Expand Down Expand Up @@ -135,13 +138,28 @@ func TestGetDatadogTraceContextFromContextObject(t *testing.T) {
traceID string
parentID string
samplingPriority string
origin string
expectTC TraceContext
expectOk bool
}{
{
"trace",
"parent",
"sampling",
"origin",
TraceContext{
"x-datadog-trace-id": "trace",
"x-datadog-parent-id": "parent",
"x-datadog-sampling-priority": "sampling",
"x-datadog-origin": "origin",
},
true,
},
{
"trace",
"parent",
"sampling",
"",
TraceContext{
"x-datadog-trace-id": "trace",
"x-datadog-parent-id": "parent",
Expand All @@ -153,20 +171,23 @@ func TestGetDatadogTraceContextFromContextObject(t *testing.T) {
"",
"parent",
"sampling",
"origin",
TraceContext{},
false,
},
{
"trace",
"",
"sampling",
"",
TraceContext{},
false,
},
{
"trace",
"parent",
"",
"",
TraceContext{
"x-datadog-trace-id": "trace",
"x-datadog-parent-id": "parent",
Expand All @@ -178,8 +199,8 @@ func TestGetDatadogTraceContextFromContextObject(t *testing.T) {

ev := loadRawJSON(t, "../testdata/non-proxy-no-headers.json")
for _, test := range testcases {
t.Run(test.traceID+test.parentID+test.samplingPriority, func(t *testing.T) {
ctx := mockTraceContext(test.traceID, test.parentID, test.samplingPriority)
t.Run(test.traceID+test.parentID+test.samplingPriority+test.origin, func(t *testing.T) {
ctx := mockTraceContext(test.traceID, test.parentID, test.samplingPriority, test.origin)
tc, ok := getTraceContext(ctx, getHeadersFromEventHeaders(ctx, *ev))
assert.Equal(t, test.expectTC, tc)
assert.Equal(t, test.expectOk, ok)
Expand Down
Loading