Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tracing/internal/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func ToKeyVals(attr slog.Attr) (kvs []attribute.KeyValue) {
case slog.KindBool:
return []attribute.KeyValue{attribute.Bool(key, val.Bool())}
case slog.KindDuration:
return []attribute.KeyValue{attribute.Float64(key, val.Duration().Seconds())}
case slog.KindFloat64:
return []attribute.KeyValue{attribute.Float64(key, val.Float64())}
case slog.KindInt64:
Expand Down
1 change: 1 addition & 0 deletions tracing/internal/convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestToKeyVal(t *testing.T) {
in slog.Attr
expected []attribute.KeyValue
}{
{slog.Duration("duration", 1500 * time.Millisecond), []attribute.KeyValue{attribute.Float64("duration", 1.5)}},
{slog.Bool("bool", true), []attribute.KeyValue{attribute.Bool("bool", true)}},
{slog.Float64("float64", 1.0), []attribute.KeyValue{attribute.Float64("float64", 1.0)}},
{slog.Int64("int64", 1), []attribute.KeyValue{attribute.Int64("int64", 1)}},
Expand Down
5 changes: 1 addition & 4 deletions tracing/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

const (
instrumentationCodeProviderName = "github.com/els0r/goProbe/pkg/tracing"
instrumentationCodeProviderName = "github.com/els0r/telemetry/tracing"
)

type tracingConfig struct {
Expand Down Expand Up @@ -142,9 +142,6 @@ func NewTracerProvider(opts ...Option) (tp *sdktrace.TracerProvider, err error)
return nil, errorNoSpanExporter
}

if err != nil {
return nil, fmt.Errorf("failed to create resource: %w", err)
}
// Register the trace exporter with a TracerProvider, using a batch
// span processor to aggregate spans before export.
bsp := sdktrace.NewBatchSpanProcessor(exporter)
Expand Down
8 changes: 3 additions & 5 deletions tracing/traceparent.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ func ContextFromW3CTraceparentHeader(ctx context.Context, traceparentHeader stri
}

if traceparentHeader == "" {
return context.Background()
return ctx
}

p := propagation.TraceContext{}
otel.SetTextMapPropagator(p)

return p.Extract(ctx,
propagation.MapCarrier{w3traceparentHeaderKey: traceparentHeader},
Expand All @@ -79,11 +78,10 @@ func ContextFromB3SingleHeader(ctx context.Context, b3Header string) context.Con
}

if b3Header == "" {
return context.Background()
return ctx
}

p := b3.New(b3.WithInjectEncoding(b3.B3MultipleHeader | b3.B3SingleHeader))
otel.SetTextMapPropagator(p)

return p.Extract(ctx, propagation.MapCarrier{b3SingleHeaderKey: b3Header})
}
Expand Down Expand Up @@ -134,7 +132,7 @@ func GetSpanID(ctx context.Context) (spanID string) {
return spanID
}
sc := trace.SpanContextFromContext(ctx)
if sc.HasTraceID() {
if sc.IsValid() {
return sc.SpanID().String()
}
return spanID
Expand Down
Loading