swift-distributed-tracing icon indicating copy to clipboard operation
swift-distributed-tracing copied to clipboard

Ability to set error event metadata when using withSpan

Open czechboy0 opened this issue 10 months ago • 1 comments

When using swift-distributing-tracing with the withSpan methods, you get the benefit of having recordError automatically being called on the span if an error was raised. However, you do not get the opportunity to annotate the error event attributes. In particular, OpenTelemetry has specific attributes that should be set of the error event attributes. There's no easy way for those to be set currently, and an adopter needs to drop down to catching the error and calling recordError manually.

We could consider adding some hook or exposing some metadata to recordError to make this specific information available to the implementers of a Tracer backend.

czechboy0 avatar Mar 06 '25 11:03 czechboy0

This might potentially look something like this:

try withSpan { span in
  throw CancellationError()
}
onError: { error, span in
  // Modify the span
}

and/or we could introduce a new protocol that errors could conform to that allows them to add additional context to the span

FranzBusch avatar Nov 06 '25 10:11 FranzBusch