Skip to content

Commit

Permalink
Set default sampling priority to sampler-keep (#88)
Browse files Browse the repository at this point in the history
* Set default sampling priority to sampler-keep

* Add a test for missing sampling priority
  • Loading branch information
agocs authored Aug 18, 2021
1 parent d6fcbc3 commit de1c7f3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
10 changes: 10 additions & 0 deletions internal/testdata/non-proxy-with-missing-sampling-priority.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"my-custom-event": {
"hello": 100
},
"fake-id": "12345678910",
"headers": {
"X-Datadog-Trace-Id": "1231452342",
"X-Datadog-Parent-Id": "45678910"
}
}
2 changes: 1 addition & 1 deletion internal/trace/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func getDatadogTraceContextFromEvent(ctx context.Context, ev json.RawMessage) (T

samplingPriority, ok := lowercaseHeaders[samplingPriorityHeader]
if !ok {
return traceCtx, false
samplingPriority = "1" //sampler-keep
}

traceCtx[samplingPriorityHeader] = samplingPriority
Expand Down
15 changes: 15 additions & 0 deletions internal/trace/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ func TestGetDatadogTraceContextForTraceMetadataWithMixedCaseHeaders(t *testing.T
assert.Equal(t, expected, headers)
}

func TestGetDatadogTraceContextForTraceMetadataWithMissingSamplingPriority(t *testing.T) {
ctx := mockLambdaXRayTraceContext(context.Background(), mockXRayTraceID, mockXRayEntityID, true)
ev := loadRawJSON(t, "../testdata/non-proxy-with-missing-sampling-priority.json")

headers, ok := getDatadogTraceContextFromEvent(ctx, *ev)
assert.True(t, ok)

expected := TraceContext{
traceIDHeader: "1231452342",
parentIDHeader: "45678910",
samplingPriorityHeader: "1",
}
assert.Equal(t, expected, headers)
}

func TestGetDatadogTraceContextForInvalidData(t *testing.T) {
ctx := mockLambdaXRayTraceContext(context.Background(), mockXRayTraceID, mockXRayEntityID, true)
ev := loadRawJSON(t, "../testdata/invalid.json")
Expand Down

0 comments on commit de1c7f3

Please sign in to comment.