Skip to content

Working in non-nodejs environments #1892

Closed

Description

@ekosz

I was wondering if the DD team is thinking of how dd-trace-js may be used in non-nodejs environments. Things like Deno, Cloudflare Workers, etc. It looks like dd-trace-js heavily uses async_hooks which isn't available on other JS platforms.

Is there a way to use the library to just emit traces + spans, but with manual propagation (i.e. Always explicitly needing to set the parent span)?

Also, I see there is an API for sending manually created traces to DD, but it requires having an agent to collect the traces. For environments like Cloudflare Workers is it possible to send the traces directly to DD servers? Or would the suggestion be first send the traces to a central DC, which forwards them to a local agent, which then forwards them to DD?

Thanks!

Activity

  1. rochdev commented on Mar 3, 2022

    @rochdev
    Member

    I was wondering if the DD team is thinking of how dd-trace-js may be used in non-nodejs environments.

    Right now only Node is supported. Some environments like Deno would be potentially easier to support assuming it's compatible with Node modules, but for environments like Cloudflare Workers it would require explicit support. It's something we're looking into but I don't have a lot of details about that (happening outside of my team).

    It looks like dd-trace-js heavily uses async_hooks which isn't available on other JS platforms.

    Unfortunately this is needed to do automatic instrumentation. In environments without it (or something equivalent) only manual instrumentation would be possible. Since context propagation wouldn't be available in these environments, it would be up to the code to pass the spans around which would be extremely invasive to the code.

    Is there a way to use the library to just emit traces + spans, but with manual propagation (i.e. Always explicitly needing to set the parent span)?

    We're in the process of splitting dd-trace in multiple components and the low-level ones should work even without async_hooks but we're not there yet.

    For environments like Cloudflare Workers is it possible to send the traces directly to DD servers?

    Technically it's possible without the agent but you would have to use the endpoint that the agent uses which is not meant to be used externally. I would not recommend going that route as the agent is doing a lot of things that are not documented publicly, some of which might impact functionality or cause over-billing if not implemented properly.

    Or would the suggestion be first send the traces to a central DC, which forwards them to a local agent, which then forwards them to DD?

    That would definitely be the recommended approach, at least for now. It requires more setup but would be in line with how Datadog is meant to be used. We have plans to reduce (or remove) reliance on the agent in dd-trace which will definitely help later on as well.

  2. ekosz commented on Mar 4, 2022

    @ekosz
    Author

    @rochdev Thank you so much for the context! If I end up writing my own library (probably something similar to the Cloudflare Workers Honeycomb lib), I'll post if here if it's useful for the DD team / wider DD community.

  3. ekosz commented on Dec 8, 2022

    @ekosz
    Author

    @rochdev Heya! Checking back in on this issue. I know a lot of changes have happened to dd-trace-js since March and now there are experimental exporters like to logs and such. Do you know if one can use dd-trace-js without NodeJS yet and if so, how to report those traces/spans to Datadog? Do you still need to get the payload to an agent running somewhere still? Or can we someone pickup the spans from our logs?

    Thanks!

  4. rochdev commented on Dec 9, 2022

    @rochdev
    Member

    @ekosz dd-trace itself cannot be used outside of Node, but I know there is an effort internally to support other environments using some more lightweight code specific to those environments. I don't have much more information than this unfortunately, but I would recommend reaching out to support so that they can forward the feature request to the right team and they would have more information about a timeline.

  5. ekosz commented on Dec 9, 2022

    @ekosz
    Author

    @rochdev Sounds good! Will do

  6. jfsiii commented on Dec 9, 2022

    @jfsiii

    @ekosz perhaps off-topic but you might find poking around https://github.com/RichiCoder1/opentelemetry-sdk-workers helpful.

    There's code written by the repo owner but much of it is built on @opentelemetry/* packages and https://github.com/open-telemetry/opentelemetry-proto/tree/e757e740ed7f63b2f969b45adf7abaea4a042fad

    You'll need to deploy an otel collector somewhere, it doesn't have to be on Workers, then that lib can generate and send traces to the collector which can send them to Datadog

  7. yoshixmk commented on May 24, 2023

    @yoshixmk

    @rochdev I was unable to use dd-trace using Deno. Any progress?
    Deno has a way to use the npm package, but I get an error like below.

    error: Uncaught TypeError: executionAsyncResource is not a function
        at AsyncResourceStorage._executionAsyncResource (file:///<user_path>/node_modules/.deno/dd-trace@4.0.0/node_modules/dd-trace/packages/datadog-core/src/storage/async_resource.js:100:12)
    ...
  8. rochdev commented on May 24, 2023

    @rochdev
    Member

    @yoshixmk Deno is not currently supported, and most of the library relies on features that are specific to Node, its built-in fork of v8, and libuv. I recommend reaching out to our support team with a feature request.

  9. Qard commented on Jun 8, 2023

    @Qard
    Contributor

    Other JS runtimes will get this for free in probably a year or so when AsyncContext reaches stage 3 and V8 implements it. Doesn't help us in the immediate term, but we should keep in mind there will be a sudden explosion in support capability when that happens.

  10. tian-sheng-low commented on Jun 21, 2023

    @tian-sheng-low

    @Qard
    Thanks for the words.

    Other JS runtimes will get this for free in probably a year or so when AsyncContext reaches stage 3 and V8 implements it

    Could you let me know where is the source? I would like to look into the detail and progress of AsyncContext and V8 implementation.

  11. Qard commented on Jun 21, 2023

    @Qard
    Contributor

    You can follow the proposal here: https://github.com/tc39/proposal-async-context

  12. jfsiii commented on Mar 24, 2025

    @jfsiii

    Other JS runtimes will get this for free in probably a year or so when AsyncContext reaches stage 3 and V8 implements it. Doesn't help us in the immediate term, but we should keep in mind there will be a sudden explosion in support capability when that happens.

    Now that Workers supports AsyncLocalStorage, diagnostics_channel, and many other node APIs I wonder how this impacts getting dd-trace or similar working in Workers.

    cc: @jasnell & @threepointone for visibility/triage at CF

  13. BridgeAR commented on May 6, 2025

    @BridgeAR
    Member

    I am going to close this, since we don't provide support in those environment by default. If it's about Cloudflare workers: it is likely best to ask if the missing features could be implemented there, while there will be better support in general "soon" (that may still take quite some time) due to the addition of the mentioned ECMAScript change.

    If you want to get official support in Datadog, please reach out to our support and request that feature https://www.datadoghq.com/support

  14. jasnell commented on Jun 22, 2025

    @jasnell

    If we can get a good cataloguing of what missing features there are in Cloudflare Workers I can look into getting those prioritized. As it is, I just don't yet have enough visibility into what is still needed.

  15. rochdev commented on Jun 26, 2025

    @rochdev
    Member

    If we can get a good cataloguing of what missing features there are in Cloudflare Workers I can look into getting those prioritized. As it is, I just don't yet have enough visibility into what is still needed.

    When we looked at it, it seemed like CloudFlare would be better served by additional plugins (so not the ones currently present in dd-trace) and we would also be able to use the tail worker integration to receive the messages published by instrumentation on diagnostics_channel in an external agent instead of processing them in the library itself. This is completely different than how dd-trace works, so it's unlikely that dd-trace itself will ever work in CloudFlare and it would instead be a new library tailored specifically to CloudFlare (which would also mean it would be a lot leaner and thus better adapted to a more constrained environment).

    It's not my team looking into that though so I'm not aware of any progress on this, but my understanding is that we have most of what we need out of the box already.

  16. jasnell commented on Jun 26, 2025

    @jasnell

    We're working on a few things with tail workers that should make it even more powerful and flexible. Happy to have a call sometime to explain what we're up to

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