Skip to content
Merged
9 changes: 5 additions & 4 deletions instrumentation/jboss-logmanager/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Settings for the JBoss Log Manager instrumentation

| System property | Type | Default | Description |
|-----------------------------------------------------------------------------|---------|---------|--------------------------------------------------------------------------------------------------------------|
| `otel.instrumentation.jboss-logmanager.experimental-log-attributes` | Boolean | `false` | Enable the capture of experimental log attributes `thread.name` and `thread.id`. |
| `otel.instrumentation.jboss-logmanager.experimental.capture-mdc-attributes` | String | | Comma separated list of MDC attributes to capture. Use the wildcard character `*` to capture all attributes. |
| System property | Type | Default | Description |
|-----------------------------------------------------------------------------|---------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `otel.instrumentation.jboss-logmanager.experimental-log-attributes` | Boolean | `false` | Enable the capture of experimental log attributes `thread.name` and `thread.id`. |
| `otel.instrumentation.jboss-logmanager.experimental.capture-mdc-attributes` | String | | Comma separated list of MDC attributes to capture. Use the wildcard character `*` to capture all attributes. |
| `otel.instrumentation.jboss-logmanager.experimental.capture-event-name` | Boolean | `false` | Enable the capture of the log event name from the `event.name` attribute (captured via one of the above means). When true, the `event.name` attribute will be used as the log event name, and the `event.name` attribute will be removed. |
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ if (latestDepTest) {
tasks.withType<Test>().configureEach {
// TODO run tests both with and without experimental log attributes
jvmArgs("-Dotel.instrumentation.jboss-logmanager.experimental.capture-mdc-attributes=*")
jvmArgs("-Dotel.instrumentation.jboss-logmanager.experimental.capture-event-name=true")
jvmArgs("-Dotel.instrumentation.jboss-logmanager.experimental-log-attributes=true")
jvmArgs("-Dotel.instrumentation.java-util-logging.experimental-log-attributes=true")
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public final class LoggingEventMapper {

public static final LoggingEventMapper INSTANCE = new LoggingEventMapper();

// copied from EventIncubatingAttributes
private static final AttributeKey<String> EVENT_NAME = AttributeKey.stringKey("event.name");
private static final Cache<String, AttributeKey<String>> mdcAttributeKeys = Cache.bounded(100);

private final List<String> captureMdcAttributes;
Expand All @@ -41,6 +43,11 @@ public final class LoggingEventMapper {
// cached as an optimization
private final boolean captureAllMdcAttributes;

private final boolean captureEventName =
AgentInstrumentationConfig.get()
.getBoolean(
"otel.instrumentation.jboss-logmanager.experimental.capture-event-name", false);

private LoggingEventMapper() {
this.captureMdcAttributes =
AgentInstrumentationConfig.get()
Expand Down Expand Up @@ -90,7 +97,21 @@ public void capture(Logger logger, ExtLogRecord record) {
attributes.put(ThreadIncubatingAttributes.THREAD_ID, currentThread.getId());
}

builder.setAllAttributes(attributes.build());
Attributes realizedAttributes = attributes.build();
if (captureEventName) {
realizedAttributes.forEach(
(attributeKey, value) -> {
if (attributeKey.equals(EVENT_NAME)) {
builder.setEventName(String.valueOf(value));
} else {
@SuppressWarnings("unchecked")
AttributeKey<Object> attributeKeyAsObject = (AttributeKey<Object>) attributeKey;
builder.setAttribute(attributeKeyAsObject, value);
}
});
} else {
builder.setAllAttributes(realizedAttributes);
}

builder.setContext(Context.current());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,13 @@ private static void performLogging(
void testMdc() {
MDC.put("key1", "val1");
MDC.put("key2", "val2");
MDC.put("event.name", "MyEventName");
try {
logger.info("xyz");
} finally {
MDC.remove("key1");
MDC.remove("key2");
MDC.remove("event.name");
}

testing.waitAndAssertLogRecords(
Expand All @@ -216,6 +218,7 @@ void testMdc() {
.hasInstrumentationScope(InstrumentationScopeInfo.builder("abc").build())
.hasSeverity(Severity.INFO)
.hasSeverityText("INFO")
.hasEventName("MyEventName")
.hasAttributesSatisfyingExactly(
equalTo(AttributeKey.stringKey("key1"), "val1"),
equalTo(AttributeKey.stringKey("key2"), "val2"),
Expand Down
15 changes: 8 additions & 7 deletions instrumentation/log4j/log4j-appender-2.17/javaagent/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Settings for the Log4j Appender instrumentation

| System property | Type | Default | Description |
|-----------------------------------------------------------------------------------|---------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| `otel.instrumentation.log4j-appender.experimental-log-attributes` | Boolean | `false` | Enable the capture of experimental log attributes `thread.name` and `thread.id`. |
| `otel.instrumentation.log4j-appender.experimental.capture-code-attributes` | Boolean | `false` | Enable the capture of [source code attributes]. Note that capturing source code attributes at logging sites might add a performance overhead. |
| `otel.instrumentation.log4j-appender.experimental.capture-map-message-attributes` | Boolean | `false` | Enable the capture of `MapMessage` attributes. |
| `otel.instrumentation.log4j-appender.experimental.capture-marker-attribute` | Boolean | `false` | Enable the capture of Log4j markers as attributes. |
| `otel.instrumentation.log4j-appender.experimental.capture-mdc-attributes` | String | | Comma separated list of context data attributes to capture. Use the wildcard character `*` to capture all attributes. |
| System property | Type | Default | Description |
|-----------------------------------------------------------------------------------|---------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `otel.instrumentation.log4j-appender.experimental-log-attributes` | Boolean | `false` | Enable the capture of experimental log attributes `thread.name` and `thread.id`. |
| `otel.instrumentation.log4j-appender.experimental.capture-code-attributes` | Boolean | `false` | Enable the capture of [source code attributes]. Note that capturing source code attributes at logging sites might add a performance overhead. |
| `otel.instrumentation.log4j-appender.experimental.capture-map-message-attributes` | Boolean | `false` | Enable the capture of `MapMessage` attributes. |
| `otel.instrumentation.log4j-appender.experimental.capture-marker-attribute` | Boolean | `false` | Enable the capture of Log4j markers as attributes. |
| `otel.instrumentation.log4j-appender.experimental.capture-mdc-attributes` | String | | Comma separated list of context data attributes to capture. Use the wildcard character `*` to capture all attributes. |
| `otel.instrumentation.log4j-appender.experimental.capture-event-name` | Boolean | `false` | Enable the capture of the log event name from the `event.name` attribute (captured via one of the above means). When true, the `event.name` attribute will be used as the log event name, and the `event.name` attribute will be removed. |

[source code attributes]: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/general/attributes.md#source-code-attributes
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public final class Log4jHelper {
List<String> captureContextDataAttributes =
config.getList(
"otel.instrumentation.log4j-appender.experimental.capture-mdc-attributes", emptyList());
boolean captureEventName =
config.getBoolean(
"otel.instrumentation.log4j-appender.experimental.capture-event-name", false);

mapper =
new LogEventMapper<>(
Expand All @@ -60,7 +63,8 @@ public final class Log4jHelper {
captureCodeAttributes,
captureMapMessageAttributes,
captureMarkerAttribute,
captureContextDataAttributes);
captureContextDataAttributes,
captureEventName);
}

public static void capture(
Expand Down
17 changes: 9 additions & 8 deletions instrumentation/log4j/log4j-appender-2.17/library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ Setting can be configured as XML attributes, for example:

The available settings are:

| XML Attribute | Type | Default | Description |
|------------------------------------|---------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `captureExperimentalAttributes` | Boolean | `false` | Enable the capture of experimental log attributes `thread.name` and `thread.id`. |
| `captureCodeAttributes` | Boolean | `false` | Enable the capture of [source code attributes]. Note that capturing source code attributes at logging sites might add a performance overhead. |
| `captureMapMessageAttributes` | Boolean | `false` | Enable the capture of `MapMessage` attributes. |
| `captureMarkerAttribute` | Boolean | `false` | Enable the capture of Log4j markers as attributes. |
| `captureContextDataAttributes` | String | | Comma separated list of context data attributes to capture. Use the wildcard character `*` to capture all attributes. |
| `numLogsCapturedBeforeOtelInstall` | Integer | 1000 | Log telemetry is emitted after the initialization of the OpenTelemetry Log4j appender with an OpenTelemetry object. This setting allows you to modify the size of the cache used to replay the first logs. |
| XML Attribute | Type | Default | Description |
|------------------------------------|---------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `captureExperimentalAttributes` | Boolean | `false` | Enable the capture of experimental log attributes `thread.name` and `thread.id`. |
| `captureCodeAttributes` | Boolean | `false` | Enable the capture of [source code attributes]. Note that capturing source code attributes at logging sites might add a performance overhead. |
| `captureMapMessageAttributes` | Boolean | `false` | Enable the capture of `MapMessage` attributes. |
| `captureMarkerAttribute` | Boolean | `false` | Enable the capture of Log4j markers as attributes. |
| `captureContextDataAttributes` | String | | Comma separated list of context data attributes to capture. Use the wildcard character `*` to capture all attributes. |
| `captureEventName` | Boolean | `false` | Enable the capture of the log event name from the `event.name` attribute (captured via one of the above means). When true, the `event.name` attribute will be used as the log event name, and the `event.name` attribute will be removed. |
| `numLogsCapturedBeforeOtelInstall` | Integer | 1000 | Log telemetry is emitted after the initialization of the OpenTelemetry Log4j appender with an OpenTelemetry object. This setting allows you to modify the size of the cache used to replay the first logs. |

[source code attributes]: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/general/attributes.md#source-code-attributes
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public static class Builder<B extends Builder<B>> extends AbstractAppender.Build
@PluginBuilderAttribute private boolean captureMapMessageAttributes;
@PluginBuilderAttribute private boolean captureMarkerAttribute;
@PluginBuilderAttribute private String captureContextDataAttributes;
@PluginBuilderAttribute private boolean captureEventName;
@PluginBuilderAttribute private int numLogsCapturedBeforeOtelInstall;

@Nullable private OpenTelemetry openTelemetry;
Expand Down Expand Up @@ -155,6 +156,24 @@ public B setCaptureContextDataAttributes(String captureContextDataAttributes) {
return asBuilder();
}

/**
* Sets whether the value of the {@code event.name} attribute is used as the log event name.
*
* <p>The {@code event.name} attribute is captured via any other mechanism supported by this
* appender, such as when {@code captureContextDataAttributes} includes {@code event.name}.
*
* <p>When {@code captureEventName} is true, then the value of the {@code event.name} attribute
* will be used as the log event name, and {@code event.name} attribute will be removed.
*
* @param captureEventName to enable or disable capturing the {@code event.name} attribute as
* the log event name
*/
@CanIgnoreReturnValue
public B setCaptureEventName(boolean captureEventName) {
this.captureEventName = captureEventName;
return asBuilder();
}

/**
* Log telemetry is emitted after the initialization of the OpenTelemetry Logback appender with
* an {@link OpenTelemetry} object. This setting allows you to modify the size of the cache used
Expand Down Expand Up @@ -188,6 +207,7 @@ public OpenTelemetryAppender build() {
captureMapMessageAttributes,
captureMarkerAttribute,
captureContextDataAttributes,
captureEventName,
numLogsCapturedBeforeOtelInstall,
openTelemetry);
}
Expand All @@ -204,6 +224,7 @@ private OpenTelemetryAppender(
boolean captureMapMessageAttributes,
boolean captureMarkerAttribute,
String captureContextDataAttributes,
boolean captureEventName,
int numLogsCapturedBeforeOtelInstall,
OpenTelemetry openTelemetry) {

Expand All @@ -215,7 +236,8 @@ private OpenTelemetryAppender(
captureCodeAttributes,
captureMapMessageAttributes,
captureMarkerAttribute,
splitAndFilterBlanksAndNulls(captureContextDataAttributes));
splitAndFilterBlanksAndNulls(captureContextDataAttributes),
captureEventName);
this.openTelemetry = openTelemetry;
this.captureCodeAttributes = captureCodeAttributes;
if (numLogsCapturedBeforeOtelInstall != 0) {
Expand Down
Loading