-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prose/filter): inject span context in w3c format for presidio
- Loading branch information
Showing
2 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
privacy-profile-composer/pkg/envoyfilter/internal/common/otel_propagator.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/openzipkin/zipkin-go/model" | ||
"go.opentelemetry.io/otel/propagation" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
var GlobalOtelPropagator = propagation.NewCompositeTextMapPropagator( | ||
propagation.TraceContext{}, | ||
propagation.Baggage{}, | ||
) | ||
|
||
func otelSpanContextFromZipkin(span model.SpanContext) (trace.SpanContext, error) { | ||
traceFlags := trace.TraceFlags(0) | ||
if span.Sampled == nil { | ||
traceFlags = traceFlags.WithSampled(false) | ||
} else { | ||
traceFlags = traceFlags.WithSampled(*span.Sampled) | ||
} | ||
|
||
traceID, err := trace.TraceIDFromHex(fmt.Sprintf("%032s", span.TraceID.String())) | ||
if err != nil { | ||
return trace.NewSpanContext( | ||
trace.SpanContextConfig{ | ||
TraceFlags: traceFlags, | ||
TraceState: trace.TraceState{}, | ||
Remote: false, | ||
}, | ||
), fmt.Errorf("invalid trace ID: %w", err) | ||
} | ||
|
||
spanID, err := trace.SpanIDFromHex(span.ID.String()) | ||
if err != nil { | ||
return trace.NewSpanContext( | ||
trace.SpanContextConfig{ | ||
TraceID: traceID, | ||
TraceFlags: traceFlags, | ||
TraceState: trace.TraceState{}, | ||
Remote: false, | ||
}, | ||
), fmt.Errorf("invalid span ID: %w", err) | ||
} | ||
|
||
return trace.NewSpanContext( | ||
trace.SpanContextConfig{ | ||
TraceID: traceID, | ||
SpanID: spanID, | ||
TraceFlags: traceFlags, | ||
TraceState: trace.TraceState{}, | ||
Remote: false, | ||
}, | ||
), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters