|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.javaagent.instrumentation.opentelemetryapi.v1_47.incubator; |
| 7 | + |
| 8 | +import static net.bytebuddy.matcher.ElementMatchers.named; |
| 9 | +import static net.bytebuddy.matcher.ElementMatchers.none; |
| 10 | + |
| 11 | +import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; |
| 12 | +import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; |
| 13 | +import io.opentelemetry.javaagent.instrumentation.opentelemetryapi.v1_40.incubator.metrics.ApplicationMeterFactory140Incubator; |
| 14 | +import io.opentelemetry.javaagent.instrumentation.opentelemetryapi.v1_47.incubator.logs.ApplicationLoggerFactory147Incubator; |
| 15 | +import io.opentelemetry.javaagent.instrumentation.opentelemetryapi.v1_47.incubator.trace.ApplicationTracerFactory147Incubator; |
| 16 | +import net.bytebuddy.asm.Advice; |
| 17 | +import net.bytebuddy.description.type.TypeDescription; |
| 18 | +import net.bytebuddy.matcher.ElementMatcher; |
| 19 | + |
| 20 | +public class OpenTelemetryIncubatorInstrumentation implements TypeInstrumentation { |
| 21 | + |
| 22 | + @Override |
| 23 | + public ElementMatcher<TypeDescription> typeMatcher() { |
| 24 | + return named("application.io.opentelemetry.api.GlobalOpenTelemetry"); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public void transform(TypeTransformer transformer) { |
| 29 | + transformer.applyAdviceToMethod( |
| 30 | + none(), OpenTelemetryIncubatorInstrumentation.class.getName() + "$InitAdvice"); |
| 31 | + } |
| 32 | + |
| 33 | + @SuppressWarnings({"ReturnValueIgnored", "unused"}) |
| 34 | + public static class InitAdvice { |
| 35 | + @Advice.OnMethodEnter |
| 36 | + public static void init() { |
| 37 | + // the sole purpose of this advice is to ensure that ApplicationLoggerFactory147Incubator is |
| 38 | + // recognized as helper class and injected into class loader |
| 39 | + ApplicationLoggerFactory147Incubator.class.getName(); |
| 40 | + // 1.40 instrumentation does not apply on 1.47, we include only the metrics part here |
| 41 | + ApplicationMeterFactory140Incubator.class.getName(); |
| 42 | + ApplicationTracerFactory147Incubator.class.getName(); |
| 43 | + } |
| 44 | + } |
| 45 | +} |
0 commit comments