Skip to content

feat(mariadb): migrate instrumentation from shimmer to orchestrion#7925

Draft
crysmags wants to merge 4 commits intomasterfrom
crysmags/mariadb-migrate2
Draft

feat(mariadb): migrate instrumentation from shimmer to orchestrion#7925
crysmags wants to merge 4 commits intomasterfrom
crysmags/mariadb-migrate2

Conversation

@crysmags
Copy link
Copy Markdown
Collaborator

@crysmags crysmags commented Apr 4, 2026

What does this PR do?

Migrates the mariadb plugin from shimmer to orchestrion AST rewriter instrumentation.

Motivation

mariadb v3.5.1 moved to pure ESM. While esmFirst: true + import-in-the-middle handles ESM live bindings, it can't solve the super() problem: shimmer instruments instances by wrapping the constructor, but moving a constructor body that calls super() into a nested function is a SyntaxError. The AST rewriter transforms source before execution and can inject instrumentation around super() without relocating it.

For v2, query methods (_queryPromise, _queryCallback, etc.) are arrow functions assigned to this inside constructors — shimmer can't reach per-instance properties set this way. The rewriter's thisPropertyName support targets these this.foo = ... assignments directly.

Key changes

  • packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ — add mariadb orchestrion hook definitions for v2 and v3+: createConnection, createPool, Pool.getConnection, and all query/execute methods across callback and promise APIs
  • packages/datadog-plugin-mariadb/ — new plugin split into connection.js (context/conf tracking) and query.js (span creation), replacing the monolithic MySQLPlugin extension
  • Clear async context during createPool/createConnection so pool-internal TCP connections don't become children of user spans
  • Restore parent span context in callback/promise completions via bindAsyncStart
  • Tag peer.service in asyncEnd (orchestrion does not fire the finish channel)
  • Support PrepareResultPacket.execute for prepared statement tracing

Additional Notes

  • noCallbackFallback (fires channels synchronously when no callback is provided) required rewriter changes — entries needing this are marked with TODOs pending upstream support
  • v2 thisPropertyName hooks use object_name: this / property_name per nodejs/orchestrion-js#58

@crysmags crysmags changed the title feat(mariadb): migrate instrumentation from shimmer to orchestrion re… feat(mariadb): migrate instrumentation from shimmer to orchestrion Apr 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

Overall package size

Self size: 5.49 MB
Deduped: 6.34 MB
No deduping: 6.34 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.1 | 82.56 kB | 817.39 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

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

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 45.60000% with 68 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.07%. Comparing base (efc9681) to head (b0f2a1e).

Files with missing lines Patch % Lines
packages/datadog-plugin-mariadb/src/connection.js 24.59% 46 Missing ⚠️
packages/datadog-plugin-mariadb/src/query.js 61.11% 21 Missing ⚠️
packages/datadog-instrumentations/src/mariadb.js 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7925      +/-   ##
==========================================
- Coverage   74.25%   74.07%   -0.19%     
==========================================
  Files         769      771       +2     
  Lines       36068    36095      +27     
==========================================
- Hits        26783    26737      -46     
- Misses       9285     9358      +73     
Flag Coverage Δ
aiguard-macos 39.44% <ø> (-0.10%) ⬇️
aiguard-ubuntu 39.56% <ø> (-0.10%) ⬇️
aiguard-windows 39.23% <ø> (-0.10%) ⬇️
apm-capabilities-tracing-macos 49.54% <45.08%> (-0.03%) ⬇️
apm-capabilities-tracing-ubuntu 49.45% <45.08%> (-0.03%) ⬇️
apm-capabilities-tracing-windows 49.31% <45.08%> (+0.01%) ⬆️
apm-integrations-child-process 38.74% <ø> (-0.10%) ⬇️
apm-integrations-couchbase-18 37.52% <ø> (-0.10%) ⬇️
apm-integrations-couchbase-eol 38.01% <ø> (-0.13%) ⬇️
apm-integrations-oracledb 37.87% <ø> (-0.10%) ⬇️
appsec-express 55.38% <ø> (-0.07%) ⬇️
appsec-fastify 51.71% <ø> (-0.07%) ⬇️
appsec-graphql 51.87% <ø> (-0.07%) ⬇️
appsec-kafka 44.49% <ø> (-0.08%) ⬇️
appsec-ldapjs 44.11% <ø> (-0.08%) ⬇️
appsec-lodash 43.71% <ø> (-0.08%) ⬇️
appsec-macos 58.09% <ø> (-0.07%) ⬇️
appsec-mongodb-core 48.90% <ø> (-0.07%) ⬇️
appsec-mongoose 49.55% <ø> (-0.08%) ⬇️
appsec-mysql 51.08% <ø> (-0.07%) ⬇️
appsec-node-serialize 43.29% <ø> (-0.08%) ⬇️
appsec-passport 47.76% <ø> (-0.09%) ⬇️
appsec-postgres 50.70% <ø> (-0.07%) ⬇️
appsec-sourcing 42.54% <ø> (-0.08%) ⬇️
appsec-stripe 44.73% <ø> (-0.09%) ⬇️
appsec-template 43.45% <ø> (-0.08%) ⬇️
appsec-ubuntu 58.18% <ø> (-0.07%) ⬇️
appsec-windows 57.91% <ø> (-0.05%) ⬇️
instrumentations-instrumentation-bluebird 32.33% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-body-parser 40.63% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-child_process 38.07% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-cookie-parser 34.36% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express 34.67% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.49% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express-session 40.27% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-fs 32.01% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-generic-pool 29.41% <ø> (ø)
instrumentations-instrumentation-http 39.99% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-knex 32.39% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-mongoose 33.51% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-multer 40.38% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-mysql2 38.40% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-passport 44.16% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-passport-http 43.84% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-passport-local 44.37% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-pg 37.84% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-promise 32.26% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-promise-js 32.26% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-q 32.31% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-url 32.23% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-when 32.28% <ø> (-0.11%) ⬇️
llmobs-ai 41.37% <ø> (-0.10%) ⬇️
llmobs-anthropic 40.84% <ø> (-0.09%) ⬇️
llmobs-bedrock 39.32% <ø> (-0.08%) ⬇️
llmobs-google-genai 40.00% <ø> (+0.04%) ⬆️
llmobs-langchain 39.45% <ø> (+0.03%) ⬆️
llmobs-openai 44.12% <ø> (-0.09%) ⬇️
llmobs-vertex-ai 40.13% <ø> (-0.09%) ⬇️
platform-core 31.47% <ø> (ø)
platform-esbuild 34.42% <ø> (ø)
platform-instrumentations-misc 34.11% <ø> (ø)
platform-shimmer 37.56% <ø> (ø)
platform-unit-guardrails 32.89% <ø> (ø)
platform-webpack 19.87% <66.66%> (+0.01%) ⬆️
plugins-azure-durable-functions 25.74% <ø> (ø)
plugins-azure-event-hubs 25.90% <ø> (ø)
plugins-azure-service-bus 25.26% <ø> (ø)
plugins-bullmq 43.61% <ø> (-0.09%) ⬇️
plugins-cassandra 37.88% <ø> (-0.23%) ⬇️
plugins-cookie 26.96% <ø> (ø)
plugins-cookie-parser 26.75% <ø> (ø)
plugins-crypto 26.73% <ø> (ø)
plugins-dd-trace-api 38.43% <ø> (-0.10%) ⬇️
plugins-express-mongo-sanitize 26.89% <ø> (ø)
plugins-express-session 26.70% <ø> (ø)
plugins-fastify 42.36% <ø> (-0.09%) ⬇️
plugins-fetch 38.51% <ø> (-0.12%) ⬇️
plugins-fs 38.75% <ø> (-0.10%) ⬇️
plugins-generic-pool 25.94% <ø> (ø)
plugins-google-cloud-pubsub 45.68% <ø> (-0.09%) ⬇️
plugins-grpc 41.01% <ø> (-0.09%) ⬇️
plugins-handlebars 26.94% <ø> (ø)
plugins-hapi 40.27% <ø> (-0.10%) ⬇️
plugins-hono 40.61% <ø> (-0.24%) ⬇️
plugins-ioredis 38.60% <ø> (-0.10%) ⬇️
plugins-knex 26.57% <ø> (ø)
plugins-langgraph 37.99% <ø> (-0.10%) ⬇️
plugins-ldapjs 24.43% <ø> (ø)
plugins-light-my-request 26.30% <ø> (ø)
plugins-limitd-client 32.61% <ø> (-0.10%) ⬇️
plugins-lodash 26.03% <ø> (ø)
plugins-mariadb 27.74% <66.66%> (-11.97%) ⬇️
plugins-memcached 38.34% <ø> (-0.10%) ⬇️
plugins-microgateway-core 39.41% <ø> (-0.02%) ⬇️
plugins-moleculer 40.63% <ø> (-0.09%) ⬇️
plugins-mongodb 39.27% <ø> (-0.10%) ⬇️
plugins-mongodb-core 39.12% <ø> (-0.10%) ⬇️
plugins-mongoose 39.01% <ø> (ø)
plugins-multer 26.70% <ø> (ø)
plugins-mysql 39.45% <ø> (-0.10%) ⬇️
plugins-mysql2 39.41% <ø> (-0.10%) ⬇️
plugins-node-serialize 27.00% <ø> (ø)
plugins-opensearch 37.74% <ø> (-0.10%) ⬇️
plugins-passport-http 26.76% <ø> (ø)
plugins-postgres 35.54% <ø> (-0.09%) ⬇️
plugins-process 26.73% <ø> (ø)
plugins-pug 26.96% <ø> (ø)
plugins-redis 39.04% <ø> (-0.10%) ⬇️
plugins-router 43.22% <ø> (-0.24%) ⬇️
plugins-sequelize 25.55% <ø> (ø)
plugins-test-and-upstream-amqp10 38.62% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-amqplib 44.37% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-apollo 39.24% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-avsc 38.69% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-bunyan 33.94% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-connect 40.93% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-graphql 40.28% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-koa 40.52% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-protobufjs 38.92% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-rhea 44.37% <ø> (-0.10%) ⬇️
plugins-undici 39.36% <ø> (-0.09%) ⬇️
plugins-url 26.73% <ø> (ø)
plugins-valkey 38.31% <ø> (-0.10%) ⬇️
plugins-vm 26.73% <ø> (ø)
plugins-winston 34.26% <ø> (-0.10%) ⬇️
plugins-ws 42.12% <ø> (-0.10%) ⬇️
profiling-macos 40.65% <ø> (-0.10%) ⬇️
profiling-ubuntu 40.78% <ø> (-0.10%) ⬇️
profiling-windows 42.30% <ø> (-0.10%) ⬇️
serverless-azure-functions-client 25.62% <ø> (ø)
serverless-azure-functions-eventhubs 25.62% <ø> (ø)
serverless-azure-functions-servicebus 25.62% <ø> (ø)

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.

@datadog-prod-us1-4
Copy link
Copy Markdown

datadog-prod-us1-4 bot commented Apr 7, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 46.83%
Overall Coverage: 68.53% (-0.16%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ac1a089 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Apr 7, 2026

Benchmarks

Benchmark execution time: 2026-04-07 21:09:24

Comparing candidate commit ac1a089 in PR branch crysmags/mariadb-migrate2 with baseline commit efc9681 in branch master.

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

crysmags and others added 2 commits April 7, 2026 16:07
…writer

Replaces the legacy shimmer-based mariadb plugin with an orchestrion
AST-rewriter approach, enabling proper async context propagation and
eliminating the need for manual module patching.

Key changes:
- Add orchestrion instrumentation entries for mariadb (v2 and v3+)
  covering createConnection, createPool, Pool.getConnection, and all
  query/execute methods across callback and promise APIs
- Add thisPropertyName query type to the rewriter for arrow function
  and regular function instance properties set in constructors
- Add noCallbackFallback option to wrapCallback for fire-and-forget queries
- Fix ArrowFunctionExpression → FunctionExpression conversion in traceFunction
  so arguments and this bindings work correctly
- New plugin split into connection.js (context/conf tracking) and query.js
  (span creation), replacing the monolithic MySQLPlugin extension
- Properly clear async context during createPool/createConnection so
  pool-internal TCP connections don't leak into user traces
- Restore parent span context in callback/promise completions via bindAsyncStart
- Tag peer.service in asyncEnd (orchestrion never fires the finish channel)
- Support PrepareResultPacket.execute for prepared statement tracing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…trion-config

Replaces custom rewriter instrumentations/mariadb.js with entries in
orchestrion-config/index.js using the standard YAML format. thisPropertyName
is expressed as object_name/property_name per nodejs/orchestrion-js#58.
noCallbackFallback entries are marked with TODO comments pending
nodejs/orchestrion-js support.

Reverts rewriter changes to transformer.js, transforms.js,
instrumentations/index.js, and associated tests.
@crysmags crysmags force-pushed the crysmags/mariadb-migrate2 branch from 0cc0256 to 7dfab81 Compare April 7, 2026 20:07
crysmags and others added 2 commits April 7, 2026 16:35
orchestrion-config/index.js is consumed by the AppSec IAST wasm rewriter,
not the APM orchestrion system. The mariadb entries broke AppSec tests
because the wasm rewriter does not support kind: callback.
Adds mariadb hook definitions to the rewriter instrumentations for v2
and v3+, covering createConnection, createPool, Pool.getConnection, and
all query/execute methods across callback and promise APIs.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant