[example] simplified TracedClient setTag

This commit is contained in:
Emanuele Palazzetti 2017-08-04 13:54:11 +02:00
parent 614ee7099f
commit 0de7cae077
No known key found for this signature in database
GPG Key ID: F4D8F69FEF18A502
2 changed files with 8 additions and 4 deletions

View File

@ -10,6 +10,7 @@ sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile project(':dd-trace')
compile project(':dd-trace-annotations')
compile group: 'io.opentracing', name: 'opentracing-api', version: '0.30.0'

View File

@ -1,7 +1,9 @@
package com.datadoghq.example.dropwizard.client;
import com.datadoghq.trace.DDTags;
import com.datadoghq.trace.Trace;
import io.opentracing.tag.StringTag;
import io.opentracing.ActiveSpan;
import io.opentracing.Tracer;
import io.opentracing.util.GlobalTracer;
import java.io.IOException;
import okhttp3.OkHttpClient;
@ -22,11 +24,12 @@ public class TracedClient {
@Trace
private static void executeCall() throws IOException {
new StringTag("service-name").set(GlobalTracer.get().activeSpan(), "TracedClient");
Tracer tracer = GlobalTracer.get();
ActiveSpan activeSpan = tracer.activeSpan();
activeSpan.setTag(DDTags.SERVICE_NAME, "http.client");
OkHttpClient client = new OkHttpClient().newBuilder().build();
Request request = new Request.Builder().url("http://localhost:8080/demo/").build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);