Skip to content

add rewriter support for generator functions#7472

Merged
rochdev merged 10 commits intomasterfrom
rewriter-generators
Feb 25, 2026
Merged

add rewriter support for generator functions#7472
rochdev merged 10 commits intomasterfrom
rewriter-generators

Conversation

@rochdev
Copy link
Copy Markdown
Member

@rochdev rochdev commented Feb 10, 2026

What does this PR do?

Add rewriter support for generator functions.

Motivation

They can't be patched using the current available functionality.

Additional Notes

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 10, 2026

Overall package size

Self size: 4.69 MB
Deduped: 5.54 MB
No deduping: 5.54 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.6 | 81.92 kB | 816.75 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 Feb 10, 2026

Codecov Report

❌ Patch coverage is 97.82609% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.33%. Comparing base (510563d) to head (7db1273).
⚠️ Report is 59 commits behind head on master.

Files with missing lines Patch % Lines
...nstrumentations/src/helpers/rewriter/transforms.js 97.05% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7472      +/-   ##
==========================================
- Coverage   80.34%   80.33%   -0.01%     
==========================================
  Files         731      734       +3     
  Lines       31093    31583     +490     
==========================================
+ Hits        24981    25373     +392     
- Misses       6112     6210      +98     
Flag Coverage Δ
aiguard-macos 38.77% <8.69%> (-0.41%) ⬇️
aiguard-ubuntu 38.89% <8.69%> (-0.33%) ⬇️
aiguard-windows 38.64% <8.69%> (-0.44%) ⬇️
apm-capabilities-tracing-macos 48.55% <8.69%> (-0.30%) ⬇️
apm-capabilities-tracing-ubuntu 48.59% <8.69%> (-0.27%) ⬇️
apm-capabilities-tracing-windows 48.28% <8.69%> (-0.30%) ⬇️
apm-integrations-child-process 38.35% <8.69%> (-0.33%) ⬇️
apm-integrations-couchbase-18 37.27% <8.69%> (-0.16%) ⬇️
apm-integrations-couchbase-eol 37.60% <8.69%> (-0.47%) ⬇️
apm-integrations-oracledb 37.59% <8.69%> (-0.51%) ⬇️
appsec-express 55.38% <8.69%> (-0.07%) ⬇️
appsec-fastify 51.70% <8.69%> (-0.37%) ⬇️
appsec-graphql 51.89% <8.69%> (-0.50%) ⬇️
appsec-kafka 44.34% <8.69%> (-0.38%) ⬇️
appsec-ldapjs 43.95% <8.69%> (-0.45%) ⬇️
appsec-lodash 43.64% <8.69%> (-0.44%) ⬇️
appsec-macos 58.46% <8.69%> (-0.09%) ⬇️
appsec-mongodb-core 48.70% <8.69%> (-0.58%) ⬇️
appsec-mongoose 49.49% <8.69%> (-0.47%) ⬇️
appsec-mysql 50.88% <8.69%> (-0.46%) ⬇️
appsec-node-serialize 43.15% <8.69%> (-0.44%) ⬇️
appsec-passport 47.62% <8.69%> (-0.57%) ⬇️
appsec-postgres 50.61% <8.69%> (-0.52%) ⬇️
appsec-sourcing 42.50% <8.69%> (-0.43%) ⬇️
appsec-template 43.32% <8.69%> (-0.44%) ⬇️
appsec-ubuntu 58.54% <8.69%> (-0.04%) ⬇️
appsec-windows 58.33% <8.69%> (-0.11%) ⬇️
instrumentations-instrumentation-bluebird 32.07% <8.69%> (-0.29%) ⬇️
instrumentations-instrumentation-body-parser 40.36% <8.69%> (-0.47%) ⬇️
instrumentations-instrumentation-child_process 37.67% <8.69%> (-0.32%) ⬇️
instrumentations-instrumentation-cookie-parser 34.11% <8.69%> (-0.50%) ⬇️
instrumentations-instrumentation-express 34.45% <8.69%> (-0.50%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.25% <8.69%> (-0.50%) ⬇️
instrumentations-instrumentation-express-session 39.99% <8.69%> (-0.52%) ⬇️
instrumentations-instrumentation-fs 31.67% <8.69%> (-0.28%) ⬇️
instrumentations-instrumentation-generic-pool 29.47% <8.69%> (-0.34%) ⬇️
instrumentations-instrumentation-http 39.70% <8.69%> (-0.02%) ⬇️
instrumentations-instrumentation-knex 32.07% <8.69%> (-0.29%) ⬇️
instrumentations-instrumentation-mongoose 33.25% <8.69%> (-0.47%) ⬇️
instrumentations-instrumentation-multer 40.11% <8.69%> (-0.46%) ⬇️
instrumentations-instrumentation-mysql2 38.14% <8.69%> (-0.23%) ⬇️
instrumentations-instrumentation-passport 43.94% <8.69%> (+3.07%) ⬆️
instrumentations-instrumentation-passport-http 43.61% <8.69%> (+2.77%) ⬆️
instrumentations-instrumentation-passport-local 44.16% <8.69%> (+3.32%) ⬆️
instrumentations-instrumentation-pg 37.56% <8.69%> (-0.33%) ⬇️
instrumentations-instrumentation-promise 32.00% <8.69%> (-0.29%) ⬇️
instrumentations-instrumentation-promise-js 32.00% <8.69%> (-0.29%) ⬇️
instrumentations-instrumentation-q 32.05% <8.69%> (-0.29%) ⬇️
instrumentations-instrumentation-url 31.97% <8.69%> (-0.29%) ⬇️
instrumentations-instrumentation-when 32.02% <8.69%> (-0.29%) ⬇️
llmobs-ai 41.18% <8.69%> (-0.47%) ⬇️
llmobs-anthropic 40.18% <8.69%> (-0.55%) ⬇️
llmobs-bedrock 39.13% <8.69%> (-0.47%) ⬇️
llmobs-google-genai 39.71% <8.69%> (-0.50%) ⬇️
llmobs-langchain 39.40% <43.47%> (-0.34%) ⬇️
llmobs-openai 43.99% <8.69%> (-0.59%) ⬇️
llmobs-vertex-ai 39.97% <8.69%> (-0.54%) ⬇️
platform-core 29.71% <ø> (+1.62%) ⬆️
platform-esbuild 32.89% <ø> (+1.40%) ⬆️
platform-instrumentations-misc 42.88% <97.82%> (+3.26%) ⬆️
platform-shimmer 36.14% <ø> (+1.31%) ⬆️
platform-unit-guardrails 31.27% <ø> (+0.89%) ⬆️
plugins-azure-event-hubs 24.02% <ø> (+1.38%) ⬆️
plugins-azure-service-bus 23.42% <ø> (+1.34%) ⬆️
plugins-bullmq 43.60% <39.13%> (-0.26%) ⬇️
plugins-cassandra 37.63% <8.69%> (-0.51%) ⬇️
plugins-cookie 25.08% <ø> (+1.38%) ⬆️
plugins-cookie-parser 24.87% <ø> (+1.37%) ⬆️
plugins-crypto 24.72% <ø> (+1.83%) ⬆️
plugins-dd-trace-api 38.21% <8.69%> (-0.32%) ⬇️
plugins-express-mongo-sanitize 25.04% <ø> (+1.36%) ⬆️
plugins-express-session 24.83% <ø> (+1.37%) ⬆️
plugins-fastify 42.12% <8.69%> (-0.51%) ⬇️
plugins-fetch 38.18% <8.69%> (-0.52%) ⬇️
plugins-fs 38.45% <8.69%> (-0.33%) ⬇️
plugins-generic-pool 24.06% <ø> (+1.38%) ⬆️
plugins-google-cloud-pubsub 45.31% <8.69%> (-0.52%) ⬇️
plugins-grpc 40.82% <8.69%> (-0.57%) ⬇️
plugins-handlebars 25.08% <ø> (+1.36%) ⬆️
plugins-hapi 39.99% <8.69%> (-0.69%) ⬇️
plugins-hono 40.26% <8.69%> (-0.47%) ⬇️
plugins-ioredis 38.26% <8.69%> (-0.32%) ⬇️
plugins-knex 24.80% <ø> (+1.29%) ⬆️
plugins-ldapjs 22.61% <ø> (+1.33%) ⬆️
plugins-light-my-request 24.48% <ø> (+1.33%) ⬆️
plugins-limitd-client 32.36% <8.69%> (-0.29%) ⬇️
plugins-lodash 24.13% <ø> (+1.39%) ⬆️
plugins-mariadb 39.34% <8.69%> (-0.37%) ⬇️
plugins-memcached 37.99% <8.69%> (-0.32%) ⬇️
plugins-microgateway-core 39.02% <8.69%> (-0.52%) ⬇️
plugins-moleculer 40.38% <8.69%> (-0.56%) ⬇️
plugins-mongodb 39.05% <8.69%> (-0.60%) ⬇️
plugins-mongodb-core 38.88% <8.69%> (-0.35%) ⬇️
plugins-mongoose 38.71% <8.69%> (-0.57%) ⬇️
plugins-multer 24.83% <ø> (+1.37%) ⬆️
plugins-mysql 39.01% <8.69%> (-0.35%) ⬇️
plugins-mysql2 39.12% <8.69%> (-0.29%) ⬇️
plugins-node-serialize 25.12% <ø> (+1.38%) ⬆️
plugins-opensearch 37.46% <8.69%> (-0.52%) ⬇️
plugins-passport-http 24.91% <ø> (+1.35%) ⬆️
plugins-postgres 35.57% <8.69%> (-0.35%) ⬇️
plugins-process 24.72% <ø> (+1.83%) ⬆️
plugins-pug 25.08% <ø> (+1.38%) ⬆️
plugins-redis 38.74% <8.69%> (-0.32%) ⬇️
plugins-router 43.01% <8.69%> (-0.33%) ⬇️
plugins-sequelize 23.66% <ø> (+1.38%) ⬆️
plugins-test-and-upstream-amqp10 38.33% <8.69%> (-0.32%) ⬇️
plugins-test-and-upstream-amqplib 43.68% <8.69%> (-0.18%) ⬇️
plugins-test-and-upstream-apollo 38.89% <8.69%> (-0.52%) ⬇️
plugins-test-and-upstream-avsc 38.55% <8.69%> (-0.37%) ⬇️
plugins-test-and-upstream-bunyan 33.66% <8.69%> (-0.31%) ⬇️
plugins-test-and-upstream-connect 40.66% <8.69%> (-0.49%) ⬇️
plugins-test-and-upstream-graphql 40.00% <8.69%> (-0.33%) ⬇️
plugins-test-and-upstream-koa 40.24% <8.69%> (-0.49%) ⬇️
plugins-test-and-upstream-protobufjs 38.78% <8.69%> (-0.38%) ⬇️
plugins-test-and-upstream-rhea 43.96% <8.69%> (-0.33%) ⬇️
plugins-undici 38.97% <8.69%> (-0.52%) ⬇️
plugins-url 24.72% <ø> (+1.83%) ⬆️
plugins-valkey 37.92% <8.69%> (-0.31%) ⬇️
plugins-vm 24.72% <ø> (+1.83%) ⬆️
plugins-winston 33.86% <8.69%> (-0.51%) ⬇️
plugins-ws 41.76% <8.69%> (-0.55%) ⬇️
profiling-macos 39.69% <8.69%> (-0.48%) ⬇️
profiling-ubuntu 39.82% <8.69%> (-0.40%) ⬇️
profiling-windows 41.05% <8.69%> (-0.52%) ⬇️
serverless-azure-functions-client 23.75% <ø> (+1.37%) ⬆️
serverless-azure-functions-eventhubs 23.75% <ø> (+1.37%) ⬆️
serverless-azure-functions-servicebus 23.75% <ø> (+1.37%) ⬆️

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.

@rochdev rochdev marked this pull request as ready for review February 10, 2026 04:12
@rochdev rochdev requested review from a team as code owners February 10, 2026 04:12
Copy link
Copy Markdown
Collaborator

@bengl bengl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start. Can't wait to see the corresponding PR against Orchestrion-JS!

self: this,
moduleVersion: "1.0.0"
};
const gen = ${channelVariable}.traceSync(__apm$traced, ctx);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to suggest that this should be ${traceMethod}, but then I remembered that async generators return synchronously, despite being called async. 😆

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I actually did the same thing and wrote it wrong at first lol.


if (callee) {
const expression = parse(`
Reflect.get(Object.getPrototypeOf(this.constructor.prototype), '${method}').call(this)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may as well be consistent and use Reflect.getPrototypeOf here.

Also, can you leave a comment explaining why Reflect.get is necessary?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I see you've added the comment, it it makes sense, but it doesn't explain why Reflect.get in particular is necessary.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't really needed in this case so I just removed it.

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Feb 11, 2026

Benchmarks

Benchmark execution time: 2026-02-20 19:23:53

Comparing candidate commit 7db1273 in PR branch rewriter-generators with baseline commit 510563d in branch master.

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

Copy link
Copy Markdown
Contributor

@wconti27 wconti27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this change @rochdev . This will really help us in instrumenting LLM/AI agent packages! Gonna leave the review up to our local node experts, but just wanted to express how helpful these Orchestrion changes are to us (IDM)!

@rochdev
Copy link
Copy Markdown
Member Author

rochdev commented Feb 18, 2026

@bengl Any other concerns with the PR?

const wrap = it => {
const { next: itNext, return: itReturn, throw: itThrow } = it;

it.next = (...args) => ${traceNext}(itNext, ctx, it, ...args);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I usually prefer iter as an instance of an iterator, but that's not a blocker.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to fix wrapSuper so I'll do this at the same time.

Copy link
Copy Markdown
Member Author

@rochdev rochdev Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed wrapSuper and renamed the variable.

bengl
bengl previously approved these changes Feb 18, 2026
@rochdev rochdev marked this pull request as draft February 18, 2026 19:27
@datadog-datadog-prod-us1-2

This comment has been minimized.

@rochdev rochdev marked this pull request as ready for review February 18, 2026 22:48
Co-authored-by: Crystal Luc-Magloire <[email protected]>
@rochdev rochdev merged commit af50fef into master Feb 25, 2026
792 checks passed
@rochdev rochdev deleted the rewriter-generators branch February 25, 2026 10:21
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.

4 participants