serilog-contrib / serilog-sinks-applicationinsights

A Serilog sink that writes events to Microsoft Azure Application Insights
Apache License 2.0
220 stars 72 forks source link

Exceptions not getting logged in Azure App Insights due its size #223

Open fdrumondwoolworths opened 8 months ago

fdrumondwoolworths commented 8 months ago

Description When using Serilog to log exceptions, the message/event payload is beyond azure app-insights limits and because of that, exceptions don't get logged.

Logging the same exception with a TelemetryClient, in the other hand, logs a message which is comparatively much smaller and gets logged by azure app-insights.

Reproduction In order to reproduce the problem, I'd have to create a docker with Elastic Search running, create an index and write a query. That would be too much of a hassle for anyone to reproduce the problem. However, I can provide you with samples of the messages being posted by both TelemetryClient and Serilog, so that you can see that Serilog generates a much longer payload.

Here's a link with the both messages: https://www.diffchecker.com/APhYHCTO/ While the Telemetry logs the exception nicely, the Serilog logs the same exception in a completely different fashion.

The Telemetry ignores the .Request and .Response properties in the ElasticsearchClientException, while Serilog seems to be serializing them as thousands of dictionary keys in the properties list.

BTW, both .Request and .Response in the ElasticsearchClientException are read-only properties, therefore I can't set them to null as a workaround. I've tried Destructurer (IExceptionDestructurer) and Enricher (ILogEventEnricher) but that's didn't help.

Expected behavior If Serilog wants to serialise .Request and .Response, it shouldn't be that way, right?

Relevant package, tooling and runtime versions Serilog.Sinks.ApplicationInsights 4.0.0

nblumhardt commented 8 months ago

Hi! You don't happen to be using the Serilog.Exceptions package, by any chance?

fdrumondwoolworths commented 8 months ago

@nblumhardt hi! I haven't installed this package but I see it's a transitive package in my project.

image

nblumhardt commented 8 months ago

That's the one; however that's being referenced, it'll be configured in your logging pipeline and is responsible for the ExceptionDetail property/data on the resulting events.