Created
September 4, 2020 14:40
-
-
Save carlosalberto/ef2c8f4762aa7cfee249984c17a83058 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import opentelemetry.context.Scope; | |
import opentelemetry.trace.Tracer; | |
import opentelemetry.trace.Span; | |
# No imports on Brave | |
// Start a new trace or a span within an existing trace representing an operation | |
Span span = tracer.spanBuilder("encode").startSpan(); | |
// Put the span in "scope" so that downstream code such as loggers can see trace IDs | |
try (Scope scope = tracer.withSpan(span)) { | |
return encoder.encode(); | |
} catch (RuntimeException | Error e) { | |
span.recordException(e); // Unless you handle exceptions, you might not know the operation failed! | |
throw e; | |
} finally { | |
span.end(); // note the scope is independent of the span. Always finish a span. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment