我使用下面的Java代碼來發送測試一絲的Stackdriver無法看到痕跡的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
我這麼想ovious?
注 - 我下面在How to do a simple Google Cloud Trace request in Java
UPDATE提到的代碼
我從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 -
{
}
控制檯
更新:
感謝有人在GCP社區鬆懈誰指出跨度名稱是有效負載中缺少能夠在跟蹤控制檯中看到它。我在這裏更新了代碼。但是,我仍然無法看到跟蹤,即使在設置span名稱後,我從java代碼發送它。
有沒有什麼辦法來檢查上面的Java代碼被觸發時正在發送的有效載荷?