private static void performWork ( Span parent ) { SpanBuilder spanBuilder = tracer . spanBuilderWithExplicitParent ( "internal_work" , parent ) . setRecordEvents ( true ) . setSampler ( Samplers . alwaysSample ( ) ) ; try ( Scope scope = spanBuilder . startScopedSpan ( ) ) { Span span = tracer . getCurrentSpan ( ) ; span . putAttribute ( "my_attribute" , AttributeValue . stringAttributeValue ( "blue" ) ) ; span . addAnnotation ( "Performing work." ) ; sleepFor ( 20 ) ; // Working hard here. span . addAnnotation ( "Done work." ) ; } }
A helper function that performs some work in its own Span .