-
Notifications
You must be signed in to change notification settings - Fork 439
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
ddtrace/tracer: setup GLS-stored context #2761
Conversation
BenchmarksBenchmark execution time: 2024-07-10 15:08:06 Comparing candidate commit c82c374 in PR branch Found 0 performance improvements and 2 performance regressions! Performance is the same for 45 metrics, 0 unstable metrics. scenario:BenchmarkOTelApiWithCustomTags/otel_api-24
scenario:BenchmarkStartSpanConcurrent-24
|
07c2865
to
6d925c5
Compare
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 |
8a805e3
to
8ca3a8c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly stylistic comments, and some ergonomics -- some of which we have discussed offline but I left there "for posterity", but you can feel free to ignore where we essentially agree they are difficult to implement without causing a QoL degradation somewhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in general. Let's just change orchestrion.FromCtxOrGLS
to orchestrion.WrapContext
.
c6953e3
to
18f3f92
Compare
Signed-off-by: Eliott Bouhana <[email protected]>
Signed-off-by: Eliott Bouhana <[email protected]>
Signed-off-by: Eliott Bouhana <[email protected]>
… as glsContext Signed-off-by: Eliott Bouhana <[email protected]>
Signed-off-by: Eliott Bouhana <[email protected]>
Signed-off-by: Eliott Bouhana <[email protected]>
Signed-off-by: Eliott Bouhana <[email protected]>
204abc9
to
1163073
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving this to unblock progress on orchestrion. This is based on:
- Monday's call with Romain and Elliot where we discussed the two PRs.
- Further review of mine today to ensure that this PR does not pose a risk to existing users of dd-trace-go that don't use orchestrion yet (I took some notes).
One important thing we need going forward is a suite of integration tests that verify that all of this is working as expected, even for the known edge cases.
In particular I'm thinking about scenarios like this:
- Parent span finishes before child span(s)
- User spawns a goroutine that calls an orchestrion instrumentation method without passing an explicit ctx.
- etc.
@@ -104,12 +104,12 @@ func (t *gqlTracer) Validate(_ graphql.ExecutableSchema) error { | |||
func (t *gqlTracer) InterceptOperation(ctx context.Context, next graphql.OperationHandler) graphql.ResponseHandler { | |||
opCtx := graphql.GetOperationContext(ctx) | |||
span, ctx := t.createRootSpan(ctx, opCtx) | |||
ctx, req := graphqlsec.StartRequestOperation(ctx, nil /* root */, span, types.RequestOperationArgs{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we pass nil
instead of span
to this func before, and why are we changing it now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed a parameter to the function StartRequestOperation
because we always passed nil
as a second argument to it. Romain also noted this here
@@ -503,6 +504,7 @@ func (s *span) Finish(opts ...ddtrace.FinishOption) { | |||
} | |||
|
|||
s.finish(t) | |||
orchestrion.GLSPopValue(sharedinternal.ActiveSpanKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if a span finishes before its children?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a case where this could happen in the same goroutine. 🤔 In a multiple goroutine setup where the parent ends in another gouroutine this is a real issue that is not taken care of today. We definitively need a kind of cross goroutine GLS in the future
Signed-off-by: Eliott Bouhana <[email protected]>
1163073
to
b33d2bf
Compare
Pull Request is not mergeable
In order to be able to lazily link against GLS accessors, these need to be declared as variables instead of functions. This allows creation of bindings on the other side that can be conditionally satisffied by the existence of initialized declarations somewhere else. Adds an integration test to demonstrate it is possible to build programs with and without the runtime modification using this technique. Enables: DataDog/dd-trace-go#2761 --------- Signed-off-by: Eliott Bouhana <[email protected]> Signed-off-by: github-actions on behalf of eliottness <[email protected]> Co-authored-by: Eliott Bouhana <[email protected]> Co-authored-by: github-actions on behalf of eliottness <[email protected]>
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 inruntime.g
to act as a Goroutine Local Storage (GLS) the same way C does with it's Thread Local Storage (TLS).Sister PR of DataDog/orchestrion#127
From there the integration of this new package cascasdes into:
ddtrace/tracer/context.go
andinternal/trace_context.go
files to support storing and reading spans/traces from the GLSinternal/appsec/dyngo
package to refactor and add support for context-stored appsec operationsinternal/appsec/emitter/...
and the graphql contribs packages to move the old way of storing context values in the new "dyngo"-wayMotivation
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.Unsure? Have a question? Request a review!