Skip to content

Instantly share code, notes, and snippets.

@benhenryhunter
Last active March 8, 2024 18:48
Show Gist options
  • Save benhenryhunter/9e2c8f7b89f67950fa5f15f630e9d566 to your computer and use it in GitHub Desktop.
Save benhenryhunter/9e2c8f7b89f67950fa5f15f630e9d566 to your computer and use it in GitHub Desktop.
example of the parent, child, and sibling tracing structure
func TraceExample(rootContext context.Context) {
parentSpan := trace.SpanFromContext(rootContext)
rootContextWithParentSpan = trace.ContextWithSpan(context.Background(), parentSpan)
traceFunctionContext, traceFunctionSpan := s.tracer.Start(rootContextWithParentSpan, "traceFunction")
childContext, childSpan := s.tracer.Start(traceFunctionContext, "childTrace")
_, grandchildSpan := s.tracer.Start(childContext, "grandchildTrace")
grandchildSpan.End()
childSpan.End()
siblingContext, siblingSpan := s.tracer.Start(rootContextWithParentSpan, "siblingTrace")
_, siblingChildSpan := s.tracer.Start(siblingContext, "siblingChildTrace")
siblingChildSpan.End()
siblingSpan.End()
parentSpan.End()
}
// heirarchical tracing
// ^ parent
// ^ child
// ^ grandchild
// ^ sibling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment