3

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: trace_list 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. child span

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: combined_trace

How can I attach my custom spans to the root span that is displayed for the request?

Sandro G
  • 150
  • 10
ttozser
  • 63
  • 5

1 Answers1

1

I checked your issue and I made some reproductions on my side and I was able to add the custom span "MyChildWorkSpan" and the annotation "annotation example" making same changes as your did from your code to the Helloworld application in AppEngine Standard with Java 8.

I've used both versions of the io.opencensus (0.12.2 as documented here (with Maven) and 0.23.0 which is the version you're trying to use). In both cases, I was succeeded to see the custom span in the Stackdriver Trace list.

Could you attach a screenshot of what you're seeing in your Google Cloud console > Stackdriver Trace list when browsing to the ? Can you see the custom span "MyChildWorkSpan" and the annotation "annotation example" there? Or is there any other custom span/annotation you're not seeing?

Sandro G
  • 150
  • 10
  • Thanks for adding more context and the screenshots. Good to hear you were able to figure things out. Regarding attaching your custom spans to the root span that is displayed for the request, this sounds like a feature request that Stackdriver doesn't have implemented yet. All I can suggest is to fill a feature request in the Public Issue tracker: Navigate to https://cloud.google.com/support/docs/issue-trackers#feature_requests > Management Tools > Create new Stackdriver Trace issue. Once created, click on the Star and you will receive notifications from the Stackdriver dedicated team. – Sandro G Aug 28 '19 at 11:06
  • I have opened a feature request for this: https://issuetracker.google.com/issues/140263093 – ttozser Aug 30 '19 at 12:13