Learn advanced manual span management techniques for fine-grained observability control
withActiveSpan
method.
withActiveSpan
method is the recommended approach for most manual instrumentation needs. It automatically handles context propagation, error handling, and span cleanup, making it both safer and easier to use than manual span management. For consistent attribute naming, combine this with Semantic Conventions.
withActiveSpan
automatically handles errors and ensures proper span cleanup:
withActiveSpan
automatically propagates span context to child operations:
withActiveSpan
provides, you can manually manage span lifecycle, attributes, and context propagation.
startActiveSpan
provides automatic context management but requires manual error handling:
startSpan
gives you complete control but requires manual context management:
withActiveSpan
isn’t sufficient:
withActiveSpan
for most use caseswithActiveSpan
for:withActiveSpan
method provides the best balance of ease of use, safety, and functionality. Only use manual span management when you need specific control over span lifecycle or context propagation that withActiveSpan
cannot provide.