Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inferred proxy spans #3052

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Add inferred proxy spans #3052

wants to merge 7 commits into from

Conversation

jordan-wong
Copy link

What does this PR do?

Motivation

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
Copy link
Contributor

@zarirhamza zarirhamza left a comment

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.

contrib/internal/httptrace/httptrace.go Outdated Show resolved Hide resolved
contrib/internal/httptrace/httptrace_api_gateway_test.go Outdated Show resolved Hide resolved
contrib/internal/httptrace/httptrace_api_gateway_test.go Outdated Show resolved Hide resolved
contrib/internal/httptrace/inferred_proxy.go Outdated Show resolved Hide resolved
contrib/internal/httptrace/inferred_proxy.go Outdated Show resolved Hide resolved
@zarirhamza zarirhamza requested a review from wantsui December 19, 2024 20:42
@pr-commenter
Copy link

pr-commenter bot commented Dec 20, 2024

Benchmarks

Benchmark execution time: 2025-01-07 16:10:31

Comparing candidate commit b356a70 in PR branch add-inferred-proxy-spans with baseline commit 58e1e63 in branch main.

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

scenario:BenchmarkStartRequestSpan-24

  • 🟩 execution_time [-7.460ns; -6.380ns] or [-2.420%; -2.069%]

contrib/internal/httptrace/inferred_proxy.go Outdated Show resolved Hide resolved
assert.Equal(2, len(spans))
gateway_span := spans[0]
web_req_span := spans[1]
assert.Equal("aws.apigateway", gateway_span.OperationName())
Copy link

Choose a reason for hiding this comment

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

Can you add tests to make sure the other aspects of the span metadata is present? Some examples can be found in the JS version: https://github.com/DataDog/dd-trace-js/pull/4837/files#diff-30cfe20da922154edf4288007e440ef1fc0873c26813eb2cc7c78e064024ebd0 .

Namely, span metadata like:

  • component
  • http.* (like http.url, http.status_codes)

I'm curious if you can assert that the inferred span in Go follows the underlying span created by httptrace.

Copy link
Author

@jordan-wong jordan-wong Jan 7, 2025

Choose a reason for hiding this comment

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

Currently working through a bug I found related to this in expected tag assertion

I'm curious if you can assert that the inferred span in Go follows the underlying span created by httptrace.

I am assuming you mean asserting that httptrace is a parent of the inferredSpan? - I have a line that checks this https://github.com/DataDog/dd-trace-go/pull/3052/files#diff-5c136a85a92fba2b6b3bdb1a3b8f5c43ed87d3dcb3d65a4bab64d68df68b769cR88
assert.True(web_req_span.ParentID() == gateway_span.SpanID())

Copy link

Choose a reason for hiding this comment

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

Sorry, to clarify, I mean asserting that the httptrace span and the inferred span have matching:

  • status codes
  • http urls
  • type

contrib/internal/httptrace/inferred_proxy.go Outdated Show resolved Hide resolved
Comment on lines +15 to +21
PROXY_HEADER_SYSTEM = "X-Dd-Proxy"
//PROXY_HEADER_START_TIME_MS = "x-dd-proxy-request-time-ms"
PROXY_HEADER_START_TIME_MS = "X-Dd-Proxy-Request-Time-Ms"
PROXY_HEADER_PATH = "X-Dd-Proxy-Path"
PROXY_HEADER_HTTPMETHOD = "X-Dd-Proxy-Httpmethod"
PROXY_HEADER_DOMAIN = "X-Dd-Proxy-Domain-Name"
PROXY_HEADER_STAGE = "X-Dd-Proxy-Stage"
Copy link

Choose a reason for hiding this comment

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

Just a question: Is this casing Go syntax specific? I noticed in the test that it'd work with x-dd-proxy-path.

Copy link
Author

Choose a reason for hiding this comment

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

Golang's http library parses and returns http request header content in "Canonical Form" with each word capitalized, so when accessing headers from a request we need to reference the exact spelling. https://ron-liu.medium.com/what-canonical-http-header-mean-in-golang-2e97f854316d

In the tests we are passing in the headers to create a new Request, so the http library automatically formats/capitalizes our headers to canonical form for us even if we pass in lowercased strings.

@zarirhamza
Copy link
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

return nil
}

// Q: is it possible to have multiple values for any of these http headers??
Copy link

Choose a reason for hiding this comment

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

Is this comment asking if it's possible for something like domain to have multiple "domain values"? At the moment, I don't think so.

Copy link
Member

@darccio darccio Jan 9, 2025

Choose a reason for hiding this comment

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

HTTP headers may have multiple values but it's up to specs to treat each header as a concrete value or a list of them, according to RFC 7231:

Authors of specifications defining new header fields are advised to consider documenting:

  • Whether the field is a single value or whether it can be a list (delimited by commas; see Section 3.2 of [RFC7230]). If it does not use the list syntax, document how to treat messages where the field occurs multiple times (a sensible default would be to ignore the field, but this might not always be the right choice).

So, whoever is emitting PROXY_HEADER_DOMAIN need to confirm if it may have multiple values or not. The same for the rest of headers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants