-
Notifications
You must be signed in to change notification settings - Fork 532
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
feat: add instrumentation for undici
versions >=5 <7
and global fetch
API
#1951
feat: add instrumentation for undici
versions >=5 <7
and global fetch
API
#1951
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1951 +/- ##
==========================================
- Coverage 90.97% 90.82% -0.16%
==========================================
Files 146 148 +2
Lines 7492 7672 +180
Branches 1502 1537 +35
==========================================
+ Hits 6816 6968 +152
- Misses 676 704 +28
|
…vid-luna/opentelemetry-js-contrib into dluna-feat-add-undici-instrumentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this 🚀
(some comments from a very quick pass, detailed review to follow 🙂)
plugins/node/opentelemetry-instrumentation-undici/tsconfig.json
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for working on this! I tested it out locally and it works great 🎉
I've added some suggestions for a few typos (those should be one-click-commit), and also I'd like to rethink the semantic attributes approach and instead use the semantic-convention package. It will then use some older conventions, yes, but it will be aligned with the other instrumentations. Then when we're ready we can update the semantic convention package for all instrumentations.
*/ | ||
|
||
// DO NOT EDIT, this is an Auto-generated file from scripts/semconv/templates//templates/SemanticAttributes.ts.j2 | ||
export const SemanticAttributes = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I'm not sure it's a good idea to set semantic attributes here in this instrumentation instead of using the semantic convention package. Is there a reason we are doing this? I would suggest using the @opentelemetry/semantic-conventions
package instead. For example, here is a section in the http instrumentation using the semantic attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the motivation is to use the latest version of semantic conventions and the way (as agreed in the SIG). The current version available miss most of the attributes:
http.request.method
url.full
url.path
url.query
url.scheme
server.address
server.port
user_agent.original
network.peer.address
network.peer.port
- ...
We could import semantic conventions for a couple of attributes but the rest are not available yet therefore we need to have it in this package and replace them when we finally get semconv updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we did this with a couple of packages already where we needed names that were not available in @opentelemetry/semantic-conventions
yet. As David said, the package is very outdated but we can't re-generate it until @opentelemetry/[email protected]
, as it's already stable.
I agree that it's not optimal, but let's do it like this for now where we add it to the instrumentation package then follow-up once the @opentelemetry/[email protected]
situation is solved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, sorry I missed that conversation about adding them here. My bigger concern really is about the http semantic conventions that changed, and trying to be consistent with other instrumentations and help end users. For example, look at this trace that contains both http and undici instrumentation. The http instrumentation uses the older semantic conventions, and the undici uses the newer. This means the same fields have different attribute names, which can be difficult for folks to deal with and compare in their backend. For the attributes that are the same, can we use the old ones and/or introduce the environment variable for http/dup
to let folks get both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, sorry I missed that conversation about adding them here. My bigger concern really is about the http semantic conventions that changed, and trying to be consistent with other instrumentations and help end users. For example, look at this trace that contains both http and undici instrumentation. The http instrumentation uses the older semantic conventions, and the undici uses the newer. This means the same fields have different attribute names, which can be difficult for folks to deal with and compare in their backend. For the attributes that are the same, can we use the old ones and/or introduce the environment variable for
http/dup
to let folks get both?
Aaah, I see. I completely agree that the inconsistency is a major headache. However, I it's in accordance with the semantic conventions for a new instrumentation to only emit new attributes. If we start requiring new instrumentations to also do that, we'll be burning a lot of our time doing so.
I think the better way forward to solve the issue would be to actually update the HTTP instrumentation to allow dual-emitting of old and new attributes as defined here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd volunteer on update the HTTP instrumentation. I wonder if undici
instrumentation should be blocked until HTTP has the dual mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@david-luna IMO it should not block this PR as it does not make the package part of the auto-instrumentation package. Users already explicitly opt-in to the new semconv based telemetry by installing and using the undici-instrumentation directly.
plugins/node/opentelemetry-instrumentation-undici/src/internal-types.ts
Outdated
Show resolved
Hide resolved
plugins/node/opentelemetry-instrumentation-undici/src/internal-types.ts
Outdated
Show resolved
Hide resolved
plugins/node/opentelemetry-instrumentation-undici/src/internal-types.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Jamie Danielson <[email protected]>
Co-authored-by: Jamie Danielson <[email protected]>
Co-authored-by: Jamie Danielson <[email protected]>
…-types.ts Co-authored-by: Jamie Danielson <[email protected]>
…-types.ts Co-authored-by: Jamie Danielson <[email protected]>
Co-authored-by: Marc Pichler <[email protected]>
This instrumetation subscribes to certain [diagnostics_channel](https://nodejs.org/api/diagnostics_channel.html) to intercept the client requests | ||
and generate traces and metrics. In particular tracing spans are started when [undici:request:create](https://undici.nodejs.org/#/docs/api/DiagnosticsChannel?id=undicirequestcreate) | ||
channel receives a message and ended when [undici:request:trailers](https://undici.nodejs.org/#/docs/api/DiagnosticsChannel?id=undicirequesttrailers) channel receive a message. | ||
This means the full reponse body is received when the instrumentation ends the span. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a little unclear - how about This means the full response body is received within the span
if that's correct, or This means the full response body has been received when the instrumentation ends the span
(typo in reponse
as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your feedback :) I'm inclined to replace it with the 2nd option you gave
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A final round of nits; thanks for working on this. 🙂
Co-authored-by: Marc Pichler <[email protected]>
Co-authored-by: Marc Pichler <[email protected]>
Co-authored-by: Marc Pichler <[email protected]>
Co-authored-by: Marc Pichler <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Nice work.
Thanks to everyone who put time into this. Can't wait to let it rip. |
…` and global `fetch` API (open-telemetry#1951) Closes: open-telemetry/opentelemetry-js#4333 Co-authored-by: Jamie Danielson <[email protected]> Co-authored-by: Trent Mick <[email protected]> Co-authored-by: Marc Pichler <[email protected]>
Thanks so much for this feature @david-luna 🙏 🥳 Just tested it with our micro-services and it works great 😍 |
Which problem is this PR solving?
Node's
fetch
global API is not instrumented therefore any outgoing request made with it are not going to be traced.Ref: open-telemetry/opentelemetry-js#4333
The
fetch
API is usingundici
under the hood and diagnostic channels emit info also whenfetch
is used. So this instrumentation works for:fetch
undici
Short description of the changes
undici
packagefetch
andundici