Skip to content

Commit f594eca

Browse files
authored
Add OpenTracing Tracer resolving through ServiceLoader (#1708)
1 parent 789406b commit f594eca

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ to assist with such efforts.
4444
the <<config-log-ecs-reformatting>> config option. This allows effortless ingestion of logs to Elasticsearch without
4545
any further configuration. Supports log4j1, log4j2 and Logback. {pull}1261[#1261]
4646
* Add support to Spring AMQP - {pull}1657[#1657]
47+
* Adds the ability to automatically configure usage of the OpenTracing bridge in systems using ServiceLoader - {pull}1708[#1708]
4748
4849
[float]
4950
===== Bug fixes

apm-opentracing/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@
4646
<version>${project.version}</version>
4747
<scope>test</scope>
4848
</dependency>
49+
50+
<!-- https://github.com/opentracing-contrib/java-tracerresolver -->
51+
<dependency>
52+
<groupId>io.opentracing.contrib</groupId>
53+
<artifactId>opentracing-tracerresolver</artifactId>
54+
<version>0.1.8</version>
55+
<scope>test</scope>
56+
</dependency>
4957
</dependencies>
5058

5159
<build>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
co.elastic.apm.opentracing.ElasticApmTracer
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*-
2+
* #%L
3+
* Elastic APM Java agent
4+
* %%
5+
* Copyright (C) 2018 - 2021 Elastic and contributors
6+
* %%
7+
* Licensed to Elasticsearch B.V. under one or more contributor
8+
* license agreements. See the NOTICE file distributed with
9+
* this work for additional information regarding copyright
10+
* ownership. Elasticsearch B.V. licenses this file to you under
11+
* the Apache License, Version 2.0 (the "License"); you may
12+
* not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing,
18+
* software distributed under the License is distributed on an
19+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20+
* KIND, either express or implied. See the License for the
21+
* specific language governing permissions and limitations
22+
* under the License.
23+
* #L%
24+
*/
25+
package co.elastic.apm.opentracing;
26+
27+
import io.opentracing.Tracer;
28+
import io.opentracing.contrib.tracerresolver.TracerResolver;
29+
import org.junit.jupiter.api.Test;
30+
31+
import static org.assertj.core.api.Assertions.assertThat;
32+
33+
public class TracerResolverTest {
34+
@Test
35+
void testTracerResolver() {
36+
Tracer tracer = TracerResolver.resolveTracer();
37+
assertThat(tracer).isNotNull();
38+
assertThat(tracer.getClass().getName()).isEqualTo(ElasticApmTracer.class.getName());
39+
}
40+
}

docs/opentracing.asciidoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ import io.opentracing.Tracer;
8686
Tracer tracer = new ElasticApmTracer();
8787
----
8888

89+
Since version 1.22.0, the OpenTracing bridge supports `Tracer` lookup and initialization through the ServiceLoader mechanism.
90+
An example for a system that relies on this capability is https://github.com/opentracing-contrib/java-tracerresolver[tracer-resolver],
91+
which is used by various OpenTracing libraries, for example the
92+
https://camel.apache.org/components/3.7.x/others/opentracing.html[Apache Camel OpenTracing component].
93+
When such is used, no code changes are required, only the addition of dependencies for the OpenTracing library and
94+
the Elastic OpenTracing bridge.
8995

9096
[float]
9197
[[elastic-apm-tags]]

0 commit comments

Comments
 (0)