Feature Request: Attach log messages to Activity.Events
See original GitHub issue[This came out of a discussion on gitter with @jchannon.]
Feature Request
OpenTracing.Contrib.NetCore will register an ILoggerProvider\ILogger which will attach log messages to a span and these are exported to Jaeger.
The ask is to have a similar mechanism in OpenTelemetry .NET.
Design
Our JaegerExporter is already coded to convert ActivityEvent
s into JaegerLogs
:
https://github.com/open-telemetry/opentelemetry-dotnet/blob/6fe93f8d79725d696e01090ab531585881636850/src/OpenTelemetry.Exporter.Jaeger/Implementation/JaegerActivityExtensions.cs#L158-L175
Given that behavior, the idea is to add a BaseProcessor<LogRecord>
which will convert log messages written through ILogger
into ActivityEvent
s and add them to Activity.Current.Events. Presumably only when Activity.IsAllDataRequested = true
but this could be configurable.
This will be something you will have to explicitly turn on because it is expensive.
Proposed API
Coming soon…
Issue Analytics
- State:
- Created 3 years ago
- Reactions:12
- Comments:19 (7 by maintainers)
@CodeBlanch Something like this? https://github.com/iSeiryu/opentelemetry-dotnet/commit/c13208510f8139bdeac966298fd911db31170dcd
Since there is no proper example for classes like that (the only existing one is for Console and it uses
BaseExporter<LogRecord>
instead ofBaseProcessor<LogRecord>
) I probably messed up some naming conventions.I tested it on local and it works. It logs general system and custom logs as well as the exceptions. I left the options empty but I’m sure it would require some configuration.
The logging code in 1.0 registers an
ILoggerProvider
which will createILoggers
that call this line:https://github.com/open-telemetry/opentelemetry-dotnet/blob/3239e5b02f639779d93b22427fece7370579432b/src/OpenTelemetry/Logs/OpenTelemetryLogger.cs#L52
Any time a log message is written, the registered
BaseProcessor<LogRecord>
will be called. The problem is, there’s noBaseProcessor<LogRecord>
implementation in there. If you build your own, you can make it work.That’s exactly what I’m going to do for this issue/feature. I’m going to create a
BaseProcessor<LogRecord>
that adds the log messages toActivity.Events
so they will export to Jaeger. Now that 1.0 is out, I’ll get back to that. But if you want to give it a shot feel free 😄Only if you are using serilog-extensions-logging which will write through
ILogger
before Serilog’s custom logger.