You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-23 22:34:47 +02:00
This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/Antonboom/testifylint](https://redirect.github.com/Antonboom/testifylint) | `v1.5.2` -> `v1.6.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>Antonboom/testifylint (github.com/Antonboom/testifylint)</summary> ### [`v1.6.0`](https://redirect.github.com/Antonboom/testifylint/releases/tag/v1.6.0): – new `equal-values` and `suite-method-signature` [Compare Source](https://redirect.github.com/Antonboom/testifylint/compare/v1.5.2...v1.6.0) #### What's Changed ##### New checkers - new checker `equal-values` by [@​Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/223](https://redirect.github.com/Antonboom/testifylint/pull/223) - new checker `suite-method-signature` by [@​Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/228](https://redirect.github.com/Antonboom/testifylint/pull/228) ##### New features - `len`: support len-len and value-len cases by [@​Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/204](https://redirect.github.com/Antonboom/testifylint/pull/204) - `error-is-as`: support NotErrorAs by [@​Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/219](https://redirect.github.com/Antonboom/testifylint/pull/219) - `useless-assert`: add NotElementsMatch and NotErrorAs by [@​Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/220](https://redirect.github.com/Antonboom/testifylint/pull/220) - `formatter`: support non-string-message checks by [@​Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/221](https://redirect.github.com/Antonboom/testifylint/pull/221) - `formatter`: warn on empty message by [@​Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/225](https://redirect.github.com/Antonboom/testifylint/pull/225) - `empty`: support empty strings, Zero for strings and len + bubbled useless-assert cases by [@​ccoVeille](https://redirect.github.com/ccoVeille) in [https://github.com/Antonboom/testifylint/pull/129](https://redirect.github.com/Antonboom/testifylint/pull/129) ##### New fixes - `negative-positive`: remove untyping, ignore Negative for len comparisons by [@​Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/226](https://redirect.github.com/Antonboom/testifylint/pull/226) - fixes: support `assert.CollectT` by [@​Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/233](https://redirect.github.com/Antonboom/testifylint/pull/233) ##### Bump deps - Upgrade testdata to v1.10.0 of testify by [@​Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/218](https://redirect.github.com/Antonboom/testifylint/pull/218) - Go 1.24 by [@​Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/234](https://redirect.github.com/Antonboom/testifylint/pull/234) - build(deps): bump golang.org/x/tools from 0.26.0 to 0.27.0 by [@​dependabot](https://redirect.github.com/dependabot) in [https://github.com/Antonboom/testifylint/pull/206](https://redirect.github.com/Antonboom/testifylint/pull/206) - build(deps): bump rlespinasse/github-slug-action from 4.4.1 to 5.0.0 by [@​dependabot](https://redirect.github.com/dependabot) in [https://github.com/Antonboom/testifylint/pull/207](https://redirect.github.com/Antonboom/testifylint/pull/207) - build(deps): bump golang.org/x/tools from 0.27.0 to 0.29.0 by [@​dependabot](https://redirect.github.com/dependabot) in [https://github.com/Antonboom/testifylint/pull/214](https://redirect.github.com/Antonboom/testifylint/pull/214) **Full Changelog**: https://github.com/Antonboom/testifylint/compare/v1.5.2...v1.6.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/open-telemetry/opentelemetry-go). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yMDAuMiIsInVwZGF0ZWRJblZlciI6IjM5LjIwMC4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJTa2lwIENoYW5nZWxvZyIsImRlcGVuZGVuY2llcyJdfQ==--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> Co-authored-by: Tyler Yahn <codingalias@gmail.com>
343 lines
8.8 KiB
Go
343 lines
8.8 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package propagation_test
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.opentelemetry.io/otel/propagation"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
var (
|
|
traceparent = http.CanonicalHeaderKey("traceparent")
|
|
tracestate = http.CanonicalHeaderKey("tracestate")
|
|
|
|
prop = propagation.TraceContext{}
|
|
)
|
|
|
|
type testcase struct {
|
|
name string
|
|
header http.Header
|
|
sc trace.SpanContext
|
|
}
|
|
|
|
func TestExtractValidTraceContext(t *testing.T) {
|
|
stateStr := "key1=value1,key2=value2"
|
|
state, err := trace.ParseTraceState(stateStr)
|
|
require.NoError(t, err)
|
|
|
|
tests := []testcase{
|
|
{
|
|
name: "not sampled",
|
|
header: http.Header{
|
|
traceparent: []string{"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00"},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
{
|
|
name: "sampled",
|
|
header: http.Header{
|
|
traceparent: []string{"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
TraceFlags: trace.FlagsSampled,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
{
|
|
name: "valid tracestate",
|
|
header: http.Header{
|
|
traceparent: []string{"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00"},
|
|
tracestate: []string{stateStr},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
TraceState: state,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
{
|
|
name: "invalid tracestate preserves traceparent",
|
|
header: http.Header{
|
|
traceparent: []string{"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00"},
|
|
tracestate: []string{"invalid$@#=invalid"},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
{
|
|
name: "future version not sampled",
|
|
header: http.Header{
|
|
traceparent: []string{"02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00"},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
{
|
|
name: "future version sampled",
|
|
header: http.Header{
|
|
traceparent: []string{"02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
TraceFlags: trace.FlagsSampled,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
{
|
|
name: "future version sample bit set",
|
|
header: http.Header{
|
|
traceparent: []string{"02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-09"},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
TraceFlags: trace.FlagsSampled,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
{
|
|
name: "future version sample bit not set",
|
|
header: http.Header{
|
|
traceparent: []string{"02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-08"},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
{
|
|
name: "future version additional data",
|
|
header: http.Header{
|
|
traceparent: []string{"02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00-XYZxsf09"},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
{
|
|
name: "B3 format ending in dash",
|
|
header: http.Header{
|
|
traceparent: []string{"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00-"},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
{
|
|
name: "future version B3 format ending in dash",
|
|
header: http.Header{
|
|
traceparent: []string{"03-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00-"},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
ctx := context.Background()
|
|
ctx = prop.Extract(ctx, propagation.HeaderCarrier(tc.header))
|
|
assert.Equal(t, tc.sc, trace.SpanContextFromContext(ctx))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestExtractInvalidTraceContextFromHTTPReq(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
header string
|
|
}{
|
|
{
|
|
name: "wrong version length",
|
|
header: "0000-00000000000000000000000000000000-0000000000000000-01",
|
|
},
|
|
{
|
|
name: "wrong trace ID length",
|
|
header: "00-ab00000000000000000000000000000000-cd00000000000000-01",
|
|
},
|
|
{
|
|
name: "wrong span ID length",
|
|
header: "00-ab000000000000000000000000000000-cd0000000000000000-01",
|
|
},
|
|
{
|
|
name: "wrong trace flag length",
|
|
header: "00-ab000000000000000000000000000000-cd00000000000000-0100",
|
|
},
|
|
{
|
|
name: "bogus version",
|
|
header: "qw-00000000000000000000000000000000-0000000000000000-01",
|
|
},
|
|
{
|
|
name: "bogus trace ID",
|
|
header: "00-qw000000000000000000000000000000-cd00000000000000-01",
|
|
},
|
|
{
|
|
name: "bogus span ID",
|
|
header: "00-ab000000000000000000000000000000-qw00000000000000-01",
|
|
},
|
|
{
|
|
name: "bogus trace flag",
|
|
header: "00-ab000000000000000000000000000000-cd00000000000000-qw",
|
|
},
|
|
{
|
|
name: "upper case version",
|
|
header: "A0-00000000000000000000000000000000-0000000000000000-01",
|
|
},
|
|
{
|
|
name: "upper case trace ID",
|
|
header: "00-AB000000000000000000000000000000-cd00000000000000-01",
|
|
},
|
|
{
|
|
name: "upper case span ID",
|
|
header: "00-ab000000000000000000000000000000-CD00000000000000-01",
|
|
},
|
|
{
|
|
name: "upper case trace flag",
|
|
header: "00-ab000000000000000000000000000000-cd00000000000000-A1",
|
|
},
|
|
{
|
|
name: "zero trace ID and span ID",
|
|
header: "00-00000000000000000000000000000000-0000000000000000-01",
|
|
},
|
|
{
|
|
name: "trace-flag unused bits set",
|
|
header: "00-ab000000000000000000000000000000-cd00000000000000-09",
|
|
},
|
|
{
|
|
name: "missing options",
|
|
header: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7",
|
|
},
|
|
{
|
|
name: "empty options",
|
|
header: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-",
|
|
},
|
|
}
|
|
|
|
empty := trace.SpanContext{}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
h := http.Header{traceparent: []string{tt.header}}
|
|
ctx := context.Background()
|
|
ctx = prop.Extract(ctx, propagation.HeaderCarrier(h))
|
|
|
|
// Failure to extract needs to result in no SpanContext being set.
|
|
// This cannot be directly measured, but we can check that an
|
|
// zero-value SpanContext is returned from SpanContextFromContext.
|
|
assert.Equal(t, empty, trace.SpanContextFromContext(ctx))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestInjectValidTraceContext(t *testing.T) {
|
|
stateStr := "key1=value1,key2=value2"
|
|
state, err := trace.ParseTraceState(stateStr)
|
|
require.NoError(t, err)
|
|
|
|
tests := []testcase{
|
|
{
|
|
name: "not sampled",
|
|
header: http.Header{
|
|
traceparent: []string{"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00"},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
{
|
|
name: "sampled",
|
|
header: http.Header{
|
|
traceparent: []string{"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
TraceFlags: trace.FlagsSampled,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
{
|
|
name: "unsupported trace flag bits dropped",
|
|
header: http.Header{
|
|
traceparent: []string{"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
TraceFlags: 0xff,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
{
|
|
name: "with tracestate",
|
|
header: http.Header{
|
|
traceparent: []string{"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00"},
|
|
tracestate: []string{stateStr},
|
|
},
|
|
sc: trace.NewSpanContext(trace.SpanContextConfig{
|
|
TraceID: traceID,
|
|
SpanID: spanID,
|
|
TraceState: state,
|
|
Remote: true,
|
|
}),
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
ctx := context.Background()
|
|
ctx = trace.ContextWithRemoteSpanContext(ctx, tc.sc)
|
|
|
|
h := http.Header{}
|
|
prop.Inject(ctx, propagation.HeaderCarrier(h))
|
|
assert.Equal(t, tc.header, h)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestInvalidSpanContextDropped(t *testing.T) {
|
|
invalidSC := trace.SpanContext{}
|
|
require.False(t, invalidSC.IsValid())
|
|
ctx := trace.ContextWithRemoteSpanContext(context.Background(), invalidSC)
|
|
|
|
header := http.Header{}
|
|
propagation.TraceContext{}.Inject(ctx, propagation.HeaderCarrier(header))
|
|
assert.Empty(t, header.Get("traceparent"), "injected invalid SpanContext")
|
|
}
|
|
|
|
func TestTraceContextFields(t *testing.T) {
|
|
expected := []string{"traceparent", "tracestate"}
|
|
assert.Equal(t, expected, propagation.TraceContext{}.Fields())
|
|
}
|