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

tracer: support 128-bit trace ids #1833

Merged
merged 19 commits into from
Mar 30, 2023
Merged

Conversation

katiehockman
Copy link
Contributor

@katiehockman katiehockman commented Mar 27, 2023

What does this PR do?

This PR merges all of the changes made to the shared/128-bit branch to support 128-bit trace id generation, propagation, and logging.

The main changes are the following:

  • Adds a new SpanContextW3C interface type to the ddtrace package which supports a new TraceID128 method.
  • Propagates 128-bit trace ids through all carriers (B3, B3 multi, Datadog, and W3C)
  • Uses a new tag, _dd.p.tid, to propagate the upper 64 bits to the Agent
  • Enables logging 128-bit trace ids using DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED, which is off by default
  • Enables generated 128-bit trace ids using DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED, which is off by default

Motivation

128 bit trace ids are generated and propagated by default for OpenTelemetry use cases

Describe how to test/QA your changes

Reviewer's Checklist

  • If known, an appropriate milestone has been selected; otherwise the Triage milestone is set.
  • Changed code has unit tests for its functionality.
  • If this interacts with the agent in a new way, a system test has been added.

@katiehockman katiehockman added this to the v1.50.0 milestone Mar 27, 2023
@katiehockman katiehockman marked this pull request as ready for review March 27, 2023 19:52
@katiehockman katiehockman requested a review from a team March 27, 2023 19:52
@pr-commenter
Copy link

pr-commenter bot commented Mar 27, 2023

Benchmarks

Comparing candidate commit d48d3ef in PR branch katiehockman/merge-branches with baseline commit fb28024 in branch main.

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

scenario:BenchmarkConcurrentTracing-24

  • 🟥 execution_time [+0.193ms; +0.210ms] or [+17.110%; +18.529%]

ajgajg1134
ajgajg1134 previously approved these changes Mar 28, 2023
Copy link
Contributor

@ajgajg1134 ajgajg1134 left a comment

Choose a reason for hiding this comment

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

I focused my review on the non-test files and it all looks good to me, only 2 things we should probably address before merging:

  1. Investigate benchmark regression (this may be related to tweaks done in the benchmarking platform, I have a meeting tomorrow with R&P team to look deeper)
  2. Add TraceID128Bytes() [16]byte to SpanContextW3C interface (to be used by otel api)

katiehockman and others added 17 commits March 28, 2023 16:00
Adds support for generating 128 bit trace ids and exposing them from the Datadog API via a new SpanContextW3C. Future PRs will propagate this id for distributed tracing.
Remove the WithTraceID128 API that was added to this feature branch (not currently in a dd-trace-go release or in main).
Support DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED to only log 128 bit trace id values when enabled.
Rather than generate a random 64 bits for the upper half of a 128-bit trace id, use the first 32 bits as a timestamp, and the remaining 32 bits padded with zeroes.
Supports 128-bit trace id propagation in B3 multi headers. Other carriers will be supported in future PRs, and TODOs have been added in the code where it is needed.

Also fixes the issue where a spanContext needed to have an associated span to access and store 128-bit trace ids. It is now a separate field of the spanContext. Now, the _dd.p.tid tag in the Meta map (upper 64 bits of 128-bit trace ID) is populated from the spanContext upon span finish.
Small refactor to tests to make it easier to test with 128-bit trace ids for other carriers.

These tests could probably be refactored even further to have less repetition, but for now, it's just extending them to support 128-bit trace ids.
Supports 128-bit trace propagation of the remaining carriers per the specification.
When DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED is false, only the lower-order 64-bits of the TraceId should be logged.
When DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED is true, the format of the injected TraceId is conditional based on the higher-order 64 bits of the TraceId - specifically, when:
zero - the injected TraceId will be its decimal string encoding (preserving the current behavior of 64-bit TraceIds)
non-zero - the injected TraceId will be encoded as 32 lower-case hexadecimal characters with zero-padding as necessary
- guarantee that the propagating tags have been set before reading them during extraction
- only set _dd.p.tid if the top 64 bits is not empty or zero
- always set _dd.p.tid to 16 characters, with padding if needed
* WIP: more refactoring, still broken tests though
* Even more bug fixes
* Update ddtrace/tracer/spancontext.go
* PR Comments: use strconv.ParseUint instead of hex.Decode since it can handle odd length strings
Co-authored-by: Katie Hockman <katie@hockman.dev>
ajgajg1134
ajgajg1134 previously approved these changes Mar 28, 2023
@dianashevchenko dianashevchenko merged commit 1fd4fae into main Mar 30, 2023
@dianashevchenko dianashevchenko deleted the katiehockman/merge-branches branch March 30, 2023 11:27
eliottness pushed a commit that referenced this pull request Mar 31, 2023
eliottness pushed a commit that referenced this pull request Apr 5, 2023
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.

None yet

3 participants