Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for jboss-logmanager #5737

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ dependencies {

compileOnly(project(":instrumentation-appender-api-internal"))

// ensure no cross interference
testInstrumentation(project(":instrumentation:jboss-logmanager-1.1:javaagent"))

testImplementation("org.awaitility:awaitility")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ public void transform(TypeTransformer transformer) {
.and(takesArguments(1))
.and(takesArgument(0, named("java.util.logging.LogRecord"))),
JavaUtilLoggingInstrumentation.class.getName() + "$LogAdvice");
transformer.applyAdviceToMethod(
isMethod()
.and(isPublic())
.and(named("logRaw"))
.and(takesArguments(1))
.and(takesArgument(0, named("org.jboss.logmanager.ExtLogRecord"))),
JavaUtilLoggingInstrumentation.class.getName() + "$LogAdvice");
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.sdk.logs.data.Severity
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import spock.lang.Shared
import spock.lang.Unroll

import java.util.logging.Level
Expand All @@ -17,12 +16,7 @@ import static org.awaitility.Awaitility.await

class JavaUtilLoggingTest extends AgentInstrumentationSpecification {

@Shared
private final Object logger = createLogger("abc")

Object createLogger(String name) {
Logger.getLogger(name)
}
private static final Logger logger = Logger.getLogger("abc")

@Unroll
def "test method=#testMethod with testArgs=#testArgs and parent=#parent"() {
Expand Down

This file was deleted.

This file was deleted.

29 changes: 29 additions & 0 deletions instrumentation/jboss-logmanager-1.1/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugins {
id("otel.javaagent-instrumentation")
}

muzzle {
pass {
group.set("org.jboss.logmanager")
module.set("jboss-logmanager")
versions.set("[1.1.0.GA,)")
assertInverse.set(true)
}
}

dependencies {
library("org.jboss.logmanager:jboss-logmanager:1.1.0.GA")

compileOnly(project(":instrumentation-appender-api-internal"))

// ensure no cross interference
testInstrumentation(project(":instrumentation:java-util-logging:javaagent"))

testImplementation("org.awaitility:awaitility")
}

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-log-attributes=true")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.opentelemetry.javaagent.instrumentation.jboss_logmanager.v2_1;

import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
import io.opentelemetry.instrumentation.api.appender.internal.LogEmitterProvider;

import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.Logger;

import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;

public class JbossLogmanagerInstrumentation implements TypeInstrumentation {
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return named("org.jboss.logmanager.Logger");
}

@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
isMethod()
.and(isPublic())
.and(named("logRaw"))
.and(takesArguments(1))
.and(takesArgument(0, named("org.jboss.logmanager.ExtLogRecord"))),
JbossLogmanagerInstrumentation.class.getName() + "$CallLogRawAdvice");
}

@SuppressWarnings("unused")
public static class CallLogRawAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void methodEnter(
@Advice.This() Logger logger,
@Advice.Argument(0) ExtLogRecord record,
@Advice.Local("otelCallDepth") CallDepth callDepth) {
// need to track call depth across all loggers in order to avoid double capture when one
// logging framework delegates to another
callDepth = CallDepth.forClass(LogEmitterProvider.class);
if (callDepth.getAndIncrement() == 0) {
LoggingEventMapper.INSTANCE.capture(logger, record);
}
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void methodExit(@Advice.Local("otelCallDepth") CallDepth callDepth) {
callDepth.decrementAndGet();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.opentelemetry.javaagent.instrumentation.jboss_logmanager.v2_1;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import java.util.List;
import static java.util.Collections.singletonList;

@AutoService(InstrumentationModule.class)
public class JbossLogmanagerInstrumentationModule extends InstrumentationModule {

public JbossLogmanagerInstrumentationModule() {
super("jboss-logmanager", "jboss-logmanager-2.1");
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return singletonList(new JbossLogmanagerInstrumentation());
}
}
Loading