mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat: unified tracing between coderd<->provisionerd (#7370)
This commit is contained in:
@ -5,6 +5,8 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
@ -41,3 +43,13 @@ func RunWithoutSpan(ctx context.Context, fn func(ctx context.Context)) {
|
||||
ctx = trace.ContextWithSpan(ctx, NoopSpan)
|
||||
fn(ctx)
|
||||
}
|
||||
|
||||
func MetadataFromContext(ctx context.Context) map[string]string {
|
||||
metadata := make(map[string]string)
|
||||
otel.GetTextMapPropagator().Inject(ctx, propagation.MapCarrier(metadata))
|
||||
return metadata
|
||||
}
|
||||
|
||||
func MetadataToContext(ctx context.Context, metadata map[string]string) context.Context {
|
||||
return otel.GetTextMapPropagator().Extract(ctx, propagation.MapCarrier(metadata))
|
||||
}
|
||||
|
Reference in New Issue
Block a user