context.go 936 B

12345678910111213141516171819202122232425262728
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package baggage // import "go.opentelemetry.io/otel/baggage"
  4. import (
  5. "context"
  6. "go.opentelemetry.io/otel/internal/baggage"
  7. )
  8. // ContextWithBaggage returns a copy of parent with baggage.
  9. func ContextWithBaggage(parent context.Context, b Baggage) context.Context {
  10. // Delegate so any hooks for the OpenTracing bridge are handled.
  11. return baggage.ContextWithList(parent, b.list)
  12. }
  13. // ContextWithoutBaggage returns a copy of parent with no baggage.
  14. func ContextWithoutBaggage(parent context.Context) context.Context {
  15. // Delegate so any hooks for the OpenTracing bridge are handled.
  16. return baggage.ContextWithList(parent, nil)
  17. }
  18. // FromContext returns the baggage contained in ctx.
  19. func FromContext(ctx context.Context) Baggage {
  20. // Delegate so any hooks for the OpenTracing bridge are handled.
  21. return Baggage{list: baggage.ListFromContext(ctx)}
  22. }