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

Added support for Otel TracerBuilder #3535

Merged
merged 2 commits into from Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.asciidoc
Expand Up @@ -35,6 +35,14 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
===== Features
* Bumped base alpine docker image version - {pull}3524[#3524]

[float]
===== Bug fixes
* Added missing support for TracerBuilder in OpenTelemetry bridge - {pull}3535[#3535]

[float]
===== Potentially breaking changes
* The minimum supported OpenTelemetry version has been increased to 1.4.0 - {pull}3535[#3535]

[[release-notes-1.x]]
=== Java Agent version 1.x

Expand Down
Expand Up @@ -30,7 +30,9 @@ public abstract class AbstractOpenTelemetryInstrumentation extends ElasticApmIns

@Override
public ElementMatcher.Junction<ClassLoader> getClassLoaderMatcher() {
return classLoaderCanLoadClass("io.opentelemetry.context.propagation.TextMapSetter");
return classLoaderCanLoadClass("io.opentelemetry.context.propagation.TextMapSetter")
//TracerBuilder has been added in 1.4.0, which is the minimum supported API version
.and(classLoaderCanLoadClass("io.opentelemetry.api.trace.TracerBuilder"));
}

@Override
Expand Down
Expand Up @@ -19,6 +19,7 @@
package co.elastic.apm.agent.opentelemetry.tracing;

import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.TracerBuilder;
import io.opentelemetry.api.trace.TracerProvider;

import javax.annotation.Nullable;
Expand All @@ -39,4 +40,9 @@ public Tracer get(String instrumentationName) {
public Tracer get(String instrumentationName, @Nullable String instrumentationVersion) {
return this.tracer;
}

@Override
public TracerBuilder tracerBuilder(String instrumentationScopeName) {
return new OtelTracerBuilder(tracer);
}
}
@@ -0,0 +1,28 @@
package co.elastic.apm.agent.opentelemetry.tracing;

import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.TracerBuilder;

public class OtelTracerBuilder implements TracerBuilder {

private final Tracer tracer;

public OtelTracerBuilder(Tracer tracer) {
this.tracer = tracer;
}

@Override
public TracerBuilder setSchemaUrl(String s) {
return this;
}

@Override
public TracerBuilder setInstrumentationVersion(String s) {
return this;
}

@Override
public Tracer build() {
return tracer;
}
}
Expand Up @@ -30,6 +30,7 @@
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.ContextKey;
import io.opentelemetry.context.Scope;
Expand Down Expand Up @@ -81,6 +82,22 @@ public void testTransaction() {
.isEqualTo(OTelSpanKind.INTERNAL);
}

@Test
public void testTracerBuilder() {
Tracer tracer = openTelemetry.tracerBuilder("foo")
.setSchemaUrl("bar")
.setInstrumentationVersion("baz")
.build();

tracer.spanBuilder("transaction")
.startSpan()
.end();

assertThat(reporter.getTransactions()).hasSize(1);
Transaction transaction = reporter.getFirstTransaction();
assertThat(transaction.getNameAsString()).isEqualTo("transaction");
}

@Test
public void testTransactionWithAttribute() {
otelTracer.spanBuilder("transaction")
Expand Down
Expand Up @@ -29,10 +29,7 @@ public class OpenTelemetryVersionIT {

@ParameterizedTest
@ValueSource(strings = {
"1.0.1",
"1.1.0",
"1.2.0",
"1.3.0",
"1.4.0",
"1.4.1",
"1.5.0",
"1.6.0",
Expand Down
2 changes: 1 addition & 1 deletion docs/api-opentelemetry.asciidoc
Expand Up @@ -43,7 +43,7 @@ The first step in getting started with the OpenTelemetry API bridge is to declar
compile "io.opentelemetry:opentelemetry-api:$openTelemetryVersion"
----

The minimum required OpenTelemetry version is 1.0.1.
The minimum required OpenTelemetry version is 1.4.0.

[float]
[[otel-init-tracer]]
Expand Down