mirror of
https://github.com/sajari/docconv.git
synced 2026-10-18 22:51:09 +08:00
26 lines
553 B
Go
26 lines
553 B
Go
package cloudtrace
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type traceKey struct{}
|
|
type spanKey struct{}
|
|
|
|
func contextWithTraceInfo(ctx context.Context, traceHeader string) context.Context {
|
|
traceID, spanID := parseHeader(traceHeader)
|
|
if traceID != "" {
|
|
ctx = context.WithValue(ctx, traceKey{}, traceID)
|
|
}
|
|
if spanID != "" {
|
|
ctx = context.WithValue(ctx, spanKey{}, spanID)
|
|
}
|
|
return ctx
|
|
}
|
|
|
|
func traceInfoFromContext(ctx context.Context) (traceID, spanID string) {
|
|
traceID, _ = ctx.Value(traceKey{}).(string)
|
|
spanID, _ = ctx.Value(spanKey{}).(string)
|
|
return
|
|
}
|