Skip to content

Commit

Permalink
rename FromCtxOrGLS to WrapContext
Browse files Browse the repository at this point in the history
Signed-off-by: Eliott Bouhana <[email protected]>
  • Loading branch information
eliottness committed Jul 3, 2024
1 parent 983a4c2 commit 18f3f92
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ddtrace/tracer/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func SpanFromContext(ctx context.Context) (Span, bool) {
if ctx == nil {
return &traceinternal.NoopSpan{}, false
}
v := orchestrion.FromCtxOrGLS(ctx).Value(internal.ActiveSpanKey)
v := orchestrion.WrapContext(ctx).Value(internal.ActiveSpanKey)
if s, ok := v.(ddtrace.Span); ok {
return s, true
}
Expand Down
2 changes: 1 addition & 1 deletion internal/appsec/dyngo/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func NewOperation(parent Operation) Operation {

// FromContext looks into the given context (or the GLS if orchestrion is enabled) for a parent Operation and returns it.
func FromContext(ctx context.Context) (Operation, bool) {
ctx = orchestrion.FromCtxOrGLS(ctx)
ctx = orchestrion.WrapContext(ctx)
if ctx == nil {
return nil, false
}
Expand Down
6 changes: 3 additions & 3 deletions internal/orchestrion/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"context"
)

// FromCtxOrGLS returns the GLS-wrapped context if orchestrion is enabled, otherwise it returns the given parameter.
func FromCtxOrGLS(ctx context.Context) context.Context {
// WrapContext returns the GLS-wrapped context if orchestrion is enabled, otherwise it returns the given parameter.
func WrapContext(ctx context.Context) context.Context {
if !Enabled() {
return ctx
}
Expand All @@ -36,7 +36,7 @@ func CtxWithValue(parent context.Context, key, val any) context.Context {
}

getDDContextStack().Push(key, val)
return FromCtxOrGLS(parent)
return WrapContext(parent)
}

// GLSPopValue pops the value from the GLS slot of orchestrion and returns it. Using context.Context values usually does
Expand Down
8 changes: 4 additions & 4 deletions internal/orchestrion/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ func TestFromGLS(t *testing.T) {

t.Run("Enabled() is false, ctx is nil", func(t *testing.T) {
enabled = false
require.Equal(t, nil, FromCtxOrGLS(nil))
require.Equal(t, nil, WrapContext(nil))
})

t.Run("Enabled() is false, ctx is not nil", func(t *testing.T) {
enabled = false
require.Equal(t, context.Background(), FromCtxOrGLS(context.Background()))
require.Equal(t, context.Background(), WrapContext(context.Background()))

})

t.Run("Enabled() is true, ctx is nil", func(t *testing.T) {
enabled = true
require.Equal(t, &glsContext{context.Background()}, FromCtxOrGLS(nil))
require.Equal(t, &glsContext{context.Background()}, WrapContext(nil))
})

t.Run("Enabled() is true, ctx is not nil", func(t *testing.T) {
enabled = true
ctx := context.WithValue(context.Background(), key("key"), "value")
require.Equal(t, &glsContext{ctx}, FromCtxOrGLS(ctx))
require.Equal(t, &glsContext{ctx}, WrapContext(ctx))
})
}

Expand Down
4 changes: 2 additions & 2 deletions internal/trace_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func WithExecutionTraced(ctx context.Context) context.Context {
// information from ctx) from being considered covered by a task, when an
// integration may create its own child span with its own execution trace task.
func WithExecutionNotTraced(ctx context.Context) context.Context {
if orchestrion.FromCtxOrGLS(ctx).Value(executionTracedKey{}) == nil {
if orchestrion.WrapContext(ctx).Value(executionTracedKey{}) == nil {
// Fast path: if it wasn't marked before, we don't need to wrap
// the context
return ctx
Expand All @@ -44,6 +44,6 @@ func WithExecutionNotTraced(ctx context.Context) context.Context {
// IsExecutionTraced returns whether ctx is associated with an execution trace
// task, as indicated via WithExecutionTraced
func IsExecutionTraced(ctx context.Context) bool {
v := orchestrion.FromCtxOrGLS(ctx).Value(executionTracedKey{})
v := orchestrion.WrapContext(ctx).Value(executionTracedKey{})
return v != nil && v.(bool)
}

0 comments on commit 18f3f92

Please sign in to comment.