Skip to content

Commit

Permalink
compare http and apigw spans in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zarirhamza committed Jan 15, 2025
1 parent 1ec1be9 commit 92fe98b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions contrib/internal/httptrace/httptrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ func StartRequestSpan(r *http.Request, opts ...ddtrace.StartSpanOption) (tracer.
inferredStartSpanOpts := make([]ddtrace.StartSpanOption, 0, 1)

spanParentCtx, spanParentErr := tracer.Extract(tracer.HTTPHeadersCarrier(r.Header))

var spanLinksCtx ddtrace.SpanContextWithLinks
if spanParentErr == nil && spanParentCtx.(ddtrace.SpanContextWithLinks) != nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if spanLinksCtx = spanParentCtx.(ddtrace.SpanContextWithLinks); spanLinksCtx.SpanLinks() != nil {

if spanParentErr == nil {
if linksCtx, ok := spanParentCtx.(ddtrace.SpanContextWithLinks); ok {
spanLinksCtx = linksCtx
inferredStartSpanOpts = append(inferredStartSpanOpts, tracer.WithSpanLinks(spanLinksCtx.SpanLinks()))
}
}
Expand Down Expand Up @@ -87,8 +87,8 @@ func StartRequestSpan(r *http.Request, opts ...ddtrace.StartSpanOption) (tracer.
cfg.Parent = spanParentCtx
}

if spanParentErr != nil && !inferredProxySpanCreated {
cfg.SpanLinks = spanLinksCtx.SpanLinks()
if spanParentErr != nil && !inferredProxySpanCreated && spanLinksCtx != nil {
tracer.WithSpanLinks(spanLinksCtx.SpanLinks())(cfg)
}

for k, v := range ipTags {
Expand Down
6 changes: 5 additions & 1 deletion contrib/internal/httptrace/httptrace_api_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func TestInferredProxySpans(t *testing.T) {

client := &http.Client{}
req, err := http.NewRequest("GET", fmt.Sprintf("%s/", appListener.URL), nil)

assert := as.New(t)
assert.NoError(err)

Expand All @@ -91,6 +90,9 @@ func TestInferredProxySpans(t *testing.T) {
assert.Equal("aws.apigateway", gatewaySpan.OperationName())
assert.Equal("http.request", webReqSpan.OperationName())
assert.True(webReqSpan.ParentID() == gatewaySpan.SpanID())
assert.Equal(webReqSpan.Tag("http.status_code"), gatewaySpan.Tag("http.status_code"))
assert.Equal(webReqSpan.Tag("span.type"), gatewaySpan.Tag("span.type"))

for _, arg := range inferredHeaders {
header, tag := normalizer.HeaderTag(arg)

Expand Down Expand Up @@ -136,6 +138,8 @@ func TestInferredProxySpans(t *testing.T) {
assert.Equal("aws.apigateway", gatewaySpan.OperationName())
assert.Equal("http.request", webReqSpan.OperationName())
assert.True(webReqSpan.ParentID() == gatewaySpan.SpanID())
assert.Equal(webReqSpan.Tag("http.status_code"), gatewaySpan.Tag("http.status_code"))
assert.Equal(webReqSpan.Tag("span.type"), gatewaySpan.Tag("span.type"))
for _, arg := range inferredHeaders {
header, tag := normalizer.HeaderTag(arg)

Expand Down

0 comments on commit 92fe98b

Please sign in to comment.