| 1 | package telemetry |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "go.opentelemetry.io/otel" |
| 7 | "go.opentelemetry.io/otel/propagation" |
| 8 | ) |
| 9 | |
| 10 | // Carry returns ctx's trace context as a map, to keep with work that goes on |
| 11 | // later, like a row in the outbox. Extract continues the trace from it. |
| 12 | func Carry(ctx context.Context) propagation.MapCarrier { |
| 13 | c := propagation.MapCarrier{} |
| 14 | otel.GetTextMapPropagator().Inject(ctx, c) |
| 15 | return c |
| 16 | } |
| 17 | |
| 18 | // Inject writes ctx's trace context into c, like a message's headers. |
| 19 | func Inject(ctx context.Context, c propagation.TextMapCarrier) { |
| 20 | otel.GetTextMapPropagator().Inject(ctx, c) |
| 21 | } |
| 22 | |
| 23 | // Extract returns ctx, with the trace context in c: the next span we start |
| 24 | // is a child of the span that wrote it. |
| 25 | func Extract(ctx context.Context, c propagation.TextMapCarrier) context.Context { |
| 26 | return otel.GetTextMapPropagator().Extract(ctx, c) |
| 27 | } |