Update vendor distro example to 0.12
MODIFY
examples/distro/build.gradle
examples/distro/build.gradle
@@ -8,8 +8,8 @@ subprojects {
ext {
versions = [
- opentelemetry : "0.10.0",
- opentelemetryJavaagent : "0.10.1",
+ opentelemetry : "0.12.0",
+ opentelemetryJavaagent : "0.12.0",
bytebuddy : "1.10.10",
guava : "20.0"

MODIFY
examples/distro/custom/src/main/java/com/example/javaagent/DemoIdGenerator.java
examples/distro/custom/src/main/java/com/example/javaagent/DemoIdGenerator.java
@@ -20,6 +20,6 @@ public class DemoIdGenerator implements IdGenerator {
@Override
public String generateTraceId() {
- return String.format("%032d", spanId.incrementAndGet());
+ return String.format("%032d", traceId.incrementAndGet());
}
}

MODIFY
examples/distro/custom/src/main/java/com/example/javaagent/DemoSampler.java
examples/distro/custom/src/main/java/com/example/javaagent/DemoSampler.java
package com.example.javaagent;
-import io.opentelemetry.api.common.ReadableAttributes;
+import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.trace.data.SpanData;
@@ -10,7 +10,7 @@ import java.util.List;
/**
* This demo sampler filters out all internal spans whose name contains string "greeting".
- *
+ * <p>
* See <a href="https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#sampling">
* OpenTelemetry Specification</a> for more information about span sampling.
*
@@ -18,7 +18,8 @@ import java.util.List;
*/
public class DemoSampler implements Sampler {
@Override
- public SamplingResult shouldSample(Context parentContext, String traceId, String name, Span.Kind spanKind, ReadableAttributes attributes, List<SpanData.Link> parentLinks) {
+ public SamplingResult shouldSample(Context parentContext, String traceId, String name,
+ Span.Kind spanKind, Attributes attributes, List<SpanData.Link> parentLinks) {
if (spanKind == Span.Kind.INTERNAL && name.contains("greeting")) {
return SamplingResult.create(SamplingResult.Decision.DROP);
} else {

MODIFY
examples/distro/custom/src/main/java/com/example/javaagent/DemoTracerCustomizer.java
examples/distro/custom/src/main/java/com/example/javaagent/DemoTracerCustomizer.java
package com.example.javaagent;
import io.opentelemetry.api.OpenTelemetry;
-import io.opentelemetry.context.propagation.DefaultContextPropagators;
+import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.javaagent.spi.TracerCustomizer;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.trace.TracerSdkManagement;
@@ -18,25 +18,20 @@ import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
public class DemoTracerCustomizer implements TracerCustomizer {
@Override
public void configure(TracerSdkManagement ignore) {
- OpenTelemetrySdk sdk = OpenTelemetrySdk.get();
- OpenTelemetrySdk.Builder sdkBuilder = sdk.toBuilder();
- TracerSdkManagement tracerSdkManagement = sdk.getTracerManagement();
+ OpenTelemetrySdk.Builder sdkBuilder = OpenTelemetrySdk.builder();
- tracerSdkManagement.addSpanProcessor(new DemoSpanProcessor());
- tracerSdkManagement.addSpanProcessor(SimpleSpanProcessor.builder(new DemoSpanExporter()).build());
+ sdkBuilder.addSpanProcessor(new DemoSpanProcessor());
+ sdkBuilder.addSpanProcessor(SimpleSpanProcessor.builder(new DemoSpanExporter()).build());
- TraceConfig currentConfig = tracerSdkManagement.getActiveTraceConfig();
+ TraceConfig currentConfig = TraceConfig.getDefault();
TraceConfig newConfig = currentConfig.toBuilder()
.setSampler(new DemoSampler())
.setMaxLengthOfAttributeValues(128)
.build();
- tracerSdkManagement.updateActiveTraceConfig(newConfig);
+ sdkBuilder.setTraceConfig(newConfig);
- //TODO https://github.com/open-telemetry/opentelemetry-java/issues/2018
-// TracerSdkProvider tracerSdkProvider = TracerSdkProvider.builder().setIdsGenerator(new DemoIdGenerator()).build();
-// sdkBuilder.setTracerProvider(tracerSdkProvider);
-
- sdkBuilder.setPropagators(DefaultContextPropagators.builder().addTextMapPropagator(new DemoPropagator()).build());
+ sdkBuilder.setIdGenerator(new DemoIdGenerator());
+ sdkBuilder.setPropagators(ContextPropagators.create(new DemoPropagator()));
OpenTelemetry.set(sdkBuilder.build());
}

DELETE
examples/distro/instrumentation/servlet-3/src/main/java/com/example/javaagent/instrumentation/DemoServlet3Instrumentation.java
-package com.example.javaagent.instrumentation;
-
-import static java.util.Collections.singletonMap;
-
-import com.google.auto.service.AutoService;
-import io.opentelemetry.api.trace.Span;
-import io.opentelemetry.javaagent.tooling.ClassLoaderMatcher;
-import io.opentelemetry.javaagent.tooling.Instrumenter;
-import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers;
-import io.opentelemetry.javaagent.tooling.matcher.NameMatchers;
-import java.util.Map;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletResponse;
-import net.bytebuddy.asm.Advice;
-import net.bytebuddy.description.method.MethodDescription;
-import net.bytebuddy.description.type.TypeDescription;
-import net.bytebuddy.matcher.ElementMatcher;
-import net.bytebuddy.matcher.ElementMatchers;
-
-/**
- * This is a demo instrumentation which hooks into servlet invocation and modifies the http response.
- */
-@AutoService(Instrumenter.class)
-public final class DemoServlet3Instrumentation extends Instrumenter.Default {
- public DemoServlet3Instrumentation() {
- super("servlet-demo", "servlet-3");
- }
-
- /*
- We want this instrumentation to be applied after the standard servlet instrumentation.
- The latter creates a server span around http request.
- This instrumentation needs access to that server span.
- */
- @Override
- public int getOrder() {
- return 1;
- }
-
- @Override
- public ElementMatcher<ClassLoader> classLoaderMatcher() {
- return ClassLoaderMatcher.hasClassesNamed("javax.servlet.http.HttpServlet");
- }
-
- @Override
- public ElementMatcher<TypeDescription> typeMatcher() {
- return AgentElementMatchers.safeHasSuperType(
- NameMatchers.namedOneOf("javax.servlet.FilterChain", "javax.servlet.http.HttpServlet"));
- }
-
- @Override
- public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
- return singletonMap(
- NameMatchers.namedOneOf("doFilter", "service")
- .and(ElementMatchers.takesArgument(0, ElementMatchers.named("javax.servlet.ServletRequest")))
- .and(ElementMatchers.takesArgument(1, ElementMatchers.named("javax.servlet.ServletResponse")))
- .and(ElementMatchers.isPublic()),
- DemoServlet3Instrumentation.class.getName() + "$DemoServlet3Advice");
- }
-
- @SuppressWarnings("unused")
- public static class DemoServlet3Advice {
-
- @Advice.OnMethodEnter(suppress = Throwable.class)
- public static void onEnter(@Advice.Argument(value = 1) ServletResponse response) {
- if (!(response instanceof HttpServletResponse)) {
- return;
- }
-
- HttpServletResponse httpServletResponse = (HttpServletResponse) response;
- if (!httpServletResponse.containsHeader("X-server-id")) {
- httpServletResponse.addHeader("X-server-id", Span.current().getSpanContext().getTraceIdAsHexString());
- }
- }
-
- }
-}
\ No newline at end of file

ADD
examples/distro/instrumentation/servlet-3/src/main/java/com/example/javaagent/instrumentation/DemoServlet3InstrumentationModule.java
+package com.example.javaagent.instrumentation;
+
+import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers.safeHasSuperType;
+import static io.opentelemetry.javaagent.tooling.matcher.NameMatchers.namedOneOf;
+import static java.util.Collections.singletonList;
+import static java.util.Collections.singletonMap;
+import static net.bytebuddy.matcher.ElementMatchers.isPublic;
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
+
+import com.google.auto.service.AutoService;
+import io.opentelemetry.api.trace.Span;
+import io.opentelemetry.javaagent.tooling.ClassLoaderMatcher;
+import io.opentelemetry.javaagent.tooling.InstrumentationModule;
+import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
+import java.util.List;
+import java.util.Map;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+import net.bytebuddy.asm.Advice;
+import net.bytebuddy.description.method.MethodDescription;
+import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+
+/**
+ * This is a demo instrumentation which hooks into servlet invocation and modifies the http response.
+ */
+@AutoService(InstrumentationModule.class)
+public final class DemoServlet3InstrumentationModule extends InstrumentationModule {
+ public DemoServlet3InstrumentationModule() {
+ super("servlet-demo", "servlet-3");
+ }
+
+ /*
+ We want this instrumentation to be applied after the standard servlet instrumentation.
+ The latter creates a server span around http request.
+ This instrumentation needs access to that server span.
+ */
+ @Override
+ public int getOrder() {
+ return 1;
+ }
+
+ @Override
+ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
+ return ClassLoaderMatcher.hasClassesNamed("javax.servlet.http.HttpServlet");
+ }
+
+ @Override
+ public List<TypeInstrumentation> typeInstrumentations() {
+ return singletonList(new DemoServlet3Instrumentation());
+ }
+
+ public static class DemoServlet3Instrumentation implements TypeInstrumentation {
+ @Override
+ public ElementMatcher<TypeDescription> typeMatcher() {
+ return safeHasSuperType(namedOneOf("javax.servlet.Filter", "javax.servlet.http.HttpServlet"));
+ }
+
+ @Override
+ public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
+ return singletonMap(
+ namedOneOf("doFilter", "service")
+ .and(takesArgument(0, named("javax.servlet.ServletRequest")))
+ .and(takesArgument(1, named("javax.servlet.ServletResponse")))
+ .and(isPublic()),
+ DemoServlet3Advice.class.getName());
+ }
+
+ @SuppressWarnings("unused")
+ public static class DemoServlet3Advice {
+
+ @Advice.OnMethodEnter(suppress = Throwable.class)
+ public static void onEnter(@Advice.Argument(value = 1) ServletResponse response) {
+ if (!(response instanceof HttpServletResponse)) {
+ return;
+ }
+
+ HttpServletResponse httpServletResponse = (HttpServletResponse) response;
+ if (!httpServletResponse.containsHeader("X-server-id")) {
+ httpServletResponse
+ .addHeader("X-server-id", Span.current().getSpanContext().getTraceIdAsHexString());
+ }
+ }
+
+ }
+ }
+}
\ No newline at end of file

MODIFY
examples/distro/smoke-tests/src/test/java/com/example/javaagent/smoketest/SpringBootSmokeTest.java
examples/distro/smoke-tests/src/test/java/com/example/javaagent/smoketest/SpringBootSmokeTest.java
@@ -14,7 +14,8 @@ import org.junit.jupiter.api.Test;
class SpringBootSmokeTest extends SmokeTest {
protected String getTargetImage(int jdk) {
- return "open-telemetry-docker-dev.bintray.io/java/smoke-springboot-jdk" + jdk + ":latest";
+ return "ghcr.io/open-telemetry/java-test-containers:smoke-springboot-jdk" + jdk
+ + "-20201204.400701583";
}
@Test
@@ -42,7 +43,8 @@ class SpringBootSmokeTest extends SmokeTest {
Assertions.assertEquals(0, countSpansByName(traces, "WebController.greeting"));
Assertions.assertEquals(1, countSpansByName(traces, "WebController.withSpan"));
Assertions.assertEquals(2, countSpansByAttributeValue(traces, "custom", "demo"));
- Assertions.assertEquals(1, countResourcesByValue(traces, "telemetry.auto.version", currentAgentVersion));
+ Assertions.assertEquals(1,
+ countResourcesByValue(traces, "telemetry.auto.version", currentAgentVersion));
Assertions.assertEquals(1, countResourcesByValue(traces, "custom.resource", "demo"));
stopTarget();

Update vendor distro example to 0.12 (#1875)