Repository navigation
Description
Hello,
some days ago my team tried to update the currently used layer to the latest version from v65. First, we tried with v68 and noticed a huge decrease in the hits metrics generated through the tracing tool: for example when using tracer.trace('name', ...), we saw a decrease in the metrics trace.name.hits.
Checking documentation and such, we noticed that the env var DD_TRACE_SAMPLE_RATE was deprecated so we migrated to use the new one DD_TRACE_SAMPLING_RULES (moving from DD_TRACE_SAMPLE_RATE=0.4 to DD_TRACE_SAMPLING_RULES='[{"sample_rate": 0.4}]'. Sadly, the issue was still there. We decided to give a try to v78, but the problem persisted.
When enabling the debugging option, I see the following output (shortened for simplicity):
// v65 using DD_TRACE_SAMPLE_RATE
{
"os_name": "Linux",
"os_version": "5.10.236-249.934.amzn2.aarch64",
"architecture": "arm64",
"version": "4.44.0",
"lang": "nodejs",
"lang_version": "20.19.1",
"sample_rate": 0.4,
"sampling_rules": [
{
"matchers": [],
"_sampler": {
"_rate": 0.4
},
"_limiter": {
"_rateLimit": 100,
"_limiter": {
"tokenBucket": {
"bucketSize": 100,
"tokensPerInterval": 100,
"interval": 1000,
"parentBucket": null,
"content": 99,
"lastDrip": 1748592474968
},
"curIntervalStart": 1558141,
"tokensThisInterval": 2
},
"_tokensRequested": 2,
"_prevIntervalTokens": 0,
"_prevTokensRequested": 0
}
}
],
...
}
// v78 using DD_TRACE_SAMPLING_RULES
{
"os_name": "Linux",
"os_version": "5.10.236-249.934.amzn2.aarch64",
"architecture": "arm64",
"version": "4.44.0",
"lang": "nodejs",
"lang_version": "20.19.1",
"sampling_rules": [
{
"matchers": [],
"_sampler": {
"_rate": 0.4
}
}
],
...
}One thing that I noticed, but not sure at all, is that even though the sample rate was configured, I saw a 100% of the traces —no sampling?—, so not sure whether it's normal after the update.
thank you
Activity
HiDAl commentedon Jun 2, 2025
Well, I've ran some experiments and adding the env var
DD_EXTENSION_VERSION=compatibilityseems to fix the issue. I'm closing this.duncanista commentedon Jun 2, 2025
Hey, I'm gonna re-open this as it looks like a bug in the Next Gen Extension
HiDAl commentedon Jun 2, 2025
cool! We've an internal case open with DD where we are sharing some info. I can share this screenshot of my tests using different
datadog-lambda-extensionand DatadogLayer versions.As you can see, the bug seems to be on the extension, because
v65+layerV(115|125)worksduncanista commentedon Jun 4, 2025
Hey @HiDAl
Just wanted to let you know that I found the internal case and I'm looking at it.
What I can share right now from my end is that trace metrics are not supposed to be accurate for Serverless due to historical reasons and we've been working on a fix for it.
What I've seen is the following:
This is a Serverless specific scenario which I'm looking closely to fix with other members of different teams at Datadog, will keep you updated.
-- Jordan G
cstarling-gc commentedon Aug 27, 2025
We’re hitting the same issue and found that setting DD_EXTENSION_VERSION=compatibility works as a workaround to upgrade. From what I understand, that means the Next Gen Extension isn’t being used
Just curious — have there been any updates on this since the last discussion?
lym953 commentedon Aug 27, 2025
@cstarling-gc Thanks for the bump. I'm working on this, and will target at fixing this by the end of September.
jlongman commentedon Oct 8, 2025
compatibilitywill be removed in v88 -- has this been fixed? (Support case from March, #2088639)lym953 commentedon Oct 8, 2025
@jlongman Thanks for the bump. We are still testing our new solution since it still produces inaccurate counts in some cases.
From what we know, in
compatibilitymode, trace metrics are also inaccurate. For example,hitsare often double counted. Could you check if it's the case for you by comparing the trace metrictrace.aws.lambda.hitswith Lambda metricaws.lambda.invocations?jlongman commentedon Oct 9, 2025
We have some old code out there which may not be up to date. I don't see a filter for extension version but "most" code should be running in
compatibilityor at least pre-date the new extension:It's not clearly 2x. If I do
(a/b)*100across all services in that window I get ~58-63%.choosing a specific service:
The dip is 22%, the peak 38%
If I do
(b/a)it looks like the sampling periods are different as I have a triangle waveform.1 remaining item
jlongman commentedon Oct 9, 2025
Oh, and IIUC there's a fix in dd-trace-js v68 but the extension at v87 only has dd-trace-js v66 so we either lose our invocations metrics or don't get trace ids in logs. Well, replacing pino might be easier.
lym953 commentedon Oct 10, 2025
@jlongman Thanks for the additional info. Would it be possible to pin to v87 for now if you prefer to use
compatibilitymode for trace metrics (even if it's also inaccurate)?Fixing trace metrics is my highest priority right now, and I'll try to fix it sooner for non-compatibility mode.
jlongman commentedon Oct 11, 2025
Yes, we’re pinned now. Godspeed etc to you.
lym953 commentedon Oct 21, 2025
We are still working with internal teams to debug the over/under-counting issue.
feat: [Trace Stats] Do not set ClientStatsPayload.hostname (#905)
lym953 commentedon Nov 5, 2025
Thanks for your patience. We are still working with backend teams to fix the undercounting issue in case of concurrent executions. Meanwhile, I'm planning to release this imperfect solution in the next release (v89) and allow you to opt in by setting an env var if you want to test it out.
lym953 commentedon Nov 23, 2025
v89 contains an "alpha" version of the new trace metric solution. If interested, you can opt in by setting env var
DD_COMPUTE_TRACE_STATS_ON_EXTENSIONtotrue. It defaults tofalsenow, and we plan to switch the default totrueonce the new solution is mature.This new solution currently has known limitations:
[SVLS-6907] feat: Support span dedup (#939)
jlongman commentedon Feb 18, 2026
I just checked and noted v92 was just released, I haven't had a chance to verify behaviour changes but will soon.
lucaspimentel commentedon Jun 26, 2026
Update:
DD_COMPUTE_TRACE_STATS_ON_EXTENSIONwas renamed toDD_LAMBDA_EXTENSION_COMPUTE_STATSin #1266.jlongman commentedon Jul 9, 2026
@lym953 does the compatibility flag still do anything? I just realized we've moved up libs and extensions but the flag is still present. eg
jlongman commentedon Jul 9, 2026
ah:
So if this means that we are using the new agent then I believe the serverless stats are correct.
jlongman commentedon Jul 10, 2026
I updated a lambda to this and now I'm seeing


I feel like I've forgotten something though, it's been a while.
jlongman commentedon Jul 10, 2026
Ah I had not set
DD_LAMBDA_EXTENSION_COMPUTE_STATS(orDD_COMPUTE_TRACE_STATS_ON_EXTENSION):This maybe speaks to the double-counting you mentioned also. Will move forward with this! Thanks!
purple4reina commentedon Jul 14, 2026
Hello all,
Just a quick update on the state of Trace Stats in the Datadog Lambda Extension.
As has been stated already, if you are sampling your spans and using the next-generation extension (v88 or newer), you will see undercounted trace stats based on the sampled data rather than your actual throughput.
Add
DD_LAMBDA_EXTENSION_COMPUTE_STATS=truewill now accurately calculate trace stats based on your actual throughput. If you are currently sampling your traces, we recommend switching to these extension computed stats.However, we are not yet ready to release extension computed stats by default. If you currently set span derived primary tags (via your APM > Settings > Default Settings in the Datadog UI), these primary tags will not be added to trace stats when computed in the extension.
Give this new stats implementation a test run and let us know if this fixes any of your issues.
R