Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Get SpanData of spans #1007

Open
smthpickboy opened this issue Jan 3, 2019 · 11 comments
Open

Get SpanData of spans #1007

smthpickboy opened this issue Jan 3, 2019 · 11 comments

Comments

@smthpickboy
Copy link

We want to implement log correlation for go(#950), so we need to access Span.data for parent span id and span name etc, and log them.

Is there a way to access Span.data? We can access it in Exporters, but only sampled trace/span can reach Exporter, while we want to log span info even if trace/span is NOT sampled.

Thanks!

@basvanbeek
Copy link
Member

For log correlation you only need the SpanContext which holds items like TraceID and SpanID which is sufficient for correlation purposes and also propagated in cases when a Trace is not sampled.

Span.data does not hold any required information to allow for log correlation and is only available for Spans that are sampled.

@smthpickboy
Copy link
Author

I think Parent Span ID is very useful for rebuilding structure of traces/spans from logs when traces are not sampled. Span Name further adds useful info to the rebuilded results.

@rghetia
Copy link
Contributor

rghetia commented Jan 21, 2019

if log data is used to rebuild traces then why not sample the trace?

@smthpickboy
Copy link
Author

@rghetia Because whether a trace will be sampled is determined at the time when the trace/span is created, but that's not where logging happens. When later the program decides to do some logging, there's no way to make sure this trace will be sampled and exported.

@bogdandrutu
Copy link
Contributor

My bad of pressing close button.

@rghetia
Copy link
Contributor

rghetia commented Feb 6, 2019

@rghetia Because whether a trace will be sampled is determined at the time when the trace/span is created, but that's not where logging happens. When later the program decides to do some logging, there's no way to make sure this trace will be sampled and exported.

unless log is created for every span rebuilding trace from log is not going to be useful. At that point it is as good as turning on always-sampling mode. Logging every span is probably more expensive then turning on sampling.

@smthpickboy
Copy link
Author

Always-sampling would be a waste of resources apparently. But when error happens, it would be nice to recover/rebuild more information as much as possible. Of course we can't recover the whole trace/span structure, but still, things like span name can provide valuable info for diagnosing problems, since not all the people in a team are familiar with the source code. And, we are planning to relate span names to the metrics names, so we can process and diagnose problems automatically in the future.

@NogginBops
Copy link

Any update on this?
Is there currently no way to get the SpanContext from a span?
I can't seem to find any way to get SpanID or TraceID from a span either.

This would be really useful to have so that one could implement log correlation yourself.

@bogdandrutu
Copy link
Contributor

Use https://github.com/census-instrumentation/opencensus-go/blob/master/trace/trace.go to get the SpanContext then the Span/trace IDs.

@NogginBops
Copy link

Oh look at how I missed that! Didn't see the function where you could get the SpanContext from the span. Thanks!

@sydnash
Copy link

sydnash commented Nov 12, 2019

how does it going? I need to get parent span id too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants