Skip to content

Decrease in trace metrics after updating to >v68 #688

Open

Description

@HiDAl

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

  1. HiDAl commented on Jun 2, 2025

    @HiDAl
    Author

    Well, I've ran some experiments and adding the env var DD_EXTENSION_VERSION=compatibility seems to fix the issue. I'm closing this.

  2. duncanista commented on Jun 2, 2025

    @duncanista
    Contributor

    Hey, I'm gonna re-open this as it looks like a bug in the Next Gen Extension

  3. added
    bug
    enhancement
    version/next
    on Jun 2, 2025
  4. HiDAl commented on Jun 2, 2025

    @HiDAl
    Author

    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-extension and DatadogLayer versions.

    Image

    As you can see, the bug seems to be on the extension, because v65 + layerV(115|125) works

  5. duncanista commented on Jun 4, 2025

    @duncanista
    Contributor

    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:

    1. With no sampling:
    • Compatibility will double count
    • Next Gen will count as expected.
    1. With sampling metrics are busted.

    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

  6. self-assigned this
    on Aug 18, 2025
  7. cstarling-gc commented on Aug 27, 2025

    @cstarling-gc

    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?

  8. lym953 commented on Aug 27, 2025

    @lym953
    Collaborator

    @cstarling-gc Thanks for the bump. I'm working on this, and will target at fixing this by the end of September.

  9. jlongman commented on Oct 8, 2025

    @jlongman

    compatibility will be removed in v88 -- has this been fixed? (Support case from March, #2088639)

  10. lym953 commented on Oct 8, 2025

    @lym953
    Collaborator

    @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 compatibility mode, trace metrics are also inaccurate. For example, hits are often double counted. Could you check if it's the case for you by comparing the trace metric trace.aws.lambda.hits with Lambda metric aws.lambda.invocations?

  11. jlongman commented on Oct 9, 2025

    @jlongman

    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 compatibility or at least pre-date the new extension:

    Image

    It's not clearly 2x. If I do (a/b)*100 across all services in that window I get ~58-63%.

    Image

    choosing a specific service:

    Image

    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.

    Image
  12. 1 remaining item

  13. jlongman commented on Oct 9, 2025

    @jlongman

    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.

  14. lym953 commented on Oct 10, 2025

    @lym953
    Collaborator

    @jlongman Thanks for the additional info. Would it be possible to pin to v87 for now if you prefer to use compatibility mode 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.

  15. jlongman commented on Oct 11, 2025

    @jlongman

    Yes, we’re pinned now. Godspeed etc to you.

  16. lym953 commented on Oct 21, 2025

    @lym953
    Collaborator

    We are still working with internal teams to debug the over/under-counting issue.

  17. lym953 commented on Nov 5, 2025

    @lym953
    Collaborator

    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.

  18. lym953 commented on Nov 23, 2025

    @lym953
    Collaborator

    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_EXTENSION to true. It defaults to false now, and we plan to switch the default to true once the new solution is mature.

    This new solution currently has known limitations:

    1. Slight overcount for Node.js runtime. It will be fixed by [SVLS-8169] feat: Support span dedup #939, which will be released in v90.
    2. Undercount of up to 20%, but it's usually < 1% from our recent tests. We are still trying to understand and fix it.
  19. jlongman commented on Feb 18, 2026

    @jlongman

    I just checked and noted v92 was just released, I haven't had a chance to verify behaviour changes but will soon.

  20. lucaspimentel commented on Jun 26, 2026

    @lucaspimentel
    Member

    Update: DD_COMPUTE_TRACE_STATS_ON_EXTENSION was renamed to DD_LAMBDA_EXTENSION_COMPUTE_STATS in #1266.

  21. jlongman commented on Jul 9, 2026

    @jlongman

    @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

    DD_EXTENSION_VERSION | compatibility
    
    Image
  22. jlongman commented on Jul 9, 2026

    @jlongman

    ah:

    This v88 release no longer contains the Compatibility Mode (Datadog Go Agent).
    DD_EXTENSION_VERSION=compatibility will no longer work to fallback. Yet you should not have any problems, this will not disturb your Lambdas or their execution.

    So if this means that we are using the new agent then I believe the serverless stats are correct.

  23. jlongman commented on Jul 10, 2026

    @jlongman

    I updated a lambda to this and now I'm seeing
    Image
    Image

    I feel like I've forgotten something though, it's been a while.

  24. jlongman commented on Jul 10, 2026

    @jlongman

    Ah I had not set DD_LAMBDA_EXTENSION_COMPUTE_STATS (or DD_COMPUTE_TRACE_STATS_ON_EXTENSION):

    Image

    This maybe speaks to the double-counting you mentioned also. Will move forward with this! Thanks!

  25. purple4reina commented on Jul 14, 2026

    @purple4reina
    Contributor

    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=true will 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugenhancementversion/next

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions