-
Notifications
You must be signed in to change notification settings - Fork 294
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
Tests using the Jest plugin cannot access tracing scope #1999
Comments
If the above fix seems reasonable, I'm happy to open a pull request for it! |
I added a sample pull request to address this issue. It works locally, but I'm not sure if it's the right fix. |
hi @mdbenjam ! Thanks for the explanation and possible fix. Are you using the CI Visibility instrumentation of This should initialise the tracer where it matters: in the environment of the tests. Initializing in a different way might result in what you describe. |
Hi @juan-fernandez , thanks so much for the quick response! I did follow the instructions on that page but am still seeing the issue. I've made a minimal reproduction here. This test is currently failing and will pass when the current tracing scope is not null. Which I assume should be the behavior that's expected. I tried to follow the setup on the link you sent, though note I removed the Let me know if something in the setup doesn't look right to you! |
Sadly I just realized my "fix" doesn't work when tests are concurrent |
Hey @juan-fernandez ,
Sorry that was somewhat vague. We run a bunch of our tests with jests'
So I was not seeing the traces on our real test (I hadn't looked for the actual traces in my example test case 🤦 ), but I realized today that the real test in our code base I was trying was marked as So I think there might be a separate issue where |
hey @mdbenjam , thanks for the info and the branches. So I hadn't actually tested the behavior of the plugin with The test function is called "right away", before I'll try to fix it, and in any case in the mean time we should add a known limitation to the docs. It seems the support for |
the same happens with |
@juan-fernandez I'm also new to |
#2003 (inspired in your PR) should fix this issue for anything other than |
Thanks for the update! The PR looks good. I've closed mine in favor of yours. As for |
thanks for your update too!
Thanks for sharing this too. I think this is a great idea 👍 |
Describe the bug
When enabling Jest tracing I expect to see connected traces for operation in my test. For example, if the test makes an http request, I expect to see that request as a sub span of the full test span.
However, in the CI tool I only ever see the top level span. Looking in the APM tool I can find relevant http spans from the test, but they're not connected to the span for the full test. They seem to be orphaned.
Digging in, I believe the reason for this is within a test
global._ddtrace
is not defined. I think this is because the global context within the test appears to be somewhat isolated from the global context of the test runner. I addedhere: https://github.com/DataDog/dd-trace-js/blob/v2.5.0/packages/datadog-plugin-jest/src/jest-environment.js#L107 and got the spans to all show up together in the CI tool. I'm not familiar enough with Jest Environments to know if this is the correct fix.
Environment
The text was updated successfully, but these errors were encountered: