Skip to content

Instantly share code, notes, and snippets.

@up1
Last active September 8, 2022 21:10
Show Gist options
  • Save up1/ab7d7cadcca1f8cff4a6803754927d15 to your computer and use it in GitHub Desktop.
Save up1/ab7d7cadcca1f8cff4a6803754927d15 to your computer and use it in GitHub Desktop.
Go Tracing + OpenTelemetry
func producer(ctx context.Context) {
tr := global.TraceProvider().Tracer("component-producer")
_, span := tr.Start(ctx, "producer")
defer span.End()
// Get tracing id and Parent span id
traceId := fmt.Sprintf("%016x", span.SpanContext().TraceID)
spanId := fmt.Sprintf("%016x", span.SpanContext().SpanID)
// Add to message
}
func consumer(traceID string, spanID string) {
fn := initTracer("trace-consumer")
defer fn()
tid, _ := core.TraceIDFromHex(traceID)
sid, _ := core.SpanIDFromHex(spanID)
ctx := context.Background()
tr := global.TraceProvider().Tracer("consumer-step01")
sc := core.SpanContext{
TraceID: tid,
SpanID: sid,
TraceFlags: 0x0,
}
_, span := tr.Start(trace.ContextWithRemoteSpanContext(ctx, sc), "consumer-span1")
span.End()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment