Note Automatic log to trace correlation provided by OpenTelemetry .NET Automatic Instrumentation currently works only for .NET applications using
Microsoft.Extensions.Logging
. See #2310 and config for more details.
OpenTelemetry .NET SDK automatically correlates logs to trace data.
When logs are emitted in the context of an active trace, trace context
fields
TraceId
, SpanId
, TraceState
are automatically populated.
The following are logs produced by the sample console application:
"logRecords": [
{
"timeUnixNano": "1679392614538226700",
"severityNumber": 9,
"severityText": "Information",
"body": {
"stringValue": "Success! Today is: {Date:MMMM dd, yyyy}"
},
"flags": 1,
"traceId": "21df288eada1ce4ace6c40f39a6d7ce1",
"spanId": "a80119e5a05fed5a"
}
]
Further reading: