I try to add custom spans and annotations to an AppEngine Standard application. In the Traces page of the GCP console, I see the default spans but not the custom spans that I have added.
I follow the documentation: https://cloud.google.com/trace/docs/setup/java I use the latest version of opencensus-api 0.23.0
The Stackdrive Trace API is enabled and I see in the metrics page of the API that the application does successful google.devtools.cloudtrace.v2.TraceService.BatchWriteSpans
calls.
I created a sample application based on the official helloworld application that reproduces this problem.
The interesting parts:
private static final Tracer tracer = Tracing.getTracer();
static {
try {
System.out.println("Init StackdriverTraceExporter");
StackdriverTraceExporter.createAndRegister(
StackdriverTraceConfiguration.builder()
.setProjectId("project-id")
.build());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static String getInfo() {
try (Scope ignored = tracer.spanBuilder("MyChildWorkSpan").setSampler(Samplers.alwaysSample()).startScopedSpan()) {
tracer.getCurrentSpan().addAnnotation("annotation example");
try {
Thread.sleep(100);
} catch (Exception e) {
throw new RuntimeException(e);
}
System.out.println("annotation created");
return "Version: " + System.getProperty("java.version")
+ " OS: " + System.getProperty("os.name")
+ " User: " + System.getProperty("user.name")
+ " Span: " + tracer.getCurrentSpan();
}
}
You can see the full code here
I figured out my mistake.
This is what I saw when I opened the question:
The problem is that the service and version are selected.
These custom spans appear like a separate request and I need to select all services otherwise they are hidden.
So at least I can see that this works in a way but this is not what I intended. I would like to achieve something like this:
How can I attach my custom spans to the root span that is displayed for the request?