Implementing opentracing bridge

Very slowly processing with some opentracing-bridge code in Java.
My main issue is that I want to inject and extract transaction and span information inside separate processes.
Have found this link talking a lot about pseudo-code with opentracing:
Can anybody give me directions towards some real sample code ??

Hi :slight_smile:

you can find plenty of OpenTracing examples here:

Does the Java agent lack some auto instrumentation for technologies you are using?

Really looking for a "Hello World" type of sample,
which would allow me to inject context and/or extract context.
Like explained in pseudo-code,
but I want real code

Have got this APM-call:
Tracer tracer = new ElasticApmTracer();

After that I am supposed to be talking "the opentracing language"

Kind of lost between the different imports ??
Don't know where to select APM and where to select opentracing.

import co.elastic.apm.opentracing.ElasticApmTracer;
import io.opentracing.Tracer;
import io.opentracing.propagation.Format;
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.tag.Tags;

1 Like

Have found some really good samples for the Jaeger product, these allow me to execute step by step and understand how opentracing works:

Have tried to implement the same using the opentracing bridge,
have commented out the original code from the sample

package lesson01.solution;
//import io.jaegertracing.internal.JaegerTracer;
import co.elastic.apm.opentracing.ElasticApmTracer;
import io.opentracing.Span;
import io.opentracing.Tracer;
import io.opentracing.util.GlobalTracer;

public class Hello {

private final Tracer tracer;

private Hello(Tracer tracer) {
    this.tracer = tracer;

private void sayHello(String helloTo) {
    Span span = tracer.buildSpan("say-hello").start();
    span.setTag("hello-to", helloTo);

    String helloStr = String.format("Hello, %s!", helloTo);
    span.log(ImmutableMap.of("event", "string-format", "value", helloStr));

    span.log(ImmutableMap.of("event", "println"));


public static void main(String[] args) {
    if (args.length != 1) {
        throw new IllegalArgumentException("Expecting one argument");

    String helloTo = args[0];

// try (JaegerTracer tracer = Tracing.init("hello-world")) {
try (ElasticApmTracer tracer = Tracing.init("hello-world")) {
new Hello(tracer).sayHello(helloTo);

Cannot get it to work with the bridge

Did you add the -javaagent flag to the JVM flags? This is still required, even when doing manual instrumentation with the OpenTracing API.

Note that with the next release, the public API of the Java agent will also support extracting and injecting the Tracing headers.

But maybe more generally, what is your use and what are you trying to instrument? In which mode do you want to use the OpenTracing bridge?

-javaagent flag is definately set.
Is this the next major ( or minor (6.5xxx) release ??

It's the next minor of the Java agent, which is 1.3.0. You can go to the Java agent on GitHub and watch for "Releases only" to get a notification for the release.

Here is also an example how to use the OpenTracing API with the java agent including inject and extract:

As of imports, you should only need co.elastic.apm.opentracing.ElasticApmTracer as the Elastic APM specific import. Otherwise, you can all use io.opentracing.* imports.

Thanks for this I will give the inject/extract a try.
Such a large amount of imports though

You can also try the upcoming API of the Java agent with a snapshot build:

Inject and extract scope of transactions and spans in a transparent, easy to code way, is my biggest concern. So far I have the unit testing, but no working sample, struggling along.

What exactly isn't working? Do you get errors? Could you attach some logs?

Really doing my best to make maximum use of opentracing and thus make the APM-layer as thin as possible. Mainly because more functionality and standards are available inside opentracing.

Any sample available from opentracing appears to be impossible to integrate with objects defined from:
import co.elastic.apm.opentracing.ElasticApmTracer;

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.