openzipkin / zipkin-gcp

Reporters and collectors for use in Google Cloud Platform
https://cloud.google.com/trace/docs/zipkin
Apache License 2.0
91 stars 55 forks source link

Google Cloud Trace Stacktrace Field Support #193

Open skhatri0 opened 3 years ago

skhatri0 commented 3 years ago

Feature

The current SpanTranslator in the zipkin-translation-stackdriver project does not have any way to set the StackTrace object in the Span. I would like to set an attribute on the zipkin span called /stacktrace and fill it with a protobuf TextFormat encoding of the stacktrace. Then the SpanTranslator would deserialize the TextFormat stacktrace into a com.google.devtools.cloudtrace.v2.StackTrace object (via TextFormat.parse) and attach it to the com.google.devtools.cloudtrace.v2.Span object. It would also make sure not to set a raw String label on the span for /stacktrace. Once the trace is sent, the "Call Stack" section on the span would appear on the trace in the Stackdriver UI. It is a bit cumbersome to have to encode and then decode the Stacktrace, but the zipkin Span API does not appear to support attaching binary data to a span. This may be a breaking change if anyone uses the /stacktrace attribute for something else, but there are some ways to safeguard against that.

Rationale

I have JDBC tracing enabled (via spring-boot-datasource-decarator), and it is useful when diagnosing performance issues to find out what path of code is causing the database call. In general it can help anyone understand how remote activity is invoked in an application.

Example Scenario

  1. Tracing is performed on a call which accesses a database.
  2. The database call takes a while and the developer has no idea which code path makes the database call.
  3. Developer adds stack trace into each span in their application (via Brave SpanHandler)
  4. Capture new trace
  5. Look inside a traced request in stackdriver, and then see the call stack. Here is a page with an example of what it would look like inside stackdriver trace UI (see Call Stack section): https://cloud.google.com/trace/docs/trace-labels
  6. Developer identifies code path and makes necessary optimizations to it.

Prior Art