javagoogle-cloud-platformstackdrivergoogle-cloud-trace

Unable to see traces in stackdriver


I am using the following Java code to send a test trace to stackdriver

HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();

GoogleCredential cred = GoogleCredential
    .fromStream(
        getClass().getClassLoader().getResourceAsStream("appengineServiceAccountKey.json"),
        httpTransport,
        jsonFactory)
    .createScoped(CloudTraceScopes.all());

CloudTrace gceTrace = new CloudTrace.Builder(httpTransport, jsonFactory, cred)
    .setApplicationName("Google Cloud Trace test app")
    .build();


TraceSpan span = new TraceSpan();
span.setName("foo-bar");
span.setSpanId(new BigInteger("1"));
span.setStartTime("2017-04-02T16:12:03.636Z");
span.setEndTime("2017-04-02T16:12:04.636Z");
Trace trace = new Trace();
trace.setTraceId(UUID.randomUUID().toString().replaceAll("-","")); // Mandatory
trace.setSpans(Collections.singletonList(span));
Traces traces = new Traces();
traces.setTraces(Collections.singletonList(trace)); // Mandatory
cloudTraceService.projects().patchTraces("myproject", traces);

However I don't see anything when I access the trace from console.

https://console.cloud.google.com/traces/details/8289f38bcb6e44c5b30c98953bee0018?project=myproject

Am I missing something ovious ?

Note - I am following the code mentioned in How to do a simple Google Cloud Trace request in Java

UPDATE

I tried the equivalent payload from the API explorer and it gave me 200 response, still no sign of the trace in the Stackdriver console.

Following was my payload

PATCH https://cloudtrace.googleapis.com/v1/projects/myproject/traces?key={YOUR_API_KEY}

{
 "traces": [
  {
   "projectId": "myproject",
   "spans": [
    {
     "startTime": "2017-04-03T16:12:03.636Z",
     "endTime": "2017-04-03T16:12:04.636Z",
     "spanId": "2"
     "name": "bar-foo"
    }
   ],
   "traceId": "8289f38bcb6e44c5b30c98953bee0018"
  }
 ]
}

Response

200

- Show headers -

{
}

Console

enter image description here

Update:

Thanks to someone in GCP community slack who pointed out that the Span Name is missing in the payload to be able to see it in trace console. I have update the code here. However I am stil not able to see the trace , when I send a it from java code even after setting the span name.

enter image description here

Is there any way to check what payload is being sent when the above java code is triggered ?


Solution

  • Finally I figured out that I was not invoking pt.execute() the request after building it

    PatchTraces pt =cloudTraceService.projects().patchTraces("myproject", traces);
    
    pt.execute()
    

    reference patchTraces#examples