Skip to content

Commit

Permalink
Update log4j library base version (open-telemetry#4914)
Browse files Browse the repository at this point in the history
* Update log4j-2.7 javaagent instrumentation to match up through 2.15.0

* Rename log4j 2.13.2 to 2.16

* Update one more location
  • Loading branch information
trask authored and RashmiRam committed May 23, 2022
1 parent c1289c7 commit 1d32380
Show file tree
Hide file tree
Showing 27 changed files with 86 additions and 122 deletions.
2 changes: 1 addition & 1 deletion buildscripts/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
</module>
<module name="PackageName">
<!-- modified from default to support packages like
io.opentelemetry.javaagent.instrumentation.log4j.v2_13_2 and
io.opentelemetry.javaagent.instrumentation.log4j.v2_16 and
io.opentelemetry.javaagent.instrumentation.netty.v4_1.client -->
<property name="format"
value="^[a-z]+(\.[a-z][a-z0-9]*)*(\.v[0-9]+_[0-9]+(_[0-9]+)?)?(\.[a-z][a-z0-9]*)*$"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import io.opentelemetry.api.trace.Span
import io.opentelemetry.instrumentation.log4j.v2_13_2.ListAppender
import io.opentelemetry.instrumentation.log4j.v2_16.ListAppender
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
import org.apache.logging.log4j.LogManager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.log4j.v2_13_2;
package io.opentelemetry.instrumentation.log4j.v2_16;

import java.util.ArrayList;
import java.util.Collections;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ muzzle {
pass {
group.set("org.apache.logging.log4j")
module.set("log4j-core")
versions.set("[2.13.2,)")
versions.set("[2.16.0,)")
assertInverse.set(true)
}
}
Expand All @@ -21,9 +21,9 @@ testSets {
}

dependencies {
library("org.apache.logging.log4j:log4j-core:2.13.2")
library("org.apache.logging.log4j:log4j-core:2.16.0")

implementation(project(":instrumentation:log4j:log4j-2.13.2:library-autoconfigure"))
implementation(project(":instrumentation:log4j:log4j-2.16:library-autoconfigure"))

testImplementation(project(":instrumentation:log4j:log4j-2-common:testing"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.log4j.v2_13_2;
package io.opentelemetry.javaagent.instrumentation.log4j.v2_16;

import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
import static java.util.Collections.singletonList;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.HelperResourceBuilder;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import java.util.Arrays;
import java.util.List;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class Log4j2InstrumentationModule extends InstrumentationModule {
public Log4j2InstrumentationModule() {
super("log4j", "log4j-2.13.2");
super("log4j", "log4j-2.16");
}

@Override
Expand All @@ -32,13 +33,19 @@ public void registerHelperResources(HelperResourceBuilder helperResourceBuilder)

@Override
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
return hasClassesNamed("org.apache.logging.log4j.core.util.ContextDataProvider");
// want to cover 2.16.0+
// - DefaultArbiter introduced in 2.15.0
// - LookupMessagePatternConverter introduced in 2.15.0, removed in 2.16.0
return hasClassesNamed("org.apache.logging.log4j.core.config.arbiters.DefaultArbiter")
.and(
not(
hasClassesNamed(
"org.apache.logging.log4j.core.pattern.MessagePatternConverter$LookupMessagePatternConverter")));
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return Arrays.asList(
new BugFixingInstrumentation(), new ResourceInjectingTypeInstrumentation());
return singletonList(new ResourceInjectingTypeInstrumentation());
}

// A type instrumentation is needed to trigger resource injection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,28 @@ You can use these keys when defining an appender in your `log4j.xml` configurati

## OpenTelemetry Appender

`OpenTelemetryAppender` is a Log4j2 [appender](https://logging.apache.org/log4j/2.x/manual/appenders.html) that can be used to forward log events to the [OpenTelemetry Log SDK](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk/logs).
`OpenTelemetryAppender` is a
Log4j2 [appender](https://logging.apache.org/log4j/2.x/manual/appenders.html) that can be used to
forward log events to
the [OpenTelemetry Log SDK](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk/logs)
.

The following demonstrates how you might configure the appender in your `log4j.xml` configuration:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="io.opentelemetry.instrumentation.log4j.v2_13_2">
<Configuration status="WARN" packages="io.opentelemetry.instrumentation.log4j.v2_16">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} traceId: %X{trace_id} spanId: %X{span_id} flags: %X{trace_flags} - %msg%n" />
<PatternLayout
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} traceId: %X{trace_id} spanId: %X{span_id} flags: %X{trace_flags} - %msg%n"/>
</Console>
<OpenTelemetry name="OpenTelemetryAppender" />
<OpenTelemetry name="OpenTelemetryAppender"/>
</Appenders>
<Loggers>
<Root>
<AppenderRef ref="OpenTelemetryAppender" level="All" />
<AppenderRef ref="Console" level="All" />
<AppenderRef ref="OpenTelemetryAppender" level="All"/>
<AppenderRef ref="Console" level="All"/>
</Root>
</Loggers>
</Configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id("otel.library-instrumentation")
}

dependencies {
library("org.apache.logging.log4j:log4j-core:2.16.0")

testImplementation(project(":instrumentation:log4j:log4j-2-common:testing"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.log4j.v2_13_2;
package io.opentelemetry.instrumentation.log4j.v2_16;

import static io.opentelemetry.instrumentation.api.log.LoggingContextConstants.SPAN_ID;
import static io.opentelemetry.instrumentation.api.log.LoggingContextConstants.TRACE_FLAGS;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.opentelemetry.instrumentation.log4j.v2_16.OpenTelemetryContextDataProvider
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
dependencies {
compileOnly("io.opentelemetry:opentelemetry-sdk-logs")

library("org.apache.logging.log4j:log4j-core:2.13.2")
library("org.apache.logging.log4j:log4j-core:2.16.0")

testImplementation("io.opentelemetry:opentelemetry-sdk-logs")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.log4j.v2_13_2;
package io.opentelemetry.instrumentation.log4j.v2_16;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.log4j.v2_13_2;
package io.opentelemetry.instrumentation.log4j.v2_16;

import io.opentelemetry.sdk.logs.LogBuilder;
import io.opentelemetry.sdk.logs.SdkLogEmitterProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.log4j.v2_13_2;
package io.opentelemetry.instrumentation.log4j.v2_16;

import io.opentelemetry.sdk.logs.SdkLogEmitterProvider;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.log4j.v2_13_2;
package io.opentelemetry.instrumentation.log4j.v2_16;

import static io.opentelemetry.instrumentation.log4j.v2_13_2.LogEventMapper.ATTR_THROWABLE_MESSAGE;
import static io.opentelemetry.instrumentation.log4j.v2_16.LogEventMapper.ATTR_THROWABLE_MESSAGE;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;

import io.opentelemetry.api.common.Attributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.log4j.v2_13_2;
package io.opentelemetry.instrumentation.log4j.v2_16;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.log4j.v2_13_2;
package io.opentelemetry.instrumentation.log4j.v2_16;

import static org.assertj.core.api.Assertions.assertThatCode;
import static org.mockito.ArgumentMatchers.any;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN"
packages="com.example.appender,io.opentelemetry.instrumentation.log4j.v2_16">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} traceId: %X{trace_id} spanId: %X{span_id} flags: %X{trace_flags} - %msg%n"/>
</Console>
<ListAppender name="ListAppender"/>
<OpenTelemetry name="OpenTelemetryAppender"/>
</Appenders>
<Loggers>
<Logger name="TestLogger" level="All">
<AppenderRef ref="OpenTelemetryAppender" level="All"/>
<AppenderRef ref="ListAppender" level="All"/>
<AppenderRef ref="Console" level="All"/>
</Logger>
<Root>
<AppenderRef ref="Console" level="All"/>
</Root>
</Loggers>
</Configuration>
4 changes: 2 additions & 2 deletions instrumentation/log4j/log4j-2.7/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ muzzle {
pass {
group.set("org.apache.logging.log4j")
module.set("log4j-core")
versions.set("[2.7,2.13.2)")
versions.set("[2.7,2.16.0)")
assertInverse.set(true)
}
}
Expand All @@ -16,5 +16,5 @@ dependencies {

testImplementation(project(":instrumentation:log4j:log4j-2-common:testing"))

latestDepTestLibrary("org.apache.logging.log4j:log4j-core:2.13.1")
latestDepTestLibrary("org.apache.logging.log4j:log4j-core:2.15.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ public Log4j27InstrumentationModule() {

@Override
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
// want to cover 2.7 through (and including) 2.15.0 (but not including 2.16.0+)
// - ContextDataInjectorFactory introduced in 2.7
// - DefaultArbiter introduced in 2.15.0
// - LookupMessagePatternConverter introduced in 2.15.0, removed in 2.16.0
return hasClassesNamed("org.apache.logging.log4j.core.impl.ContextDataInjectorFactory")
.and(not(hasClassesNamed("org.apache.logging.log4j.core.util.ContextDataProvider")));
.and(
not(hasClassesNamed("org.apache.logging.log4j.core.config.arbiters.DefaultArbiter"))
.or(
hasClassesNamed(
"org.apache.logging.log4j.core.pattern.MessagePatternConverter$LookupMessagePatternConverter")));
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ include(":instrumentation:liberty:liberty:javaagent")
include(":instrumentation:liberty:liberty-dispatcher:javaagent")
include(":instrumentation:log4j:log4j-1.2:javaagent")
include(":instrumentation:log4j:log4j-2.7:javaagent")
include(":instrumentation:log4j:log4j-2.13.2:javaagent")
include(":instrumentation:log4j:log4j-2.13.2:library")
include(":instrumentation:log4j:log4j-2.13.2:library-autoconfigure")
include(":instrumentation:log4j:log4j-2.16:javaagent")
include(":instrumentation:log4j:log4j-2.16:library")
include(":instrumentation:log4j:log4j-2.16:library-autoconfigure")
include(":instrumentation:log4j:log4j-2-common:testing")
include(":instrumentation:logback-1.0:javaagent")
include(":instrumentation:logback-1.0:library")
Expand Down
2 changes: 1 addition & 1 deletion smoke-tests/images/grpc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
implementation platform("io.grpc:grpc-bom:1.33.1")
implementation platform("io.opentelemetry:opentelemetry-bom:1.0.0")
implementation platform("io.opentelemetry:opentelemetry-bom-alpha:1.0.0-alpha")
implementation platform("org.apache.logging.log4j:log4j-bom:2.13.2")
implementation platform("org.apache.logging.log4j:log4j-bom:2.16.0")

implementation "io.grpc:grpc-netty-shaded"
implementation "io.grpc:grpc-protobuf"
Expand Down

0 comments on commit 1d32380

Please sign in to comment.