fix: disable stats computation to prevent per-invocation latency in Lambda#244
Merged
Conversation
…head in Lambda Stats computation was enabled by default in dd-trace-go v2.1.0 (DataDog/dd-trace-go#3548). When extension v91+ advertises /v0.6/stats support in its /info response, tracer.Flush() makes a synchronous HTTP POST to http://127.0.0.1:8126/v0.6/stats before returning, adding 33-59ms per warm invocation. This fix disables stats computation at the tracer level so it is never posted from Lambda, mirroring the identical fix already applied to the dd-trace-go contrib Lambda wrapper in DataDog/dd-trace-go#4471 (APMSVLS-389). Resolves: SLES-2790
purple4reina
approved these changes
Apr 20, 2026
Contributor
I suspect that once we enable Agent-Side Stats, we'll start seeing these log messages again and probably see an increase in post runtime duration again. But I think you were seeing these requests for each invocation, but with proper Agent-Side Stats they'll be every 10s. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes ~40% Lambda latency regression for customers using
datadog-lambda-gowith extension v91+ and dd-trace-go v2.1.0+.Jira: SLES-2790
Root Cause
DataDog/dd-trace-go#3548 changed the default value of
DD_TRACE_STATS_COMPUTATION_ENABLEDfromfalsetotruein dd-trace-go v2.1.0, enabling client-side stats computation by default.What happens when stats computation is enabled
At the end of every Lambda invocation,
HandlerFinishedcallstracer.Flush(). Here is the exact call chain when stats computation is enabled:tracer.Flush()sends a flush signal to the tracer worker goroutine and blocks on adonechannelflushAndSend()callscanComputeStats(), which returnstruewhen three conditions are met:StatsComputationEnabled == true(default since v2.1.0)stats: truein its/inforesponse (extension v91 does this)drop_p0s: truein its/inforesponseflushAndSend()makes a synchronous HTTP POST tohttp://127.0.0.1:8126/v0.6/statsdoneget sent, unblockingtracer.Flush()This means every Lambda invocation pays an extra HTTP round-trip to the extension — on top of the trace payload flush — before the handler can return. This round-trip is 33–59ms per warm invocation and up to 809ms on cold start (first TCP connection to extension).
Why extension v58→v91 matters: Extension v58 did not advertise the
/v0.6/statsendpoint in its/inforesponse, socanComputeStats()returnedfalseand no stats POST was made. Extension v91 added this support, which combined with the v2.1.0 default change means all three conditions became true simultaneously — triggering the regression.Why disabling telemetry didn't help:
DD_INSTRUMENTATION_TELEMETRY_ENABLED=falsedisables the telemetry reporter goroutine (a completely different subsystem). The correct env var to disable stats computation isDD_TRACE_STATS_COMPUTATION_ENABLED=false.Fix
Added
tracer.WithStatsComputation(false)toinitTracer()ininternal/trace/listener.go. This sets the tracer option that disables stats computation regardless of theDD_TRACE_STATS_COMPUTATION_ENABLEDenv var and regardless of what the extension advertises in/info. The extension still receives and processes traces — only the stats pre-aggregation and the/v0.6/statsPOST are skipped.This is the identical fix already applied to dd-trace-go's own Lambda wrapper in DataDog/dd-trace-go#4471 (APMSVLS-389).
Verification
Two Go Lambda functions were deployed to AWS sandbox using extension v91 on
provided.al2/x86_64(matching the customer's exact config):sles-2790-go-unfixed: published datadog-lambda-go v1.31.0 (stats enabled by default)sles-2790-go-fixed: patched withWithStatsComputation(false)10,000 warm invocations per function (20 sequential warm-up invocations excluded, then 10,000 test invocations at 10 concurrent workers):
Every percentile improved. The median (30ms → 21ms, 32% improvement) is the cleanest signal as it is least affected by cold-start outliers.
CloudWatch extension logs for the unfixed function show on every invocation:
Fixed function: no
Stats requestlog line at all across all 10,000 invocations.Immediate Workaround (no deploy needed)
Set
DD_TRACE_STATS_COMPUTATION_ENABLED=falsein Lambda environment variables.