-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Which JS SDK should be used in manual instrumentation docs? #1436
Comments
Let's split them out. I think it'd make sense to actually break node and browser into separate files entirely? |
So I think that the majority of content can stay the same for both SDKs, including nested spans. Both propagate context (at least within the same process!) and so creating nested spans is easy peasy. E.g. in web: const onClick = () => {
webTracerWithZone.startActiveSpan('files-series-info', singleSpan => {
for (let i = 0, j = 5; i < j; i += 1) {
webTracerWithZone.startActiveSpan(`files-series-info-${i}`, fileSeriesSpan => {
traceGetData(url);
fileSeriesSpan.addEvent(`fetching-span-${i}-completed`)
fileSeriesSpan.end();
});
}
singleSpan.end();
});
}; This creates child spans just as you'd expect:
Maybe this can be the layout? Initialize tracingwords Node.jswords and code sample Browserwords and code sample Create spans... And then maybe a separate doc or section about when you're using neither, which requires you to manually put spans into context if you want a parent-child relationship. |
I would think that it's fine to keep in one file (just to avoid duplicating example) however there is a request to support deno (and ongoing work to do so) and i would bet that workers (like cloudflare) might follow at some point so we need to think about how that you go, in other sections too ? |
I was reading the docs, which state:
and looking into why ended up here as the issue which prompted this addition to the docs. Why doesn't |
Not quite - |
It also does Full disclosure, I haven't used the API at all, I'm just browsing the documentation at this point, so I very definitely might be overlooking something 😅 |
I think what you're missing is the subtlety in the API calls -- |
The manual instrumentation docs today use
sdk-trace-base
: https://opentelemetry.io/docs/instrumentation/js/instrumentation/This is helpful insofar as the code here is useful both in Node and in the browser.
However,
sdk-trace-base
doesn't propagate context, and so creating nested spans is kind of awful: https://opentelemetry.io/docs/instrumentation/js/instrumentation/#create-nested-spansContrast this with when using the Node SDK (code is from a basic express app):
No needing to set the current span in context, get the new context, and use that awful overload to create a nested span. Just creating a span like any other language automatically gives you that parent-child relationship. Nice!
But not everyone reading this document is going to be a Node developer, so the code to initialize tracing, such that you can just use the OTel APIs happily, is not applicable for everyone.
My proposal would be to create this content twice on this page: https://opentelemetry.io/docs/instrumentation/js/instrumentation/#initializing-a-tracer
One for node, and one for browser JS. This could be as tabbed content, although we may want to use tabs later on to show JS vs. TS code. I'm fine with whatever folks think works best. But mainly, I'd like to not document the hard way to create nested spans.
@open-telemetry/javascript-approvers what do you think?
The text was updated successfully, but these errors were encountered: