[example] simplified TracedClient setTag
This commit is contained in:
parent
614ee7099f
commit
0de7cae077
|
@ -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'
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue