Skip to content

WORK-IN-PROGRESS feat(lambda): migrate datadog-lambda-js into dd-trace-js as a plugin#7778

Draft
joeyzhao2018 wants to merge 3 commits intomasterfrom
joey/migrate-datadog-lambda
Draft

WORK-IN-PROGRESS feat(lambda): migrate datadog-lambda-js into dd-trace-js as a plugin#7778
joeyzhao2018 wants to merge 3 commits intomasterfrom
joey/migrate-datadog-lambda

Conversation

@joeyzhao2018
Copy link
Contributor

Consolidates all server-side Lambda tracing functionality from the standalone datadog-lambda-js repo into dd-trace-js as a proper plugin, eliminating the double-wrapping problem and using AWS_LAMBDA_EXEC_WRAPPER for clean auto-instrumentation.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

What does this PR do?

Motivation

Additional Notes

Consolidates all server-side Lambda tracing functionality from the
standalone datadog-lambda-js repo into dd-trace-js as a proper plugin,
eliminating the double-wrapping problem and using AWS_LAMBDA_EXEC_WRAPPER
for clean auto-instrumentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@joeyzhao2018 joeyzhao2018 requested review from a team as code owners March 13, 2026 16:30
@joeyzhao2018 joeyzhao2018 requested review from khanayan123 and lym953 and removed request for a team March 13, 2026 16:30
@datadog-prod-us1-3

This comment has been minimized.

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.27%. Comparing base (dd965cf) to head (6b3b006).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7778      +/-   ##
==========================================
- Coverage   80.42%   76.27%   -4.16%     
==========================================
  Files         741      647      -94     
  Lines       32177    27386    -4791     
==========================================
- Hits        25878    20888    -4990     
- Misses       6299     6498     +199     
Flag Coverage Δ
aiguard-macos 39.08% <ø> (+0.14%) ⬆️
aiguard-ubuntu 39.19% <ø> (+0.14%) ⬆️
aiguard-windows 38.92% <ø> (+0.14%) ⬆️
apm-capabilities-tracing-macos ?
apm-capabilities-tracing-ubuntu ?
apm-capabilities-tracing-windows ?
apm-integrations-child-process 38.38% <ø> (-0.12%) ⬇️
apm-integrations-couchbase-18 37.30% <ø> (-0.12%) ⬇️
apm-integrations-couchbase-eol 37.76% <ø> (-0.12%) ⬇️
apm-integrations-oracledb 37.60% <ø> (-0.11%) ⬇️
appsec-express 55.18% <ø> (-0.09%) ⬇️
appsec-fastify 51.53% <ø> (-0.09%) ⬇️
appsec-graphql 51.73% <ø> (-0.08%) ⬇️
appsec-kafka 44.25% <ø> (-0.10%) ⬇️
appsec-ldapjs 43.91% <ø> (-0.10%) ⬇️
appsec-lodash 43.57% <ø> (-0.10%) ⬇️
appsec-macos 58.20% <ø> (-0.08%) ⬇️
appsec-mongodb-core 48.69% <ø> (-0.10%) ⬇️
appsec-mongoose 49.35% <ø> (-0.09%) ⬇️
appsec-mysql 50.79% <ø> (-0.09%) ⬇️
appsec-node-serialize 43.09% <ø> (-0.10%) ⬇️
appsec-passport 47.53% <ø> (-0.10%) ⬇️
appsec-postgres 50.51% <ø> (-0.09%) ⬇️
appsec-sourcing 42.50% <ø> (-0.10%) ⬇️
appsec-template 43.26% <ø> (-0.10%) ⬇️
appsec-ubuntu 58.27% <ø> (-0.08%) ⬇️
appsec-windows 58.06% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-bluebird 32.25% <ø> (-0.12%) ⬇️
instrumentations-instrumentation-body-parser 40.40% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-child_process 37.69% <ø> (-0.12%) ⬇️
instrumentations-instrumentation-cookie-parser 34.23% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-express 34.55% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.36% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-express-session 40.03% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-fs 31.87% <ø> (-0.12%) ⬇️
instrumentations-instrumentation-generic-pool 29.68% <ø> (-0.02%) ⬇️
instrumentations-instrumentation-http 39.67% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-knex 32.25% <ø> (-0.12%) ⬇️
instrumentations-instrumentation-mongoose 33.38% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-multer 40.15% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-mysql2 38.15% <ø> (-0.12%) ⬇️
instrumentations-instrumentation-passport 43.96% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-passport-http 43.62% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-passport-local 44.16% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-pg 37.59% <ø> (-0.12%) ⬇️
instrumentations-instrumentation-promise 32.18% <ø> (-0.12%) ⬇️
instrumentations-instrumentation-promise-js 32.19% <ø> (-0.12%) ⬇️
instrumentations-instrumentation-q 32.23% <ø> (-0.12%) ⬇️
instrumentations-instrumentation-url 32.15% <ø> (-0.12%) ⬇️
instrumentations-instrumentation-when 32.20% <ø> (-0.12%) ⬇️
llmobs-ai 42.14% <ø> (-0.11%) ⬇️
llmobs-anthropic 40.13% <ø> (-0.11%) ⬇️
llmobs-bedrock 39.12% <ø> (-0.10%) ⬇️
llmobs-google-genai 39.67% <ø> (-0.10%) ⬇️
llmobs-langchain 39.92% <ø> (-0.09%) ⬇️
llmobs-openai 43.86% <ø> (-0.10%) ⬇️
llmobs-vertex-ai 39.93% <ø> (-0.11%) ⬇️
platform-core 31.47% <ø> (-0.07%) ⬇️
platform-esbuild 34.42% <ø> (-0.07%) ⬇️
platform-instrumentations-misc 48.35% <ø> (-0.05%) ⬇️
platform-shimmer 37.56% <ø> (-0.07%) ⬇️
platform-unit-guardrails 32.89% <ø> (-0.07%) ⬇️
plugins-azure-durable-functions 25.62% <ø> (?)
plugins-azure-event-hubs 25.79% <ø> (-0.05%) ⬇️
plugins-azure-service-bus 25.15% <ø> (-0.04%) ⬇️
plugins-bullmq 44.06% <ø> (-0.12%) ⬇️
plugins-cassandra 37.64% <ø> (-0.11%) ⬇️
plugins-cookie 26.84% <ø> (-0.05%) ⬇️
plugins-cookie-parser 26.63% <ø> (-0.05%) ⬇️
plugins-crypto 26.73% <ø> (-0.06%) ⬇️
plugins-dd-trace-api 38.21% <ø> (-0.12%) ⬇️
plugins-express-mongo-sanitize 26.78% <ø> (-0.05%) ⬇️
plugins-express-session 26.59% <ø> (-0.05%) ⬇️
plugins-fastify 42.11% <ø> (-0.11%) ⬇️
plugins-fetch 38.20% <ø> (-0.11%) ⬇️
plugins-fs 38.48% <ø> (-0.12%) ⬇️
plugins-generic-pool 25.83% <ø> (-0.05%) ⬇️
plugins-google-cloud-pubsub 45.32% <ø> (-0.11%) ⬇️
plugins-grpc 40.79% <ø> (-0.11%) ⬇️
plugins-handlebars 26.82% <ø> (-0.05%) ⬇️
plugins-hapi 40.03% <ø> (-0.11%) ⬇️
plugins-hono 40.29% <ø> (-0.11%) ⬇️
plugins-ioredis 38.29% <ø> (-0.12%) ⬇️
plugins-knex 26.46% <ø> (-0.04%) ⬇️
plugins-ldapjs 24.32% <ø> (-0.04%) ⬇️
plugins-light-my-request 26.19% <ø> (-0.05%) ⬇️
plugins-limitd-client 32.53% <ø> (-0.12%) ⬇️
plugins-lodash 25.92% <ø> (-0.05%) ⬇️
plugins-mariadb 39.33% <ø> (-0.12%) ⬇️
plugins-memcached 38.01% <ø> (-0.12%) ⬇️
plugins-microgateway-core 39.10% <ø> (-0.11%) ⬇️
plugins-moleculer 40.38% <ø> (-0.11%) ⬇️
plugins-mongodb 39.03% <ø> (-0.11%) ⬇️
plugins-mongodb-core 38.86% <ø> (-0.12%) ⬇️
plugins-mongoose 38.72% <ø> (-0.11%) ⬇️
plugins-multer 26.59% <ø> (-0.05%) ⬇️
plugins-mysql 39.02% <ø> (-0.12%) ⬇️
plugins-mysql2 39.12% <ø> (-0.12%) ⬇️
plugins-node-serialize 26.89% <ø> (-0.05%) ⬇️
plugins-opensearch 37.47% <ø> (-0.11%) ⬇️
plugins-passport-http 26.64% <ø> (-0.05%) ⬇️
plugins-postgres 35.52% <ø> (-0.10%) ⬇️
plugins-process 26.73% <ø> (-0.06%) ⬇️
plugins-pug 26.84% <ø> (-0.05%) ⬇️
plugins-redis 38.75% <ø> (-0.12%) ⬇️
plugins-router 42.84% <ø> (-0.11%) ⬇️
plugins-sequelize 25.43% <ø> (-0.05%) ⬇️
plugins-test-and-upstream-amqp10 38.36% <ø> (-0.12%) ⬇️
plugins-test-and-upstream-amqplib 43.74% <ø> (-0.12%) ⬇️
plugins-test-and-upstream-apollo 38.99% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-avsc 38.54% <ø> (-0.12%) ⬇️
plugins-test-and-upstream-bunyan 33.79% <ø> (-0.12%) ⬇️
plugins-test-and-upstream-connect 40.69% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-graphql 39.98% <ø> (-0.12%) ⬇️
plugins-test-and-upstream-koa 40.28% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-protobufjs 38.76% <ø> (-0.12%) ⬇️
plugins-test-and-upstream-rhea 43.95% <ø> (-0.09%) ⬇️
plugins-undici 38.98% <ø> (-0.11%) ⬇️
plugins-url 26.73% <ø> (-0.06%) ⬇️
plugins-valkey 37.95% <ø> (-0.12%) ⬇️
plugins-vm 26.73% <ø> (-0.06%) ⬇️
plugins-winston 33.98% <ø> (-0.11%) ⬇️
plugins-ws 41.74% <ø> (-0.11%) ⬇️
profiling-macos 39.79% <ø> (-0.12%) ⬇️
profiling-ubuntu 39.91% <ø> (-0.12%) ⬇️
profiling-windows 41.10% <ø> (-0.50%) ⬇️
serverless-azure-functions-client 25.50% <ø> (-0.04%) ⬇️
serverless-azure-functions-eventhubs 25.50% <ø> (-0.04%) ⬇️
serverless-azure-functions-servicebus 25.50% <ø> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joeyzhao2018 joeyzhao2018 reopened this Mar 13, 2026
@joeyzhao2018 joeyzhao2018 changed the title feat(lambda): migrate datadog-lambda-js into dd-trace-js as a plugin WORK-IN-PROGRESS feat(lambda): migrate datadog-lambda-js into dd-trace-js as a plugin Mar 13, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 13, 2026

Overall package size

Self size: 5.06 MB
Deduped: 5.91 MB
No deduping: 5.91 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.0 | 81.15 kB | 815.98 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

The Agent Extension layer ships its own /opt/datadog_wrapper, which
overwrites the dd-trace layer's wrapper. Move the wrapper into
/opt/nodejs/dd_trace_wrapper to avoid the collision. Also fix handler
instrumentation to use Module._load instead of addHook, since the
Lambda runtime loads handlers by file path (not npm package name).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pr-commenter
Copy link

pr-commenter bot commented Mar 13, 2026

Benchmarks

Benchmark execution time: 2026-03-14 04:12:50

Comparing candidate commit b6ed1e9 in PR branch joey/migrate-datadog-lambda with baseline commit dd965cf in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 228 metrics, 32 unstable metrics.

@BridgeAR BridgeAR marked this pull request as draft March 13, 2026 22:24
…ixes

The nodejs22.x Lambda runtime uses ESM import() to load handlers, which
bypasses Module._load patching entirely. Switch to overriding _HANDLER in
the wrapper script to point to a handler-wrapper module that loads the
original handler, wraps it with tracing channel events, and re-exports it.

Also fixes several issues found during real-world Lambda deployment:
- Register lambda plugin explicitly in PluginManager (no addHook flow)
- Add DD_TRACE_LAMBDA_ENABLED to supported-configurations.json
- Add lambda schema to v0/v1 serverless service naming definitions
- Don't propagate X-Ray Sampled=0 as sampling priority -1 unless
  DD_MERGE_XRAY_TRACES is enabled (was dropping all traces)
- Wrap asyncStart in try/finally to guarantee span.finish()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant