Skip to content

Conversation

philsttr
Copy link
Contributor

@philsttr philsttr commented Sep 12, 2025

Added a new capture-event-name configuration option to logback/log4j/jboss-logmanager library/javaagent instrumentation that, when true,

  1. captures the log event name from the recently undeprecated semantic attribute named event.name, and
  2. removes the event.name attribute from the log event.

This allows the log event name to be specified when logging using standard log APIs, rather than having to use the OpenTelemetry SDK log APIs directly.

The event.name attribute can be captured using any attribute capturing mechanism supported by the log instrumentation. For example, if logback-appender's captureKeyValuePairAttributes is true, then an application can specify the event.name attribute via an slf4j key/value when logging.

Capturing the event name is enabled with the following configuration values, depending on what you're using:

  • logback-appender-1.0/library - io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender - captureEventName
  • logback-appender-1.0/javaagent - otel.instrumentation.logback-appender.experimental.capture-event-name
  • log4j-appender-2.17/library - io.opentelemetry.instrumentation.log4j.appender.v2_17.OpenTelemetryAppender - captureEventName
  • log4j-appender-2.17/javaagent - otel.instrumentation.log4j-appender.experimental.capture-event-name
  • jboss-logmanager-appender-1.1/javaagent - otel.instrumentation.jboss-logmanager.experimental.capture-event-name

Not supported in java-util-logging instrumentation, since that instrumentation has no mechanism to pass an event.name attribute.

Fixes: gh-14632

Added a new capture-event-name configuration option to logback/log4j/jboss-logmanager library/javaagent instrumentation that, when true,
1. captures the log event name from the recently undeprecated semantic attribute named `event.name`, and
2. removes the `event.name` attribute from the log event.

This allows the log event name to be specified when logging using standard log APIs, rather than having to use the OpenTelemetry SDK log APIs directly.

The `event.name` attribute can be captured using any attribute capturing mechanism supported by the log instrumentation.  For example, if logback-appender's `captureKeyValuePairAttributes` is true, then an application can specify the `event.name` attribute via an slf4j key/value when logging.

Capturing the event name is enabled with the following configuration values, depending on what you're using:
* logback-appender-1.0/library - `io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender` - `captureEventName`
* logback-appender-1.0/javaagent - `otel.instrumentation.logback-appender.experimental.capture-event-name`
* log4j-appender-2.17/library - `io.opentelemetry.instrumentation.log4j.appender.v2_17.OpenTelemetryAppender` - `captureEventName`
* log4j-appender-2.17/javaagent - `otel.instrumentation.log4j-appender.experimental.capture-event-name`
* jboss-logmanager-appender-1.1/javaagent - `otel.instrumentation.jboss-logmanager.experimental.capture-event-name`

Fixes: open-telemetrygh-14632
@otelbot-java-instrumentation
Copy link
Contributor

🔧 The result from spotlessApply was committed to the PR branch.

Use cached AttributeKeys for dynamic key names in log mappers.

Rename setAttributeMaybeEventName to setAttributeOrEventName

Clarify capture event name description in readme
@laurit
Copy link
Contributor

laurit commented Sep 18, 2025

@philsttr
Copy link
Contributor Author

philsttr commented Sep 18, 2025

Could you also do this for log4j 1.2 instrumentation

Done

@laurit laurit added this to the v2.21.0 milestone Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow emitting events through common logging APIs
3 participants