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

Use OpenTelemetry Shim with Lightstep launcher #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ If you have access to [LightStep](https://app.lightstep.com]), you will need you

```properties
tracer=lightstep
lightstep.collector_host=collector.lightstep.com
lightstep.collector_port=443
lightstep.collector_host=ingest.lightstep.com
lightstep.access_token=XXXXXXXXXXXXXXX // TODO: replace with your token
```

Expand Down
42 changes: 28 additions & 14 deletions microdonuts/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-web-servlet-filter</artifactId>
<version>0.1.1</version>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-okhttp3</artifactId>
<version>0.1.0</version>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand All @@ -52,31 +52,33 @@
<version>3.7.0</version>
</dependency>

<!-- OpenTracing Tracer Implementations -->
<dependency>
<groupId>com.lightstep.tracer</groupId>
<artifactId>lightstep-tracer-jre</artifactId>
<version>0.14.2</version>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-opentracing-shim</artifactId>
<version>0.7.0-20200727.220734-33</version>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this version still accessible/download-able? Else, we should probably wait for the 0.7.0 release of the agent (and related components).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's better to wait for 0.7.0.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated version to 0.7.0

</dependency>

<dependency>
<groupId>com.lightstep.opentelemetry</groupId>
<artifactId>opentelemetry-launcher</artifactId>
<version>0.1.0</version>
</dependency>

<!-- OpenTracing Tracer Implementations -->
<dependency>
<groupId>io.jaegertracing</groupId>
<artifactId>jaeger-core</artifactId>
<version>0.27.0</version>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>io.opentracing.brave</groupId>
<artifactId>brave-opentracing</artifactId>
<version>0.31.2</version>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter</artifactId>
<version>2.7.6</version>
<version>0.37.2</version>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-sender-okhttp3</artifactId>
<version>2.7.6</version>
<version>2.15.0</version>
</dependency>

</dependencies>
Expand Down Expand Up @@ -135,4 +137,16 @@
</plugins>
</build>

<repositories>
<repository>
<id>bintray-lightstep-maven</id>
<url>https://dl.bintray.com/lightstep/maven/</url>
</repository>
<repository>
<id>oss-snapshot-local</id>
<name>oss-snapshot-local</name>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
</repository>
</repositories>

</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.otsample.api;

import io.opentracing.Span;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;
Expand All @@ -16,8 +17,6 @@
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.otsample.api.KitchenConsumer;
import com.otsample.api.Utils;
import com.otsample.api.resources.DonutRequest;
import com.otsample.api.resources.StatusReq;
import com.otsample.api.resources.StatusRes;
Expand Down Expand Up @@ -57,8 +56,9 @@ public OrderServlet(KitchenConsumer kitchenConsumer)
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
try (Scope orderSpanScope = GlobalTracer.get().buildSpan("order_span").startActive(true)) {
request.setAttribute("span", orderSpanScope.span());
Span span = GlobalTracer.get().buildSpan("order_span").start();
try (Scope orderSpanScope = GlobalTracer.get().activateSpan(span)) {
request.setAttribute("span", span);

DonutRequest[] donutsInfo = parseDonutsInfo(request);
if (donutsInfo == null) {
Expand All @@ -84,6 +84,8 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
Utils.writeJSON(response, statusRes);
} catch (Throwable t) {
t.printStackTrace();
} finally {
span.finish();
}
}

Expand Down
25 changes: 12 additions & 13 deletions microdonuts/src/main/java/com/otsample/api/App.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.otsample.api;

import brave.opentracing.BraveTracer;
import com.lightstep.opentelemetry.launcher.OpenTelemetryConfiguration;
import io.jaegertracing.internal.samplers.ConstSampler;
import io.opentelemetry.opentracingshim.TraceShim;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
Expand All @@ -11,16 +15,11 @@
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.ResourceHandler;

import com.lightstep.tracer.jre.JRETracer;
import com.lightstep.tracer.shared.Options;

import brave.Tracing;
import brave.opentracing.BraveTracer;
import io.jaegertracing.Configuration;
import io.jaegertracing.Configuration.ReporterConfiguration;
import io.jaegertracing.Configuration.SamplerConfiguration;
import io.jaegertracing.Configuration.SenderConfiguration;
import io.jaegertracing.samplers.ConstSampler;
import io.opentracing.Tracer;
import io.opentracing.util.GlobalTracer;
import zipkin2.Span;
Expand Down Expand Up @@ -100,17 +99,17 @@ static boolean configureGlobalTracer(Properties config, String componentName)
.spanReporter(reporter)
.build());
} else if ("lightstep".equals(tracerName)) {
Options opts = new Options.OptionsBuilder()
.withAccessToken(config.getProperty("lightstep.access_token"))
.withCollectorHost(config.getProperty("lightstep.collector_host"))
.withCollectorPort(Integer.decode(config.getProperty("lightstep.collector_port")))
.withComponentName(componentName)
.build();
tracer = new JRETracer(opts);
OpenTelemetryConfiguration.newBuilder()
.setServiceName(componentName)
.setAccessToken(config.getProperty("lightstep.access_token"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to directly use the new system property names, e.g. ls.acess.token (as also, in the future, we want to support configuration through property files).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to use system properties

.setSpanEndpoint(config.getProperty("lightstep.collector_host"))
.install();

tracer = TraceShim.createTracerShim();
} else {
return false;
}
GlobalTracer.register(tracer);
GlobalTracer.registerIfAbsent(tracer);
return true;
}
}
5 changes: 2 additions & 3 deletions microdonuts/tracer_config.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
public_directory=../client

// Selector for the below config blocks
tracer=jaeger
tracer=lightstep

// Jaeger config
jaeger.reporter_host=localhost
Expand All @@ -12,6 +12,5 @@ zipkin.reporter_host=localhost
zipkin.reporter_port=9411

// LightStep config
lightstep.collector_host=collector.lightstep.com
lightstep.collector_port=80
lightstep.collector_host=ingest.lightstep.com
lightstep.access_token={your_token}