Custom Spans
Generates: Spans
Measure execution time of specific operations.
Automatic Span Management
trackSpan() starts the span, runs your action, and ends it automatically (even on exception):
PulseSDK.INSTANCE.trackSpan(
spanName = "fetch_user_data",
params = mapOf("user_id" to "12345"),
) {
apiClient.getUserProfile("12345")
}
Manual Span Control
Use startSpan() when you need to end the span at a different point:
val endSpan = PulseSDK.INSTANCE.startSpan(
spanName = "image_processing",
params = mapOf("image_id" to "img-123"),
)
try {
processImage()
} finally {
endSpan()
}
Advanced: OpenTelemetry APIs
For cases where you need the full OTel API:
val otelRum = PulseSDK.INSTANCE.getOtelOrNull() ?: return
val tracer = otelRum.openTelemetry.tracerProvider.get("my-instrumentation")
val span = tracer.spanBuilder("custom_operation").startSpan()
try {
// your work
} finally {
span.end()
}
Attributes
Custom spans do not set pulse.type by default. Any params you pass become span attributes, plus automatic global attributes (session.id, device, OS, etc.).
Related
- Custom Events — Track business events
- Error Tracking — Report non-fatal errors