Update OpenTelemetry to v1.38.0 and semantic conventions to v1.37.0
This commit is contained in:
parent
5878238077
commit
5dfb832921
13 changed files with 250 additions and 196 deletions
|
|
@ -20,7 +20,8 @@ import (
|
|||
"go.opentelemetry.io/otel/metric"
|
||||
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.37.0/httpconv"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/encoding/gzip"
|
||||
)
|
||||
|
|
@ -39,9 +40,9 @@ func SetMeterProvider(meterProvider *sdkmetric.MeterProvider) {
|
|||
// SemConvMetricsRegistry holds stables semantic conventions metric instruments.
|
||||
type SemConvMetricsRegistry struct {
|
||||
// server metrics
|
||||
httpServerRequestDuration metric.Float64Histogram
|
||||
httpServerRequestDuration httpconv.ServerRequestDuration
|
||||
// client metrics
|
||||
httpClientRequestDuration metric.Float64Histogram
|
||||
httpClientRequestDuration httpconv.ClientRequestDuration
|
||||
}
|
||||
|
||||
// NewSemConvMetricRegistry registers all stables semantic conventions metrics.
|
||||
|
|
@ -58,17 +59,13 @@ func NewSemConvMetricRegistry(ctx context.Context, config *types.OTLP) (*SemConv
|
|||
meter := otel.Meter("github.com/traefik/traefik",
|
||||
metric.WithInstrumentationVersion(version.Version))
|
||||
|
||||
httpServerRequestDuration, err := meter.Float64Histogram(semconv.HTTPServerRequestDurationName,
|
||||
metric.WithDescription(semconv.HTTPServerRequestDurationDescription),
|
||||
metric.WithUnit("s"),
|
||||
httpServerRequestDuration, err := httpconv.NewServerRequestDuration(meter,
|
||||
metric.WithExplicitBucketBoundaries(config.ExplicitBoundaries...))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't build httpServerRequestDuration histogram: %w", err)
|
||||
}
|
||||
|
||||
httpClientRequestDuration, err := meter.Float64Histogram(semconv.HTTPClientRequestDurationName,
|
||||
metric.WithDescription(semconv.HTTPClientRequestDurationDescription),
|
||||
metric.WithUnit("s"),
|
||||
httpClientRequestDuration, err := httpconv.NewClientRequestDuration(meter,
|
||||
metric.WithExplicitBucketBoundaries(config.ExplicitBoundaries...))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't build httpClientRequestDuration histogram: %w", err)
|
||||
|
|
@ -81,18 +78,18 @@ func NewSemConvMetricRegistry(ctx context.Context, config *types.OTLP) (*SemConv
|
|||
}
|
||||
|
||||
// HTTPServerRequestDuration returns the HTTP server request duration histogram.
|
||||
func (s *SemConvMetricsRegistry) HTTPServerRequestDuration() metric.Float64Histogram {
|
||||
func (s *SemConvMetricsRegistry) HTTPServerRequestDuration() httpconv.ServerRequestDuration {
|
||||
if s == nil {
|
||||
return nil
|
||||
return httpconv.ServerRequestDuration{}
|
||||
}
|
||||
|
||||
return s.httpServerRequestDuration
|
||||
}
|
||||
|
||||
// HTTPClientRequestDuration returns the HTTP client request duration histogram.
|
||||
func (s *SemConvMetricsRegistry) HTTPClientRequestDuration() metric.Float64Histogram {
|
||||
func (s *SemConvMetricsRegistry) HTTPClientRequestDuration() httpconv.ClientRequestDuration {
|
||||
if s == nil {
|
||||
return nil
|
||||
return httpconv.ClientRequestDuration{}
|
||||
}
|
||||
|
||||
return s.httpClientRequestDuration
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/traefik/traefik/v3/pkg/middlewares"
|
||||
"github.com/traefik/traefik/v3/pkg/tracing"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ import (
|
|||
"github.com/traefik/traefik/v3/pkg/middlewares"
|
||||
"github.com/traefik/traefik/v3/pkg/middlewares/capture"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.37.0/httpconv"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -46,7 +46,7 @@ func newServerMetricsSemConv(ctx context.Context, semConvMetricRegistry *metrics
|
|||
}
|
||||
|
||||
func (e *semConvServerMetrics) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
if e.semConvMetricRegistry == nil || e.semConvMetricRegistry.HTTPServerRequestDuration() == nil || !SemConvMetricsEnabled(req.Context()) {
|
||||
if e.semConvMetricRegistry == nil || !SemConvMetricsEnabled(req.Context()) {
|
||||
e.next.ServeHTTP(rw, req)
|
||||
return
|
||||
}
|
||||
|
|
@ -70,12 +70,12 @@ func (e *semConvServerMetrics) ServeHTTP(rw http.ResponseWriter, req *http.Reque
|
|||
attrs = append(attrs, attribute.Key("error.type").String(strconv.Itoa(capt.StatusCode())))
|
||||
}
|
||||
|
||||
attrs = append(attrs, semconv.HTTPRequestMethodKey.String(req.Method))
|
||||
// Additional optional attributes.
|
||||
attrs = append(attrs, semconv.HTTPResponseStatusCode(capt.StatusCode()))
|
||||
attrs = append(attrs, semconv.NetworkProtocolName(strings.ToLower(req.Proto)))
|
||||
attrs = append(attrs, semconv.NetworkProtocolVersion(Proto(req.Proto)))
|
||||
attrs = append(attrs, semconv.ServerAddress(req.Host))
|
||||
attrs = append(attrs, semconv.URLScheme(req.Header.Get("X-Forwarded-Proto")))
|
||||
|
||||
e.semConvMetricRegistry.HTTPServerRequestDuration().Record(req.Context(), end.Sub(start).Seconds(), metric.WithAttributes(attrs...))
|
||||
e.semConvMetricRegistry.HTTPServerRequestDuration().Record(req.Context(), end.Sub(start).Seconds(),
|
||||
httpconv.RequestMethodAttr(req.Method), req.Header.Get("X-Forwarded-Proto"), attrs...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/traefik/traefik/v3/pkg/middlewares/observability"
|
||||
"github.com/traefik/traefik/v3/pkg/tracing"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ import (
|
|||
"github.com/traefik/traefik/v3/pkg/middlewares/observability"
|
||||
"github.com/traefik/traefik/v3/pkg/tracing"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.37.0/httpconv"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
|
|
@ -68,9 +68,7 @@ func (t *wrapper) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||
span.End(trace.WithTimestamp(end))
|
||||
}
|
||||
|
||||
if !observability.SemConvMetricsEnabled(req.Context()) ||
|
||||
t.semConvMetricRegistry == nil ||
|
||||
t.semConvMetricRegistry.HTTPClientRequestDuration() == nil {
|
||||
if !observability.SemConvMetricsEnabled(req.Context()) || t.semConvMetricRegistry == nil {
|
||||
return response, err
|
||||
}
|
||||
|
||||
|
|
@ -86,24 +84,27 @@ func (t *wrapper) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||
attrs = append(attrs, semconv.HTTPResponseStatusCode(statusCode))
|
||||
attrs = append(attrs, semconv.NetworkProtocolName(strings.ToLower(req.Proto)))
|
||||
attrs = append(attrs, semconv.NetworkProtocolVersion(observability.Proto(req.Proto)))
|
||||
attrs = append(attrs, semconv.ServerAddress(req.URL.Host))
|
||||
|
||||
var serverPort int
|
||||
_, port, splitErr := net.SplitHostPort(req.URL.Host)
|
||||
if splitErr != nil {
|
||||
switch req.URL.Scheme {
|
||||
case "http":
|
||||
attrs = append(attrs, semconv.ServerPort(80))
|
||||
serverPort = 80
|
||||
attrs = append(attrs, semconv.ServerPort(serverPort))
|
||||
case "https":
|
||||
attrs = append(attrs, semconv.ServerPort(443))
|
||||
serverPort = 443
|
||||
attrs = append(attrs, semconv.ServerPort(serverPort))
|
||||
}
|
||||
} else {
|
||||
intPort, _ := strconv.Atoi(port)
|
||||
attrs = append(attrs, semconv.ServerPort(intPort))
|
||||
serverPort, _ := strconv.Atoi(port)
|
||||
attrs = append(attrs, semconv.ServerPort(serverPort))
|
||||
}
|
||||
|
||||
attrs = append(attrs, semconv.URLScheme(req.Header.Get("X-Forwarded-Proto")))
|
||||
|
||||
t.semConvMetricRegistry.HTTPClientRequestDuration().Record(req.Context(), end.Sub(start).Seconds(), metric.WithAttributes(attrs...))
|
||||
t.semConvMetricRegistry.HTTPClientRequestDuration().Record(req.Context(), end.Sub(start).Seconds(),
|
||||
httpconv.RequestMethodAttr(req.Method), req.URL.Host, serverPort, attrs...)
|
||||
|
||||
return response, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import (
|
|||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package tracing
|
|||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
|
@ -15,6 +14,8 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
"github.com/traefik/traefik/v3/pkg/config/static"
|
||||
"github.com/traefik/traefik/v3/pkg/types"
|
||||
"go.opentelemetry.io/collector/pdata/pcommon"
|
||||
"go.opentelemetry.io/collector/pdata/ptrace"
|
||||
"go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.opentelemetry.io/otel/trace/noop"
|
||||
|
|
@ -76,15 +77,16 @@ func TestTracing(t *testing.T) {
|
|||
headers map[string]string
|
||||
resourceAttributes map[string]string
|
||||
wantServiceHeadersFn func(t *testing.T, headers http.Header)
|
||||
assertFn func(*testing.T, string)
|
||||
assertFn func(*testing.T, ptrace.Traces)
|
||||
}{
|
||||
{
|
||||
desc: "service name and version",
|
||||
assertFn: func(t *testing.T, trace string) {
|
||||
assertFn: func(t *testing.T, traces ptrace.Traces) {
|
||||
t.Helper()
|
||||
|
||||
assert.Regexp(t, `({"key":"service.name","value":{"stringValue":"traefik"}})`, trace)
|
||||
assert.Regexp(t, `({"key":"service.version","value":{"stringValue":"dev"}})`, trace)
|
||||
attributes := resourceAttributes(traces)
|
||||
assert.Equal(t, "traefik", attributes["service.name"])
|
||||
assert.Equal(t, "dev", attributes["service.version"])
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -92,10 +94,11 @@ func TestTracing(t *testing.T) {
|
|||
resourceAttributes: map[string]string{
|
||||
"service.environment": "custom",
|
||||
},
|
||||
assertFn: func(t *testing.T, trace string) {
|
||||
assertFn: func(t *testing.T, traces ptrace.Traces) {
|
||||
t.Helper()
|
||||
|
||||
assert.Regexp(t, `({"key":"service.environment","value":{"stringValue":"custom"}})`, trace)
|
||||
attributes := resourceAttributes(traces)
|
||||
assert.Equal(t, "custom", attributes["service.environment"])
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -111,12 +114,13 @@ func TestTracing(t *testing.T) {
|
|||
assert.Regexp(t, `(00-00000000000000000000000000000001-\w{16}-01)`, headers["Traceparent"][0])
|
||||
assert.Equal(t, []string{"foo=bar"}, headers["Tracestate"])
|
||||
},
|
||||
assertFn: func(t *testing.T, trace string) {
|
||||
assertFn: func(t *testing.T, traces ptrace.Traces) {
|
||||
t.Helper()
|
||||
|
||||
assert.Regexp(t, `("traceId":"00000000000000000000000000000001")`, trace)
|
||||
assert.Regexp(t, `("parentSpanId":"0000000000000001")`, trace)
|
||||
assert.Regexp(t, `("traceState":"foo=bar")`, trace)
|
||||
span := mainSpan(traces)
|
||||
assert.Equal(t, "00000000000000000000000000000001", span.TraceID().String())
|
||||
assert.Equal(t, "0000000000000001", span.ParentSpanID().String())
|
||||
assert.Equal(t, "foo=bar", span.TraceState().AsRaw())
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -127,11 +131,12 @@ func TestTracing(t *testing.T) {
|
|||
|
||||
assert.Regexp(t, `(00-\w{32}-\w{16}-01)`, headers["Traceparent"][0])
|
||||
},
|
||||
assertFn: func(t *testing.T, trace string) {
|
||||
assertFn: func(t *testing.T, traces ptrace.Traces) {
|
||||
t.Helper()
|
||||
|
||||
assert.Regexp(t, `("traceId":"\w{32}")`, trace)
|
||||
assert.Regexp(t, `("parentSpanId":"\w{16}")`, trace)
|
||||
span := mainSpan(traces)
|
||||
assert.Len(t, span.TraceID().String(), 32)
|
||||
assert.Empty(t, span.ParentSpanID().String())
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -145,11 +150,12 @@ func TestTracing(t *testing.T) {
|
|||
|
||||
assert.Regexp(t, `(00000000000000000000000000000001-\w{16}-1)`, headers["B3"][0])
|
||||
},
|
||||
assertFn: func(t *testing.T, trace string) {
|
||||
assertFn: func(t *testing.T, traces ptrace.Traces) {
|
||||
t.Helper()
|
||||
|
||||
assert.Regexp(t, `("traceId":"00000000000000000000000000000001")`, trace)
|
||||
assert.Regexp(t, `("parentSpanId":"0000000000000002")`, trace)
|
||||
span := mainSpan(traces)
|
||||
assert.Equal(t, "00000000000000000000000000000001", span.TraceID().String())
|
||||
assert.Equal(t, "0000000000000002", span.ParentSpanID().String())
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -160,11 +166,12 @@ func TestTracing(t *testing.T) {
|
|||
|
||||
assert.Regexp(t, `(\w{32}-\w{16}-1)`, headers["B3"][0])
|
||||
},
|
||||
assertFn: func(t *testing.T, trace string) {
|
||||
assertFn: func(t *testing.T, traces ptrace.Traces) {
|
||||
t.Helper()
|
||||
|
||||
assert.Regexp(t, `("traceId":"\w{32}")`, trace)
|
||||
assert.Regexp(t, `("parentSpanId":"\w{16}")`, trace)
|
||||
span := mainSpan(traces)
|
||||
assert.Len(t, span.TraceID().String(), 32)
|
||||
assert.Empty(t, span.ParentSpanID().String())
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -184,11 +191,12 @@ func TestTracing(t *testing.T) {
|
|||
assert.Equal(t, "1", headers["X-B3-Sampled"][0])
|
||||
assert.Len(t, headers["X-B3-Spanid"][0], 16)
|
||||
},
|
||||
assertFn: func(t *testing.T, trace string) {
|
||||
assertFn: func(t *testing.T, traces ptrace.Traces) {
|
||||
t.Helper()
|
||||
|
||||
assert.Regexp(t, `("traceId":"00000000000000000000000000000001")`, trace)
|
||||
assert.Regexp(t, `("parentSpanId":"0000000000000002")`, trace)
|
||||
span := mainSpan(traces)
|
||||
assert.Equal(t, "00000000000000000000000000000001", span.TraceID().String())
|
||||
assert.Equal(t, "0000000000000002", span.ParentSpanID().String())
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -201,11 +209,12 @@ func TestTracing(t *testing.T) {
|
|||
assert.Equal(t, "1", headers["X-B3-Sampled"][0])
|
||||
assert.Regexp(t, `(\w{16})`, headers["X-B3-Spanid"][0])
|
||||
},
|
||||
assertFn: func(t *testing.T, trace string) {
|
||||
assertFn: func(t *testing.T, traces ptrace.Traces) {
|
||||
t.Helper()
|
||||
|
||||
assert.Regexp(t, `("traceId":"\w{32}")`, trace)
|
||||
assert.Regexp(t, `("parentSpanId":"")`, trace)
|
||||
span := mainSpan(traces)
|
||||
assert.Len(t, span.TraceID().String(), 32)
|
||||
assert.Empty(t, span.ParentSpanID().String())
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -231,11 +240,12 @@ func TestTracing(t *testing.T) {
|
|||
|
||||
assert.Regexp(t, `(00000000000000000000000000000001:\w{16}:0:1)`, headers["Uber-Trace-Id"][0])
|
||||
},
|
||||
assertFn: func(t *testing.T, trace string) {
|
||||
assertFn: func(t *testing.T, traces ptrace.Traces) {
|
||||
t.Helper()
|
||||
|
||||
assert.Regexp(t, `("traceId":"00000000000000000000000000000001")`, trace)
|
||||
assert.Regexp(t, `("parentSpanId":"\w{16}")`, trace)
|
||||
span := mainSpan(traces)
|
||||
assert.Equal(t, "00000000000000000000000000000001", span.TraceID().String())
|
||||
assert.Len(t, span.ParentSpanID().String(), 16)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -246,11 +256,12 @@ func TestTracing(t *testing.T) {
|
|||
|
||||
assert.Regexp(t, `(\w{32}:\w{16}:0:1)`, headers["Uber-Trace-Id"][0])
|
||||
},
|
||||
assertFn: func(t *testing.T, trace string) {
|
||||
assertFn: func(t *testing.T, traces ptrace.Traces) {
|
||||
t.Helper()
|
||||
|
||||
assert.Regexp(t, `("traceId":"\w{32}")`, trace)
|
||||
assert.Regexp(t, `("parentSpanId":"\w{16}")`, trace)
|
||||
span := mainSpan(traces)
|
||||
assert.Len(t, span.TraceID().String(), 32)
|
||||
assert.Empty(t, span.ParentSpanID().String())
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -264,11 +275,12 @@ func TestTracing(t *testing.T) {
|
|||
|
||||
assert.Regexp(t, `(Root=1-5759e988-bd862e3fe1be46a994272793;Parent=\w{16};Sampled=1)`, headers["X-Amzn-Trace-Id"][0])
|
||||
},
|
||||
assertFn: func(t *testing.T, trace string) {
|
||||
assertFn: func(t *testing.T, traces ptrace.Traces) {
|
||||
t.Helper()
|
||||
|
||||
assert.Regexp(t, `("traceId":"5759e988bd862e3fe1be46a994272793")`, trace)
|
||||
assert.Regexp(t, `("parentSpanId":"\w{16}")`, trace)
|
||||
span := mainSpan(traces)
|
||||
assert.Equal(t, "5759e988bd862e3fe1be46a994272793", span.TraceID().String())
|
||||
assert.Len(t, span.ParentSpanID().String(), 16)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -279,11 +291,12 @@ func TestTracing(t *testing.T) {
|
|||
|
||||
assert.Regexp(t, `(Root=1-\w{8}-\w{24};Parent=\w{16};Sampled=1)`, headers["X-Amzn-Trace-Id"][0])
|
||||
},
|
||||
assertFn: func(t *testing.T, trace string) {
|
||||
assertFn: func(t *testing.T, traces ptrace.Traces) {
|
||||
t.Helper()
|
||||
|
||||
assert.Regexp(t, `("traceId":"\w{32}")`, trace)
|
||||
assert.Regexp(t, `("parentSpanId":"\w{16}")`, trace)
|
||||
span := mainSpan(traces)
|
||||
assert.Len(t, span.TraceID().String(), 32)
|
||||
assert.Empty(t, span.ParentSpanID().String())
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -294,16 +307,17 @@ func TestTracing(t *testing.T) {
|
|||
|
||||
assert.Empty(t, headers)
|
||||
},
|
||||
assertFn: func(t *testing.T, trace string) {
|
||||
assertFn: func(t *testing.T, traces ptrace.Traces) {
|
||||
t.Helper()
|
||||
|
||||
assert.Regexp(t, `("traceId":"\w{32}")`, trace)
|
||||
assert.Regexp(t, `("parentSpanId":"\w{16}")`, trace)
|
||||
span := mainSpan(traces)
|
||||
assert.Len(t, span.TraceID().String(), 32)
|
||||
assert.Empty(t, span.ParentSpanID().String())
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
traceCh := make(chan string)
|
||||
traceCh := make(chan ptrace.Traces)
|
||||
collector := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
gzr, err := gzip.NewReader(r.Body)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -315,10 +329,7 @@ func TestTracing(t *testing.T) {
|
|||
err = req.UnmarshalProto(body)
|
||||
require.NoError(t, err)
|
||||
|
||||
marshalledReq, err := json.Marshal(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
traceCh <- string(marshalledReq)
|
||||
traceCh <- req.Traces()
|
||||
}))
|
||||
t.Cleanup(collector.Close)
|
||||
|
||||
|
|
@ -384,10 +395,10 @@ func TestTracing(t *testing.T) {
|
|||
case <-time.After(10 * time.Second):
|
||||
t.Error("Trace not exported")
|
||||
|
||||
case trace := <-traceCh:
|
||||
case traces := <-traceCh:
|
||||
assert.Equal(t, http.StatusOK, rw.Code)
|
||||
if test.assertFn != nil {
|
||||
test.assertFn(t, trace)
|
||||
test.assertFn(t, traces)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -464,3 +475,30 @@ func TestNewTracer_HeadersCanonicalization(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
// resourceAttributes extracts resource attributes as a map.
|
||||
func resourceAttributes(traces ptrace.Traces) map[string]string {
|
||||
attributes := make(map[string]string)
|
||||
if traces.ResourceSpans().Len() > 0 {
|
||||
resource := traces.ResourceSpans().At(0).Resource()
|
||||
resource.Attributes().Range(func(k string, v pcommon.Value) bool {
|
||||
if v.Type() == pcommon.ValueTypeStr {
|
||||
attributes[k] = v.Str()
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
return attributes
|
||||
}
|
||||
|
||||
// mainSpan gets the main span from traces (assumes single span for testing).
|
||||
func mainSpan(traces ptrace.Traces) ptrace.Span {
|
||||
for _, resourceSpans := range traces.ResourceSpans().All() {
|
||||
for _, scopeSpans := range resourceSpans.ScopeSpans().All() {
|
||||
if scopeSpans.Spans().Len() > 0 {
|
||||
return scopeSpans.Spans().At(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ptrace.NewSpan()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
"github.com/rs/zerolog/log"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
|
||||
kerror "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
kclientset "k8s.io/client-go/kubernetes"
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp"
|
||||
otelsdk "go.opentelemetry.io/otel/sdk/log"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/encoding/gzip"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import (
|
|||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/encoding/gzip"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue