无法在stackdriver

时间:2017-04-01 15:25:20

标签: java google-cloud-platform stackdriver google-cloud-trace

我使用以下Java代码将测试跟踪发送到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);

但是当我从控制台访问跟踪时,我什么也看不到。

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

我错过了一些事情吗?

注意 - 我遵循How to do a simple Google Cloud Trace request in Java

中提到的代码

更新

我尝试了来自API explorer的等效有效负载,它给了我200响应,仍然没有Stackdriver控制台中的跟踪迹象。

以下是我的有效载荷

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"
  }
 ]
}

回复

200

- Show headers -

{
}

控制台

enter image description here

更新

感谢GCP社区中的某个人,他指出有效负载中缺少Span Name,以便能够在跟踪控制台中看到它。我在这里更新了代码。但是,即使在设置了span名称之后,当我从java代码发送它时,我仍然无法看到跟踪。

enter image description here

当触发上述java代码时,有没有办法检查发送的有效负载?

1 个答案:

答案 0 :(得分:2)

最后我发现在构建之后我没有调用 pt.execute()

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

pt.execute()

参考patchTraces#examples