Visitar URL original
Feature Request: Undici / Global Fetch integration · Issue #1615 · DataDog/dd-trace-js · GitHub
Skip to content

Feature Request: Undici / Global Fetch integration #1615

Closed

Description

@flovilmart

Hi there!

We're starting to shift away from axios / request and wish to roll out undici in our new deployments.
Unfortunately, there is no 'official' tracing package for it.

Is it something that is being worked on? Would a PR be accepted to add an undici plugin? Should I be aware of any 🐉 ?

Thanks!

Activity

  1. rochdev commented on Sep 15, 2021

    @rochdev
    Member

    Is it something that is being worked on?

    We've been looking into using Undici for sending traces, but we haven't looked into writing a plugin for it yet.

    Would a PR be accepted to add an undici plugin?

    Definitely accepted and welcomed!

    Should I be aware of any 🐉 ?

    Not that I know of, it should be pretty similar to other HTTP servers/clients that are already supported.

  2. flovilmart commented on Sep 15, 2021

    @flovilmart
    Author

    Thanks @rochdev ; I'll draw some inspiration from the http tracing plugin.

  3. bengl commented on Sep 15, 2021

    @bengl
    Collaborator

    @flovilmart Note also that undici has also recently added support for diagnostics channel, so we'll want to use that in versions of undici where that's available.

    https://github.com/nodejs/undici/blob/main/docs/api/DiagnosticsChannel.md

  4. flovilmart commented on Sep 29, 2021

    @flovilmart
    Author

    That's a super neat feature those diagnostics channels!
    I assume we want both implementations and patch based on the node.js and undici versions?

  5. rochdev commented on Sep 30, 2021

    @rochdev
    Member

    @flovilmart It should be based on the undici version, but the Node version shouldn't matter since in older versions the module will not exist so the plugin will simply never run. Since we're in the process of rewriting a lot of how plugins work and there are no examples currently of using diagnostics channel in a plugin, I would recommend writing the plugin like any other plugin (for example HTTP) and not worry about diagnostics channel for now.

  6. flovilmart commented on Oct 2, 2021

    @flovilmart
    Author

    OK that works for me @rochdev , we're not even on node 16 yet! I planned to get on that next week.

  7. flovilmart commented on Oct 5, 2021

    @flovilmart
    Author

    Got this nodejs/undici#1053 patch done for undici for better compatibility.

    Outside the request call, patching all other API's (pipeline, stream etc...) is proven to be cumbersome.

    The implementation through the diag channels is very straightforward with some book-keeping.
    I'll visit the implementation through patching the Client and Request objects after.

  8. flovilmart commented on Oct 5, 2021

    @flovilmart
    Author

    @rochdev , what do you think about this:nodejs/undici#1053 (comment)?

  9. rochdev commented on Oct 5, 2021

    @rochdev
    Member

    @flovilmart Actually it's fine if the implementation in Undici is backed 100% by diagnostics channel. My thought was that we need to do the monkey-patching anyway to support older versions of Undici without the channel available. In that sense, the idea was to first implement the monkey-patching and then add support to use the channel once it lands in Undici. This doesn't mean adding any monkey-patching ability to Undici since that would be redundant when the channels are available.

    So basically:

    • dd-trace would support older versions of Undici with monkey-patching.
    • dd-trace would support newer versions of Undici with diagnostics channel subscribers when the publishers are implemented in Undici.

    In both cases, no change is needed in Undici other than adding diagnostics channel support.

  10. flovilmart commented on Oct 5, 2021

    @flovilmart
    Author

    @rochdev @bengl I've open the PR above to gather initial feedback around the implementation.
    Notably, the next tests seem to fails because of the inclusion of the diagnostic_channels module. Any guidance on the workaround?

    For now, I'm waiting for a new release of undici, which explains why the tests are currently failing.

  11. rochdev commented on Oct 19, 2021

    @rochdev
    Member

    Notably, the next tests seem to fails because of the inclusion of the diagnostic_channels module. Any guidance on the workaround?

    @flovilmart Not sure why these would interact. Can you try rebasing the PR? There was a change to how Next is tests a few weeks ago, maybe that change wasn't in your branch and it would fix the issue.

  12. flovilmart commented on Oct 19, 2021

    @flovilmart
    Author

    Interesting! I've rebased, let's see how it goes!

  13. JustinTRoss commented on Jan 27, 2022

    @JustinTRoss
    Contributor

    Any resolution on this since? I see in your PR that there has been some back and forth on whether to solve monkey-patching or diagnostic channels approach first.

    Are we pinning this to Undici DC PR as a dependency?

  14. flovilmart commented on Jan 27, 2022

    @flovilmart
    Author

    @JustinTRoss I haven't had a chance to actually move forward with a new implementation; the monkey patching look very complex given undici's architecture; there are multiple APIs that leverage dispatchers differently, I haven't found any "clean" monkey patching strategy for all APIs (request, client, pipeline etc...)

  15. 3 remaining items

  16. kibertoad commented on Oct 13, 2022

    @kibertoad

    @flovilmart Maybe it might make sense to skip the complex monkey-patching altogether and only support newer versions of Undici?

  17. rochdev commented on Oct 13, 2022

    @rochdev
    Member

    Quick update related to the above: we're currently finishing up the new approach which we'll be trying internally in the next few weeks, and we plan to add instrumentation to Undici directly in Node core soon after. That work can be tracked in nodejs/node#44943

  18. flovilmart commented on Oct 13, 2022

    @flovilmart
    Author

    Amazing work @rochdev glad your team was able to pull it through! That was not a simple endeavour!

  19. mrkosima commented on Apr 24, 2023

    @mrkosima

    hello there, are there any updates on Undici support?

  20. saimon-moore commented on Jun 1, 2023

    @saimon-moore

    Looks like this nodejs/node#44943 was merged so I guess this is closer now?

  21. SimpleCreations commented on Aug 17, 2023

    @SimpleCreations

    I see that support for fetch has been added here (#3258).
    Does this mean this issue can be closed now?

  22. cassiascheffer commented on Oct 27, 2023

    @cassiascheffer

    We tested out undici for our gateway application and datadog didn't report any traces for backend services when we used undici. I don't think this issue can be closed until dd-trace supports undici.

    We are using dd-trace-js v 4.14.0

  23. SimpleCreations commented on Oct 27, 2023

    @SimpleCreations

    I meant to say that most people want undici support because the Fetch API uses undici. But I guess there are cases when one might use undici without fetch.

  24. changed the title [-]Support for undici tracing[/-] [+]Feature Request: Undici Support[/+] on Dec 18, 2023
  25. changed the title [-]Feature Request: Undici Support[/-] [+]Feature Request: Undici / Global Fetch integration[/+] on Dec 18, 2023
  26. dpnova commented on Jun 29, 2024

    @dpnova

    https://datadoghq.dev/dd-trace-js/interfaces/export_.plugins.undici.html

    Whatever this is, it doesn't work.

    It's very hard to find docs on the over-the-wire format of datadog APM trace metadata (datadog or otel tracecontext) - everything points to libs.

    Well AFAICT there's no datadog lib that can instrument undici yet, so I'm trying to do it manully.

    Thus far, not having much luck with either otel's undici instrumentation or datadog's tease of one in the docs linked above.

    edit: udpate - turns out our code was not using global fetch but one of the other libs. My mistake!

  27. alyahmedaly commented on Apr 11, 2025

    @alyahmedaly

    @tlhunter do you mind shared an update about the status, and is there is anything we can do like using hooks to get something working for now?

  28. rochdev commented on Jun 4, 2025

    @rochdev
    Member

    Closing as support for undici and fetch have landed in 5.17.0 and 4.3.0 respectively.

    Note: this is only true for the fetch API in both cases. If you are looking for undici's other APIs such as request, please upvote #5268

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions