Package org.bithon.agent.sdk.tracing
Class SpanScopeBuilder
java.lang.Object
org.bithon.agent.sdk.tracing.SpanScopeBuilder
Builder for creating scoped spans with fluent API.
Use
TraceContext.newScopedSpan(String) to create an instance.
For example,
try (ISpanScope span = TraceContext.newScopedSpan("operation")
.kind(SpanKind.CLIENT) // optional, default is SpanKind.INTERNAL
.create()) {
// Update tags if needed
span.tag("key", "value");
// Business logic here
}
- Author:
- frank.chen021@outlook.com
- Date:
- 2025/01/20
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
LOGGER
-
LOG_INTERVAL_MS
private static final long LOG_INTERVAL_MS- See Also:
-
lastLogTime
private static long lastLogTime -
operationName
-
kind
-
-
Constructor Details
-
SpanScopeBuilder
-
-
Method Details
-
shouldLog
private static boolean shouldLog() -
kind
Sets the span kind for this scoped span.- Parameters:
kind- the span kind to use- Returns:
- this builder for method chaining
-
create
Creates a scoped span within the current tracing context.The created span will be a child of the current active span. If the
kind(SpanKind)is not called, the default kind isSpanKind.INTERNAL.- Returns:
- an ISpan ready for use in try-with-resources. Callers MUST ensure to close the span to avoid resource leaks.
- Throws:
SdkException- if there's no active tracing context.
-
operationName
-
kind
-