Capturing logs with OpenTelemetry
By default, ASP.NET Core applications write logs to stdout
, but since we want to correlate them with traces and query them by any attribute, we should export them to the observability backend or the log management tool that supports it. If your vendor supports ILogger
, you can send logs directly to your vendor by configuring the corresponding logging provider. It will be up to this logging provider to annotate logs with trace context or environment information. By collecting logs with OpenTelemetry, we can annotate them consistently with other signals.
Let’s see how to collect logs from the meme application with OpenTelemetry. To get the most out of the structure, we’ll export them to ClickHouse – an open source database that supports SQL queries.
Here’s an example of a configuration that exports logs with the OpenTelemetry Protocol (OTLP) exporter to the OpenTelemetry Collector first:
frontend/Program.cs
builder...