Package org.bithon.agent.sdk.tracing
Class TraceContext
java.lang.Object
org.bithon.agent.sdk.tracing.TraceContext
- Author:
- frank.chen021@outlook.com
- Date:
- 8/5/25 5:47 pm
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static longprivate static final longprivate static final Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ISpanScopeReturns the current span scope, or a no-op span scope if there is no active span.static StringReturns the span ID of the current span, or null if there is no active span.static StringReturns the trace ID of the current trace context, or null if there is no active trace.static ISpanDeprecated.static SpanScopeBuildernewScopedSpan(String operationName) Creates a new scoped span builder for the given operation.static TraceScopeBuilderCreates a new trace scope builder for the given operation.private static boolean
-
Field Details
-
LOGGER
-
LOG_INTERVAL_MS
private static final long LOG_INTERVAL_MS- See Also:
-
lastLogTime
private static long lastLogTime
-
-
Constructor Details
-
TraceContext
public TraceContext()
-
-
Method Details
-
shouldLog
private static boolean shouldLog() -
currentTraceId
Returns the trace ID of the current trace context, or null if there is no active trace. -
currentSpanId
Returns the span ID of the current span, or null if there is no active span. -
currentSpan
Returns the current span scope, or a no-op span scope if there is no active span. Generally, you should not call the 'close' method after using the returned span scope.- Since:
- 1.2.3
-
newScopedSpan
Deprecated.UsenewScopedSpan(String)instead. This method will be removed in a future version. -
newScopedSpan
Creates a new scoped span builder for the given operation. Use the builder to configure the span and then call attach() to start the span.Examples:
// Simple scoped span try (ISpanScope span = TraceContext.newScopedSpan("operation").attach()) { // do your work here } // Scoped span with custom kind try (ISpanScope span = TraceContext.newScopedSpan("operation") .kind(SpanKind.CLIENT) .attach()) { // do your work here }- Parameters:
operationName- the name of the operation.- Returns:
- a SpanScopeBuilder for configuring and creating the span
- Throws:
IllegalArgumentException- if the given operation name is null- Since:
- 1.2.2
-
newTrace
Creates a new trace scope builder for the given operation. Use the builder to configure the trace and then call attach() to start tracing.Examples:
// Simple root trace try (ITraceScope scope = TraceContext.newTrace("operation").attach()) { // do your work here } // Root trace with custom tracing mode try (ITraceScope scope = TraceContext.newTrace("operation") .withTracingMode(TracingMode.LOGGING) .attach()) { // do your work here } // Cross-thread continuation String traceId = TraceContext.currentTraceId(); String parentSpanId = TraceContext.currentSpanId(); ITraceScope asyncTrace = TraceContext.newTrace("background-work") .withParent(traceId, parentSpanId) .attach(); // pass asyncTrace to another thread...- Parameters:
operationName- the name of the operation.- Returns:
- a TraceScopeBuilder for configuring and creating the trace
- Throws:
IllegalArgumentException- if the given operation name is null- Since:
- 1.2.2
-
newScopedSpan(String)instead.