Download pkg/otelx/spancontext.go from Leon4gr45/openmeter: direct link, hf CLI and curl.
- Browser
- Download file 676 Bytes
-
https://huggingface.co/spaces/Leon4gr45/openmeter/resolve/main/pkg/otelx/spancontext.go
- Command line
-
hf download hf://spaces/Leon4gr45/openmeter/pkg/otelx/spancontext.go
-
curl -L -o spancontext.go https://huggingface.co/spaces/Leon4gr45/openmeter/resolve/main/pkg/otelx/spancontext.go
676 Bytes
| package otelx | |
| import ( | |
| "encoding/base64" | |
| "encoding/json" | |
| "go.opentelemetry.io/otel/trace" | |
| ) | |
| const OTelSpanContextKey = "otel.span.context" | |
| func SerializeSpanContext(c trace.SpanContext) ([]byte, error) { | |
| b, err := c.MarshalJSON() | |
| if err != nil { | |
| return nil, err | |
| } | |
| s := base64.StdEncoding.EncodeToString(b) | |
| return []byte(s), nil | |
| } | |
| func DeserializeSpanContext(b []byte) (*trace.SpanContext, error) { | |
| b, err := base64.StdEncoding.DecodeString(string(b)) | |
| if err != nil { | |
| return nil, err | |
| } | |
| config := trace.SpanContextConfig{} | |
| err = json.Unmarshal(b, &config) | |
| if err != nil { | |
| return nil, err | |
| } | |
| ctx := trace.NewSpanContext(config) | |
| return &ctx, nil | |
| } | |