-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add helper function trace.Start (fixes #1090) #1674
Conversation
|
Codecov Report
@@ Coverage Diff @@
## main #1674 +/- ##
=====================================
Coverage 77.3% 77.3%
=====================================
Files 128 128
Lines 6681 6684 +3
=====================================
+ Hits 5166 5171 +5
+ Misses 1268 1266 -2
Partials 247 247
|
I've signed a CLA, and not quite sure why it's saying it can't find my UserID on that commit. |
2a0f3d5
to
d301f74
Compare
…s ...SpanOption) (context.Context, Span) fixes open-telemetry#1091
d301f74
to
61667a8
Compare
There we go, was an issue with multiple email addresses. Sorted now. |
The one thing that worries me about this approach is that it takes away knowledge of the Would it be preferable to use the global |
@Aneurysm9 Ah, I think I've misunderstood a key difference between OpenCensus and OpenTelemetry, and I opened the underlying 'issue' 7 months ago and best practice has matured since then. In OpenCensus each tracer had to be wired up to an exporter (in practical usage there was only ever one tracer), so in coming to OpenTelemetry my assumption was that to get cohesive trace outputs in your exporter that either all packages would have to use the same tracer, or each package would have to export its tracer so that the main entry code could wire them all up to the exporter. And if you used multiple tracer that the outputs wouldn't be linked in the final output of the TraceProvider. Whereas reading some of the more recent changes it now seems much clearer that I probably misunderstood and that in OpenTelemetry that the main program defines the trace provider and that each package is free to make it's own tracer from that provider and you don't need to worry about passing through or wiring in, and you'll still get linked outputs. For example if you had a main and a sub packages: foo/main.go func main() {
// setup, say, stackdriver exporter `tp`
otel.SetTracerProvider(tp)
// use default traceprovider
tr := otel.Tracer("github.com/pci/.../foo")
ctx, span := tr.Start(ctx, "b")
defer span.End()
b.Run(ctx)
} and a second package foo/b/b.go var (
// use default traceprovider
tr = otel.Tracer("github.com/pci/.../foo/b")
)
func Run(ctx context.Context) {
ctx, otherSpan := tr.Start(ctx, "other_things")
defer otherSpan.End()
// do other stuff
} then in, again say, stackdriver you'll still get a cohesive waterfall? TL;DR - I think I misunderstood opentelemetry best practise. @Aneurysm9 if you wouldn't mind confirming the above, just in case I got that wrong, but then I'll close this PR and the linked issue. And thank you for your time, much appreciated! |
This is correct. The That last scenario is still potentially problematic and can result in broken trace graphs if the spans are not exported to the same destination. I'm not sure we have a good way of handling this other than to recommend that instrumentations that wish to have a separate trace graph be very careful about providing |
@pci your comment about best practices looks accurate to me. Does that mean this PR and related Issue can be closed? |
@MrAlias apologies for the late reply, had a family emergency come up. Yes, now I understand best practise better I think this PR would be at best not-needed, at worse an anti-pattern! I'll close the PR and issue and leave a comment with an explanation. Thanks again. |
No worries! Thanks for the contribution and feedback 😄 |
I am so used to using |
This is an implementation of #1090 with the motivation for the change in that issue. I've tried to follow the test patterns of the surrounding tests as best I could. The test case internally uses
ContextWithSpan
andSpanFromContext
so it's not a true unit test of solely that function, but it seemed the best way to test the functionality.