Is it possible to use Serilog with OpenTelemetry?
https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/docs/logs/getting-started/README.md
One approach you might consider if you're running apps in Docker or Kubernetes is to just make Serilog log to console (as per 12 factor logging guidelines). From there the console logs can get received by a collector/forwarder agent such as the OpenTelemetry collector agent (or others like Logstash of Fluentd) and exported to a destination solution (e.g. Splunk or Elasticsearch). Some ways for a collector/forwarder agent to receive console logs include:
A lot of the collector/forwarder agents like the ones mentioned have the ability to transform and enrich log messages on their way through e.g. you could reshape log messages to the Open Telemetry log data model described here.
Actually I've played around with the OpenTelemetry collector agent and it does some out of the box transformations e.g. a log message of "test" received by the OpenTelemetry collector agent via the filelog receiver ends up looking like the following after it gets exported (that is, without any processing/transformation on the way through):
{
"time_unix_nano": 1637538007545231018,
"body": {
"Value": {
"string_value": "test"
}
},
"attributes": [
{
"key": "file.name",
"value": {
"Value": {
"string_value": "filename.log"
}
}
}
],
"trace_id": "",
"span_id": ""
}
I suppose if you were to log as JSON in Serilog and enrich the logs with trace & span IDs using a Serilog enricher similar to this one (disclaimer this is a plugin I wrote a few years back when things were still known as OpenTracing), you could potentially do some transformation in the collector/forwarder agent to get the trace & span IDs populated correctly as per the defined OTEL log data model.
If you don't want to do that approach outlined above (which might be overly complex for simple scenarios) you could do some custom output formatting - see here for formatting output in Serilog, and send the logs directly to your sink...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With