-
Notifications
You must be signed in to change notification settings - Fork 328
Fix span pointers env var & tests #5546
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
Fix span pointers env var & tests #5546
Conversation
Overall package sizeSelf size: 9.33 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | @datadog/libdatadog | 0.5.1 | 29.73 MB | 29.73 MB | | @datadog/native-appsec | 8.5.2 | 19.33 MB | 19.34 MB | | @datadog/native-iast-taint-tracking | 3.3.1 | 13.99 MB | 13.99 MB | | @datadog/pprof | 5.7.1 | 9.51 MB | 9.88 MB | | @opentelemetry/core | 1.30.1 | 908.66 kB | 7.16 MB | | protobufjs | 7.4.0 | 2.77 MB | 5.42 MB | | @datadog/wasm-js-rewriter | 4.0.1 | 2.85 MB | 3.58 MB | | @datadog/native-metrics | 3.1.1 | 1.02 MB | 1.43 MB | | @opentelemetry/api | 1.8.0 | 1.21 MB | 1.21 MB | | import-in-the-middle | 1.13.1 | 117.64 kB | 839.26 kB | | source-map | 0.7.4 | 226 kB | 226 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | lru-cache | 7.18.3 | 133.92 kB | 133.92 kB | | pprof-format | 2.1.0 | 111.69 kB | 111.69 kB | | @datadog/sketches-js | 2.1.1 | 109.9 kB | 109.9 kB | | lodash.sortby | 4.7.0 | 75.76 kB | 75.76 kB | | ignore | 5.3.2 | 53.63 kB | 53.63 kB | | istanbul-lib-coverage | 3.2.0 | 29.34 kB | 29.34 kB | | rfdc | 1.4.1 | 27.15 kB | 27.15 kB | | @isaacs/ttlcache | 1.4.1 | 25.2 kB | 25.2 kB | | dc-polyfill | 0.1.8 | 25.08 kB | 25.08 kB | | tlhunter-sorted-set | 0.1.0 | 24.94 kB | 24.94 kB | | shell-quote | 1.8.2 | 23.54 kB | 23.54 kB | | limiter | 1.1.5 | 23.17 kB | 23.17 kB | | retry | 0.13.1 | 18.85 kB | 18.85 kB | | semifies | 1.0.0 | 15.84 kB | 15.84 kB | | jest-docblock | 29.7.0 | 8.99 kB | 12.76 kB | | crypto-randomuuid | 1.0.0 | 11.18 kB | 11.18 kB | | ttl-set | 1.0.0 | 4.61 kB | 9.69 kB | | path-to-regexp | 0.1.12 | 6.6 kB | 6.6 kB | | koalas | 1.0.2 | 6.47 kB | 6.47 kB | | module-details-from-path | 1.0.3 | 4.47 kB | 4.47 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5546 +/- ##
==========================================
+ Coverage 79.27% 79.33% +0.06%
==========================================
Files 513 514 +1
Lines 23342 23416 +74
==========================================
+ Hits 18504 18577 +73
- Misses 4838 4839 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
This should be tested to avoid the same situation happening again.
BenchmarksBenchmark execution time: 2025-04-16 17:14:50 Comparing candidate commit fe9434a in PR branch Found 2 performance improvements and 0 performance regressions! Performance is the same for 946 metrics, 15 unstable metrics. scenario:startup-with-tracer-22
|
Datadog ReportBranch report: ✅ 0 Failed, 926 Passed, 0 Skipped, 9m 33.79s Total Time |
@rochdev Looks like the config requires a default value to be set (see https://github.com/DataDog/dd-trace-js/blob/nicholas.hulston/fix-dynamodb-span-ptr-env-var/packages/dd-trace/src/config.js#L444-L445), but it seems this is not tested in unit tests. This seems like a bigger issue with testing I'm currently working on functional tests for Serverless; that's how I discovered this issue: |
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 faulty change is about the default value. It was originally just undefined. Changing it to the correct name should still result in the same behavior. It is still a falsy value and that did not change by renaming the default.
AFAIC the issue is somewhere else.
@BridgeAR I've tested manually and this one-liner fixes our regression |
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 checked again and we seem to iterate over the default keys in the config to merge just those values. That is something we should probably fix. It is weird that we need a default value for any value to be defined later.
This will therefore indeed fix the issue.
After looking into the tests, it seems that those do not get executed properly. If I read the code correct, the test calls testSpanPointers() which returns a method that is never called and the test passes. Please always make sure that the test fails initially before letting it pass. That way we guarantee that our test actually tests the changed code. A good coding pattern for this is Test Driven Development.
I am going to approve this due to indeed fixing the issue but please fix the tests right afterwards. I will have a look at the config sometime during the next weeks.
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 don't see having tests elsewhere that don't fail on PRs and that might manually be checked before releasing a dependant library after releasing a broken dd-trace a satisfactory testing strategy. If there is a missing test for this feature, let's add it in this repo.
0007c7b
to
e2fa243
Compare
e2fa243
to
4fe0deb
Compare
The issue was that the dynamodb span pointer tests were not failing when they should have failed. I've fixed that issue in this PR. Thanks :) |
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 looking into the tests! Now that they run, they seem to cause a lot of tests to fail 😅
412eeaf
to
8af1ab3
Compare
Co-authored-by: Ruben Bridgewater <[email protected]>
Co-authored-by: Ruben Bridgewater <[email protected]>
… one test Co-authored-by: Ruben Bridgewater <[email protected]>
ed6f96f
to
976b3f1
Compare
operation: (callback) => { | ||
dynamo.deleteItem({ | ||
operation () { | ||
return util.promisify(dynamo.deleteItem).bind(dynamo)({ |
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.
Could you please use a helper method that checks if the method already supports promises and to use that instead in those cases? That way we prevent the deprecation warning from popping up and having to fix this later.
That applies to all usages of util.promisify()
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 with the deprecation warnings gone :)
delete process.env.DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS | ||
}) | ||
async function testSpanPointers ({ env, expectedHashes, operation }) { | ||
await agent.close({ ritmReset: false, wipe: true }) |
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.
This should be done in after
or afterEach
, never in tests directly to avoid dependencies between tests.
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.
It should actually be a beforeEach to match the current behavior (that is also reflected in the test failures).
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. I moved the agent.close
call into beforeEach
. However, we still have to load the agent inside this method because we have to update the env var before loading the agent.
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.
It should actually be a beforeEach to match the current behavior (that is also reflected in the test failures).
Why would it be needed in beforeEach
if afterEach
cleans up properly?
However, we still have to load the agent inside this method because we have to update the env var before loading the agent.
That's fine, although I think it could be refactored to happen in a before
.
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.
If we try to close the agent but it's already been closed, the tests fail. So the first test in this describe block will fail if we put it in afterEach.
Seems like an issue with the mock agent, but that's outside the scope of this PR.
I'm not a member of the APM team; just trying to fix a feature for Serverless
|
||
before(async () => { | ||
await agent.load('aws-sdk') | ||
await agent.load() |
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.
Why the empty agent.load()
?
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.
Not sure, I didn't write these with configuration
tests. Looks like we need to load the agent with a specific tracer config, and closing the agent when it's not already loaded causes failures. It fails without this line
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 am just trying to fix a regression; these tests are unrelated
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.
Still LGTM. This is definitely a big improvement. It fixes the reported issue and the tests are now run. So no matter that there are a few more theoretical improvements about how these tests could be implemented, it's a big improvement.
What does this PR do?
Fixes dynamodb span pointer tests which were not running correctly.
Also fixes the
trace.dynamoDb.tablePrimaryKeys
env var.Also, here I remove a duplicate log

Motivation
It looks someone accidentally renamed the env var
trace.dynamoDb.tablePrimaryKeys
toaws.dynamoDb.tablePrimaryKeys
. This was not caught because the tests were not failing when expected.(Originally, it was
aws.dynamoDb
but I changed it totrace.dynamoDb
. Looks like later, someone must've rebased incorrectly and reverted my change in #5266)Plugin Checklist
Additional Notes
https://datadoghq.atlassian.net/browse/SVLS-6602