How can I link a StackDriver trace to the App Engi

2019-05-22 05:18发布

When I go looking at StackDriver traces that AppEngine generates automatically, there's a log link (that never brings up any more than one line of the log, but hopefully, they're working on fixing it.)

Is there a way to tell StackDriver, when I send a trace and set of spans, what request_id to associate the trace with?

1条回答
Explosion°爆炸
2楼-- · 2019-05-22 05:37

It is supposed to be one log only since you are searching for log for one particular request. Clicking on the left side triangle will expand the log.

If you don't really need to go to logs viewer to view the log, you can use the "show logs" button on the trace detail page. By clicking on it, it will embed the log statement in between spans. The position of the log statement is determined by the log time, relative to start time of the spans.

Clicking on the log statement line will show the full details of the log statement on the right side panel. See example below. "show logs" button is in the circle.

Show log in Trace

To pair up the trace spans you created with the trace spans created by GAE, simply pass the trace context as HTTP header to the GAE app.

Header name: X-Cloud-Trace-Context
Header format: <trace-id>[/<span-id>][;o=<trace-options>]

trace-id should be set to the same as the trace you generated. span-id should be set to the one that calls into GAE app. This is the parent span id of the GAE top span. o should be set to 1 if you want to trace, 0 if you don't.

Example:

X-Cloud-Trace-Context : 905e8445aa7843bc8bf206b13f12439c/12345;o=1
$ curl --header "X-Cloud-Trace-Context:4bf92f3577b34da6a3ce929d0e0e4736/12345;o=1" \
http://<your-app-id>.appspot.com/
查看更多
登录 后发表回答