dd-trace-go
dd-trace-go copied to clipboard
ddtrace/tracer: setup GLS-stored context
What does this PR do?
This PR adds a new internal package called orchestrion to better interop with orchestrion. It's first feature is to interact with a compile-time added field in runtime.g to act as a Goroutine Local Storage (GLS) the same way C does with it's Thread Local Storage (TLS).
From there the integration of this new package cascasdes into:
- [x] the
ddtrace/tracer/context.goandinternal/trace_context.gofiles to support storing and reading spans/traces from the GLS - [x] the
internal/appsec/dyngopackage to refactor and add support for context-stored appsec operations - [x] the
internal/appsec/emitter/...and the graphql contribs packages to move the old way of storing context values in the new "dyngo"-way
Motivation
Auto-instrumentation comes and breaks the current way that spans are passed around using Go context.Context key value store. Using the GLS is the appropriate solution to have a better coverage where we can't pass a context around.
Reviewer's Checklist
For every reviewer, this seems interesting to read the internal/orchestrion package first.
For the appsec reviewer (@RomainMuller) reading what's inside internal/appsec/dyngo second also seems useful.
- [x] 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.
Unsure? Have a question? Request a review!
Benchmarks
Benchmark execution time: 2024-07-10 15:08:06
Comparing candidate commit c82c37475da5b92f583f7accc046ccb8b84970f7 in PR branch eliott.bouhana/APPSEC-53654 with baseline commit 6f26c4cce0a1be1885b232bf25c1dc74e3dd7560 in branch main.
Found 0 performance improvements and 2 performance regressions! Performance is the same for 45 metrics, 0 unstable metrics.
scenario:BenchmarkOTelApiWithCustomTags/otel_api-24
- 🟥
execution_time[+223.324ns; +294.876ns] or [+2.979%; +3.934%]
scenario:BenchmarkStartSpanConcurrent-24
- 🟥
execution_time[+120.618ns; +270.582ns] or [+2.235%; +5.013%]
I'll approve it when Julio's suggestions are included and the PR is back to open again 😁
I believe my PR is missing a crucial component so I will put it back to draft