Target OTel SDK snapshot
MODIFY
gradle/dependencies.gradle
gradle/dependencies.gradle
@@ -8,7 +8,8 @@ configurations.all {
ext {
versions = [
- opentelemetry: '0.6.0',
+ // Check https://oss.jfrog.org/libs-snapshot/io/opentelemetry/ for latest snapshot version.
+ opentelemetry: '0.7.0-20200721.021000-20',
slf4j : "1.7.30",
guava : "20.0", // Last version to support Java 7

MODIFY
instrumentation/opentelemetry-api-beta/src/main/java/io/opentelemetry/auto/instrumentation/opentelemetryapi/OpenTelemetryApiInstrumentation.java
instrumentation/opentelemetry-api-beta/src/main/java/io/opentelemetry/auto/instrumentation/opentelemetryapi/OpenTelemetryApiInstrumentation.java
@@ -65,7 +65,9 @@ public class OpenTelemetryApiInstrumentation extends AbstractInstrumentation {
public static void methodExit(
@Advice.Return(readOnly = false)
unshaded.io.opentelemetry.trace.TracerProvider tracerProvider) {
- tracerProvider = new UnshadedTracerProvider();
+ ContextStore<Context, io.grpc.Context> contextStore =
+ InstrumentationContext.get(Context.class, io.grpc.Context.class);
+ tracerProvider = new UnshadedTracerProvider(contextStore);
}
}

MODIFY
instrumentation/opentelemetry-api-beta/src/main/java/io/opentelemetry/auto/instrumentation/opentelemetryapi/trace/UnshadedSpan.java
instrumentation/opentelemetry-api-beta/src/main/java/io/opentelemetry/auto/instrumentation/opentelemetryapi/trace/UnshadedSpan.java
@@ -19,8 +19,10 @@ package io.opentelemetry.auto.instrumentation.opentelemetryapi.trace;
import static io.opentelemetry.auto.instrumentation.opentelemetryapi.trace.Bridging.toShaded;
import static io.opentelemetry.auto.instrumentation.opentelemetryapi.trace.Bridging.toShadedOrNull;
+import io.opentelemetry.auto.bootstrap.ContextStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import unshaded.io.grpc.Context;
import unshaded.io.opentelemetry.common.AttributeValue;
import unshaded.io.opentelemetry.common.Attributes;
import unshaded.io.opentelemetry.trace.EndSpanOptions;
@@ -146,9 +148,13 @@ class UnshadedSpan implements Span {
private static final Logger log = LoggerFactory.getLogger(Builder.class);
private final io.opentelemetry.trace.Span.Builder shadedBuilder;
+ private final ContextStore<Context, io.grpc.Context> contextStore;
- Builder(final io.opentelemetry.trace.Span.Builder shadedBuilder) {
+ Builder(
+ final io.opentelemetry.trace.Span.Builder shadedBuilder,
+ ContextStore<Context, io.grpc.Context> contextStore) {
this.shadedBuilder = shadedBuilder;
+ this.contextStore = contextStore;
}
@Override
@@ -167,6 +173,12 @@ class UnshadedSpan implements Span {
return this;
}
+ @Override
+ public Span.Builder setParent(Context context) {
+ shadedBuilder.setParent(contextStore.get(context));
+ return this;
+ }
+
@Override
public Span.Builder setNoParent() {
shadedBuilder.setNoParent();

MODIFY
instrumentation/opentelemetry-api-beta/src/main/java/io/opentelemetry/auto/instrumentation/opentelemetryapi/trace/UnshadedTracer.java
instrumentation/opentelemetry-api-beta/src/main/java/io/opentelemetry/auto/instrumentation/opentelemetryapi/trace/UnshadedTracer.java
package io.opentelemetry.auto.instrumentation.opentelemetryapi.trace;
+import io.opentelemetry.auto.bootstrap.ContextStore;
+import unshaded.io.grpc.Context;
import unshaded.io.opentelemetry.context.Scope;
import unshaded.io.opentelemetry.trace.Span;
import unshaded.io.opentelemetry.trace.Tracer;
@@ -23,9 +25,13 @@ import unshaded.io.opentelemetry.trace.Tracer;
class UnshadedTracer implements Tracer {
private final io.opentelemetry.trace.Tracer shadedTracer;
+ private final ContextStore<Context, io.grpc.Context> contextStore;
- UnshadedTracer(final io.opentelemetry.trace.Tracer shadedTracer) {
+ UnshadedTracer(
+ final io.opentelemetry.trace.Tracer shadedTracer,
+ ContextStore<Context, io.grpc.Context> contextStore) {
this.shadedTracer = shadedTracer;
+ this.contextStore = contextStore;
}
@Override
@@ -40,6 +46,6 @@ class UnshadedTracer implements Tracer {
@Override
public Span.Builder spanBuilder(final String spanName) {
- return new UnshadedSpan.Builder(shadedTracer.spanBuilder(spanName));
+ return new UnshadedSpan.Builder(shadedTracer.spanBuilder(spanName), contextStore);
}
}

MODIFY
instrumentation/opentelemetry-api-beta/src/main/java/io/opentelemetry/auto/instrumentation/opentelemetryapi/trace/UnshadedTracerProvider.java
instrumentation/opentelemetry-api-beta/src/main/java/io/opentelemetry/auto/instrumentation/opentelemetryapi/trace/UnshadedTracerProvider.java
package io.opentelemetry.auto.instrumentation.opentelemetryapi.trace;
+import io.opentelemetry.auto.bootstrap.ContextStore;
+import unshaded.io.grpc.Context;
import unshaded.io.opentelemetry.trace.Tracer;
import unshaded.io.opentelemetry.trace.TracerProvider;
public class UnshadedTracerProvider implements TracerProvider {
+ private final ContextStore<Context, io.grpc.Context> contextStore;
+
+ public UnshadedTracerProvider(ContextStore<Context, io.grpc.Context> contextStore) {
+ this.contextStore = contextStore;
+ }
+
@Override
public Tracer get(final String instrumentationName) {
return new UnshadedTracer(
- io.opentelemetry.OpenTelemetry.getTracerProvider().get(instrumentationName));
+ io.opentelemetry.OpenTelemetry.getTracerProvider().get(instrumentationName), contextStore);
}
@Override
public Tracer get(final String instrumentationName, final String instrumentationVersion) {
return new UnshadedTracer(
io.opentelemetry.OpenTelemetry.getTracerProvider()
- .get(instrumentationName, instrumentationVersion));
+ .get(instrumentationName, instrumentationVersion),
+ contextStore);
}
}

MODIFY
instrumentation/opentelemetry-api-beta/src/test/groovy/MeterTest.groovy
instrumentation/opentelemetry-api-beta/src/test/groovy/MeterTest.groovy
@@ -53,7 +53,7 @@ class MeterTest extends AgentTestRunner {
}
then:
- def metricData = findMetric(OpenTelemetrySdk.getMeterProvider().getMetricProducer().getAllMetrics(), instrumentationName, "test")
+ def metricData = findMetric(OpenTelemetrySdk.getMeterProvider().getMetricProducer().collectAllMetrics(), instrumentationName, "test")
metricData != null
metricData.descriptor.description == "d"
metricData.descriptor.unit == "u"
@@ -106,7 +106,7 @@ class MeterTest extends AgentTestRunner {
}
then:
- def metricData = findMetric(OpenTelemetrySdk.getMeterProvider().getMetricProducer().getAllMetrics(), instrumentationName, "test")
+ def metricData = findMetric(OpenTelemetrySdk.getMeterProvider().getMetricProducer().collectAllMetrics(), instrumentationName, "test")
metricData != null
metricData.descriptor.description == "d"
metricData.descriptor.unit == "u"
@@ -189,7 +189,7 @@ class MeterTest extends AgentTestRunner {
}
then:
- def metricData = findMetric(OpenTelemetrySdk.getMeterProvider().getMetricProducer().getAllMetrics(), instrumentationName, "test")
+ def metricData = findMetric(OpenTelemetrySdk.getMeterProvider().getMetricProducer().collectAllMetrics(), instrumentationName, "test")
metricData != null
metricData.descriptor.description == "d"
metricData.descriptor.unit == "u"
@@ -241,7 +241,7 @@ class MeterTest extends AgentTestRunner {
.put(doubleMeasure, 6.6)
.record()
- def allMetrics = OpenTelemetrySdk.getMeterProvider().getMetricProducer().getAllMetrics()
+ def allMetrics = OpenTelemetrySdk.getMeterProvider().getMetricProducer().collectAllMetrics()
then:
def metricData = findMetric(allMetrics, instrumentationName, "test")

MODIFY
instrumentation/opentelemetry-api-beta/src/test/groovy/TracerTest.groovy
instrumentation/opentelemetry-api-beta/src/test/groovy/TracerTest.groovy
@@ -181,6 +181,34 @@ class TracerTest extends AgentTestRunner {
}
}
+ def "capture span with explicit parent from context"() {
+ when:
+ def tracer = OpenTelemetry.getTracerProvider().get("test")
+ def parentSpan = tracer.spanBuilder("parent").startSpan()
+ def context = withSpan(parentSpan, Context.current())
+ def testSpan = tracer.spanBuilder("test").setParent(context).startSpan()
+ testSpan.end()
+ parentSpan.end()
+
+ then:
+ assertTraces(1) {
+ trace(0, 2) {
+ span(0) {
+ operationName "parent"
+ parent()
+ attributes {
+ }
+ }
+ span(1) {
+ operationName "test"
+ childOf span(0)
+ attributes {
+ }
+ }
+ }
+ }
+ }
+
def "capture span with explicit no parent"() {
when:
def tracer = OpenTelemetry.getTracerProvider().get("test")

Target OTel SDK snapshot (#746)