baggage.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. package telemetry
  2. import (
  3. "context"
  4. "go.opentelemetry.io/otel/attribute"
  5. "go.opentelemetry.io/otel/baggage"
  6. "go.opentelemetry.io/otel/sdk/trace"
  7. )
  8. // Copied from https://github.com/honeycombio/honeycomb-opentelemetry-go
  9. type baggageSpanProcessor struct{}
  10. var _ trace.SpanProcessor = (*baggageSpanProcessor)(nil)
  11. // NewBaggageSpanProcessor returns a new baggageSpanProcessor.
  12. //
  13. // The Baggage span processor duplicates onto a span the attributes found
  14. // in Baggage in the parent context at the moment the span is started.
  15. func NewBaggageSpanProcessor() trace.SpanProcessor {
  16. return &baggageSpanProcessor{}
  17. }
  18. func (processor baggageSpanProcessor) OnStart(ctx context.Context, span trace.ReadWriteSpan) {
  19. baggage := baggage.FromContext(ctx)
  20. for _, entry := range baggage.Members() {
  21. span.SetAttributes(attribute.String(entry.Key(), entry.Value()))
  22. }
  23. }
  24. func (processor baggageSpanProcessor) OnEnd(s trace.ReadOnlySpan) {}
  25. func (processor baggageSpanProcessor) Shutdown(context.Context) error { return nil }
  26. func (processor baggageSpanProcessor) ForceFlush(context.Context) error { return nil }