You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-25 22:41:46 +02:00
Make SpanContext Immutable (#1573)
* Make SpanContext Immutable
* Adds NewSpanContext() constructor and SpanContextConfig{} struct for
constructing a new SpanContext when all fields are known
* Adds With<field>() methods to SpanContext for deriving a SpanContext
with a single field changed.
* Updates all uses of SpanContext to use the new API
Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>
* Update CHANGELOG.md
Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>
* Add tests for new SpanContext constructor and derivation
Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>
* Address PR feedback
* Fix new uses of SpanContext from main
This commit is contained in:
committed by
GitHub
parent
d75e268053
commit
e88a091a72
@@ -30,11 +30,11 @@ func TestParentBasedDefaultLocalParentSampled(t *testing.T) {
|
||||
sampler := ParentBased(AlwaysSample())
|
||||
traceID, _ := trace.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
|
||||
spanID, _ := trace.SpanIDFromHex("00f067aa0ba902b7")
|
||||
parentCtx := trace.SpanContext{
|
||||
parentCtx := trace.NewSpanContext(trace.SpanContextConfig{
|
||||
TraceID: traceID,
|
||||
SpanID: spanID,
|
||||
TraceFlags: trace.FlagsSampled,
|
||||
}
|
||||
})
|
||||
if sampler.ShouldSample(SamplingParameters{ParentContext: parentCtx}).Decision != RecordAndSample {
|
||||
t.Error("Sampling decision should be RecordAndSample")
|
||||
}
|
||||
@@ -44,10 +44,10 @@ func TestParentBasedDefaultLocalParentNotSampled(t *testing.T) {
|
||||
sampler := ParentBased(AlwaysSample())
|
||||
traceID, _ := trace.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
|
||||
spanID, _ := trace.SpanIDFromHex("00f067aa0ba902b7")
|
||||
parentCtx := trace.SpanContext{
|
||||
parentCtx := trace.NewSpanContext(trace.SpanContextConfig{
|
||||
TraceID: traceID,
|
||||
SpanID: spanID,
|
||||
}
|
||||
})
|
||||
if sampler.ShouldSample(SamplingParameters{ParentContext: parentCtx}).Decision != Drop {
|
||||
t.Error("Sampling decision should be Drop")
|
||||
}
|
||||
@@ -108,13 +108,13 @@ func TestParentBasedWithSamplerOptions(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
traceID, _ := trace.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
|
||||
spanID, _ := trace.SpanIDFromHex("00f067aa0ba902b7")
|
||||
parentCtx := trace.SpanContext{
|
||||
parentCtx := trace.NewSpanContext(trace.SpanContextConfig{
|
||||
TraceID: traceID,
|
||||
SpanID: spanID,
|
||||
}
|
||||
})
|
||||
|
||||
if tc.isParentSampled {
|
||||
parentCtx.TraceFlags = trace.FlagsSampled
|
||||
parentCtx = parentCtx.WithTraceFlags(trace.FlagsSampled)
|
||||
}
|
||||
|
||||
params := SamplingParameters{ParentContext: parentCtx}
|
||||
@@ -225,9 +225,9 @@ func TestTracestateIsPassed(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
parentCtx := trace.SpanContext{
|
||||
parentCtx := trace.NewSpanContext(trace.SpanContextConfig{
|
||||
TraceState: traceState,
|
||||
}
|
||||
})
|
||||
params := SamplingParameters{ParentContext: parentCtx}
|
||||
|
||||
require.Equal(t, traceState, tc.sampler.ShouldSample(params).Tracestate, "TraceState is not equal")
|
||||
|
||||
Reference in New Issue
Block a user