-
Notifications
You must be signed in to change notification settings - Fork 72
Description
Describe your suggestion
Currently, when using the TraceTelemetryConverter, if a log message contains an exception it is logged to AI as an ExceptionTelemetry, otherwise as a TraceTelemetry. At least in our scenario, we don't really differentiate that much between exceptions and other errors, they must all be handled adequately. The current approach means that all our queries must start with exceptions | union traces
, and must also account for the data in the tables being different (for example the message in exceptions is the exception message, not the logged message).
When an exception is logged as a trace, it should have customData["exception"] = exception.ToString()
(or something)
It would probably also be useful for someone to have the options LogExceptionsAs = "Exceptions" (default) | "Traces" | "Both"
Application Insights itself seems to allow this with
builder.AddApplicationInsights(options => options.TrackExceptionsAsExceptionTelemetry = false);
Describe alternatives you've considered
My current workaround is to write my own TelemetryConverter
public class ExceptionsAsTracesTelemetryConverter : TraceTelemetryConverter
{
public override IEnumerable<ITelemetry> Convert(LogEvent logEvent, IFormatProvider formatProvider)
{
if (logEvent.Exception != null)
{
var evtCopy = new LogEvent(logEvent.Timestamp, logEvent.Level, null, logEvent.MessageTemplate, logEvent.Properties.Select(kvp => new LogEventProperty(kvp.Key, kvp.Value)));
foreach (TraceTelemetry t in base.Convert(evtCopy, formatProvider))
{
t.Properties["exception"] = logEvent.Exception.ToString();
yield return t;
}
}
else
{
foreach (var e in base.Convert(logEvent, formatProvider))
{
yield return e;
}
}
}
}
This works, but it seems to me that this is a feature that would make sense to have built-in.