Skip to content

Include spans from beforeAll hook in jest test suite #5677

@BridgeAR

Description

@BridgeAR

Discussed in https://github.com/DataDog/dd-trace-js/discussions/5577

Originally posted by smcroskey April 14, 2025
We have our datadog configured to emit traces for our Jest tests using DD_CIVISIBILITY_AGENTLESS_ENABLED=true for our CI integration tests, and all is working well; i.e. we have traces/spans for every test suite and test in datadog. However, one thing we'd like to do is also instrument work done in the beforeAll hooks within each test suite, as these often have lengthy setup steps and we want visibility into the beforeAll hook durations and errors.

Inside a beforeAll hook, however, it seems that tracer.scope().active() is null, so any tracer.trace(...) spans aren't linked back to the test session (span) context. Is there a way to link a custom span created via tracer.trace(...) to the parent test suite span?E.g. I imagine we'll need to somehow get the testSessionId/testModuleId like here to derive the correct span context?


I (@BridgeAR) opened this as feature request, since I can imagine it's useful for more users and asked @smcroskey to reach out to our support to request it officially.

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