open-telemetry / opentelemetry-dotnet

The OpenTelemetry .NET Client
https://opentelemetry.io
Apache License 2.0
3.17k stars 751 forks source link

Transform `exception.message` for custom exception types #5786

Open lvde0 opened 1 month ago

lvde0 commented 1 month ago

What is the question?

Is there any reasonable way of transforming the exception.message of an exception record? I have this ProblemDetails (RFC 7807) exception that carries its information inside the Detail property and not the Message. Would be nice if I could send that to the OTLP endpoint.

Additional context

No response

cijothomas commented 4 weeks ago

Is that for Activity or LogRecord?

lvde0 commented 4 weeks ago

@cijothomas For LogRecord

cijothomas commented 4 weeks ago

The raw Exception object is stored in LogRecord, so you can write a LogRecordProcessor that can read the Exception, get the additional details from it, and store it as attributes on LogRecord. (Its not super straightforward, https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry/Logs/LogRecord.cs maybe used as a starting example to make extra attributes)

This is a doc gap as well. If you are not able to get it working, let us know.