Skip to content

contrib/internal/httptrace: add support for inferred proxy spans#3052

Merged
darccio merged 30 commits into
mainfrom
add-inferred-proxy-spans
Jan 23, 2025
Merged

contrib/internal/httptrace: add support for inferred proxy spans#3052
darccio merged 30 commits into
mainfrom
add-inferred-proxy-spans

Conversation

@jordan-wong

@jordan-wong jordan-wong commented Dec 19, 2024

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR introduces functionality to infer proxy spans based on headers that we instruct users to inject upstream, allowing these headers to be propagated downstream. The headers are then used to infer a proxy span to provide increased visibility to a user's trace. The headers are as follows:

Header Name AWS Mappings Header Contents
x-dd-proxy aws-apigateway aws-apigateway
x-dd-proxy-request-time-ms context.requestTimeEpoch Start time of request in ms
x-dd-proxy-domain-name context.domainName AWS domain name
x-dd-proxy-httpmethod context.httpMethod HTTP method used for request
x-dd-proxy-path context.path Path for request
x-dd-proxy-stage context.stage AWS stage name

Motivation

There is no current support for API Gateway and other proxies that do not run Datadog code. By inferring spans via headers, the gaps in observability can be filled to provide a more accurate trace.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.
  • For internal contributors, a matching PR should be created to the v2-dev branch and reviewed by @DataDog/apm-go.

Unsure? Have a question? Request a review!

@jordan-wong jordan-wong self-assigned this Dec 19, 2024

@zarirhamza zarirhamza left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Needs a bit of cleanup and logging for prod but logically looks good. Going to request @wantsui to look at it as well to confirm the span information is relatively similar as in dd-trace-js.

Comment thread contrib/internal/httptrace/httptrace.go Outdated
Comment thread contrib/internal/httptrace/httptrace_api_gateway_test.go Outdated
Comment thread contrib/internal/httptrace/httptrace_api_gateway_test.go Outdated
Comment thread contrib/internal/httptrace/inferred_proxy.go Outdated
Comment thread contrib/internal/httptrace/inferred_proxy.go Outdated
@zarirhamza
zarirhamza requested a review from wantsui December 19, 2024 20:42
@pr-commenter

pr-commenter Bot commented Dec 20, 2024

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2025-01-22 22:12:35

Comparing candidate commit 39087f1 in PR branch add-inferred-proxy-spans with baseline commit 241a6f1 in branch main.

Found 0 performance improvements and 3 performance regressions! Performance is the same for 55 metrics, 1 unstable metrics.

scenario:BenchmarkStartRequestSpan-24

  • 🟥 allocated_mem [+72 bytes; +72 bytes] or [+40.909%; +40.909%]
  • 🟥 allocations [+1; +1] or [+20.000%; +20.000%]
  • 🟥 execution_time [+66.057ns; +67.123ns] or [+21.642%; +21.992%]

Comment thread contrib/internal/httptrace/inferred_proxy.go Outdated
Comment thread contrib/internal/httptrace/httptrace_api_gateway_test.go Outdated
Comment thread contrib/internal/httptrace/inferred_proxy.go Outdated
Comment thread contrib/internal/httptrace/inferred_proxy.go Outdated
@zarirhamza

Copy link
Copy Markdown
Contributor

Let's also make sure that we test that our inferred span matches the behavior of the parent span by asserting things like that status code are the same

Comment thread contrib/internal/httptrace/inferred_proxy.go Outdated
…W spans via headers

Function checks for existence of AWS APIGW headers and infers proxy span if necessary
Updates usage in all contribs that implement function
Updates test usage that implement function
Comment thread contrib/internal/httptrace/config.go Outdated
Comment thread contrib/internal/httptrace/httptrace.go Outdated
Comment thread contrib/internal/httptrace/httptrace.go Outdated
Comment thread contrib/internal/httptrace/httptrace.go Outdated
Comment thread contrib/internal/httptrace/httptrace.go Outdated
Comment thread contrib/internal/httptrace/httptrace.go Outdated
Comment thread contrib/internal/httptrace/inferred_proxy.go Outdated
Comment thread contrib/internal/httptrace/httptrace.go Outdated
Comment thread contrib/internal/httptrace/httptrace.go Outdated
Comment thread contrib/internal/httptrace/httptrace_api_gateway_test.go Outdated
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jan 15, 2025

Copy link
Copy Markdown

Datadog Report

Branch report: add-inferred-proxy-spans
Commit report: 64501fb
Test service: dd-trace-go

✅ 0 Failed, 5207 Passed, 72 Skipped, 2m 19.94s Total Time

Comment thread contrib/internal/httptrace/httptrace.go Outdated
Comment thread contrib/internal/httptrace/httptrace.go Outdated
Comment thread contrib/internal/httptrace/httptrace.go Outdated
Comment thread contrib/internal/httptrace/httptrace.go Outdated
Comment thread contrib/internal/httptrace/inferred_proxy.go
Comment thread contrib/internal/httptrace/inferred_proxy.go Outdated
Comment thread contrib/internal/httptrace/inferred_proxy.go Outdated
Comment thread contrib/internal/httptrace/inferred_proxy.go Outdated
Comment thread contrib/internal/httptrace/inferred_proxy.go Outdated
Comment thread contrib/internal/httptrace/inferred_proxy.go Outdated
Comment thread contrib/labstack/echo.v4/echotrace.go Outdated
Comment thread contrib/labstack/echo/echotrace.go Outdated
Comment thread contrib/internal/httptrace/config.go Outdated
@zarirhamza zarirhamza changed the title Add inferred proxy spans contrib/internal/httptrace: add support for inferred proxy spans Jan 21, 2025
@github-actions github-actions Bot added the apm:ecosystem contrib/* related feature requests or bugs label Jan 21, 2025
@zarirhamza
zarirhamza marked this pull request as ready for review January 21, 2025 14:55
@zarirhamza
zarirhamza requested review from a team as code owners January 21, 2025 14:55
Comment thread contrib/internal/httptrace/inferred_proxy.go Outdated
Comment thread contrib/internal/httptrace/httptrace.go Outdated
@rarguelloF
rarguelloF self-requested a review January 21, 2025 16:14
Comment thread contrib/internal/httptrace/inferred_proxy.go
Comment thread contrib/internal/httptrace/httptrace_api_gateway_test.go
Comment thread contrib/internal/httptrace/inferred_proxy.go
@darccio

darccio commented Jan 22, 2025

Copy link
Copy Markdown
Member

@zarirhamza @jordan-wong Do you know why the benchmarks are reporting this 50%+ increase in execution time in BenchmarkStartRequestSpan?

🟥 execution_time [+159.899ns; +160.941ns] or [+52.326%; +52.667%]

Comment thread contrib/internal/httptrace/httptrace.go Outdated
Comment on lines +46 to +47
spanParentCtx, spanParentErr := tracer.Extract(tracer.HTTPHeadersCarrier(r.Header))
spanLinksCtx, spanLinksOk := spanParentCtx.(ddtrace.SpanContextWithLinks)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@zarirhamza @jordan-wong I think this unconditional extraction of spanParentCtx is the source of the performance impact.

Would it be possible to isolate everything related to the inferred proxy spans so it runs if the feature is activated?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Previously, the span extraction would happen on every call anyway just within the span option func. I tried isolating all behaviors as much as possible so that should improve the performance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also unsure if the fact we now have cleanup functions via StartRequestSpans may result in increased usage that is expected solely due to behavior

@darccio darccio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like the increased CPU time and memory are to be expected due to the new implementation.

@darccio
darccio merged commit 700f43e into main Jan 23, 2025
@darccio
darccio deleted the add-inferred-proxy-spans branch January 23, 2025 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apm:ecosystem contrib/* related feature requests or bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants