Is your feature request related to a problem? Please describe.
An OpenTelemetry Event is a LogRecord with an EventName field.
Currently, to emit an Event, one must use the OpenTelemetry SDK log API like this:
- Obtain an OpenTelemetry SDK
LoggerProvider
- Obtain an OpenTelemetry SDK
Logger via LoggerProvider.get(...)
- Obtain a OpenTelemetry SDK
LogRecordBuilder via Logger.logRecordBuilder()
- Set the event name via
logRecordBuilder.setEventName(...)
- Set other properties/attributes on the
logRecordBuilder
- Call
logRecordBuilder.emit().
While this is ok in general, it requires direct usage of the OpenTelemetry SDK log APIs, as opposed to using a more common log API (like slf4j). It also bypasses features and the event population performed when using a logging API that is bridged to OpenTelemetry (like logback/log4j). Therefore, you would need to duplicate the event population that those bridges perform (in Step 5).
Describe the solution you'd like
I would like
- to be able to emit OpenTelemetry Events using a common log API (like slf4j) without using the OpenTelemetry SDK log API directly
- to be able to specify a value for the
EventName field when using a more common log API
- to take advantage of the features and the event population performed when using a logging API that is bridged to OpenTelemetry (like logback/log4j) to populate the other OpenTelemetry Event fields
The event.name semantic attribute was recently undeprecated in open-telemetry/semantic-conventions#2715 for this purpose.
Users could opt in to having the attribute named event.name be used for the log event name.
For example, when using opentelemetry-logback-appender-1.0...
First, tell the OpenTelemetry logback appender to opt-in to using the event.name attribute as the event name
otel.instrumentation.logback-appender.experimental.capture-event-name=true
otel.instrumentation.logback-appender.experimental.capture-key-value-pair-attributes=true
or
<appender name="OpenTelemetry" class="io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender">
<captureEventName>true</captureEventName>
<captureKeyValuePairAttributes>true</captureKeyValuePairAttributes>
</appender>
Then, to log an event ...
private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(MyEventLogger.class);
LOGGER.atInfo()
// specify the event name using the event.name key enabled above
.addKeyValue("event.name", "MyEvent")
// add other event-specific attributes
//.addKeyValue(..., ...)
.log("body...");
Internally, when capture-event-name is configured, the LoggingEventMapper would:
- call
logRecordBuilder.setEventName(...) with the value of the event.name attribute (in this example, MyEvent).
- not include the
event.name in attributes
This could be implemented for any logging API that supports capturing attributes
Describe alternatives you've considered
Use the OpenTelemetry SDK Log APIs directly.
Explicitly populate everything that a common log API bridge would populate, plus the EventName field.
Additional context
No response
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
Is your feature request related to a problem? Please describe.
An OpenTelemetry Event is a LogRecord with an
EventNamefield.Currently, to emit an Event, one must use the OpenTelemetry SDK log API like this:
LoggerProviderLoggerviaLoggerProvider.get(...)LogRecordBuilderviaLogger.logRecordBuilder()logRecordBuilder.setEventName(...)logRecordBuilderlogRecordBuilder.emit().While this is ok in general, it requires direct usage of the OpenTelemetry SDK log APIs, as opposed to using a more common log API (like slf4j). It also bypasses features and the event population performed when using a logging API that is bridged to OpenTelemetry (like logback/log4j). Therefore, you would need to duplicate the event population that those bridges perform (in Step 5).
Describe the solution you'd like
I would like
EventNamefield when using a more common log APIThe
event.namesemantic attribute was recently undeprecated in open-telemetry/semantic-conventions#2715 for this purpose.Users could opt in to having the attribute named
event.namebe used for the log event name.For example, when using opentelemetry-logback-appender-1.0...
First, tell the OpenTelemetry logback appender to opt-in to using the
event.nameattribute as the event nameor
Then, to log an event ...
Internally, when capture-event-name is configured, the
LoggingEventMapperwould:logRecordBuilder.setEventName(...)with the value of theevent.nameattribute (in this example,MyEvent).event.namein attributesThis could be implemented for any logging API that supports capturing attributes
Describe alternatives you've considered
Use the OpenTelemetry SDK Log APIs directly.
Explicitly populate everything that a common log API bridge would populate, plus the EventName field.
Additional context
No response
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding
+1orme too, to help us triage it. Learn more here.