⚗️ Add instrumentConstructor utility#4714
Conversation
Bundles Sizes Evolution
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c445e3c783
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 25ddf41 | Docs | Datadog PR Page | Give us feedback! |
c445e3c to
e2bdea2
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e2bdea2f62
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0b52da5151
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0f0b7a0fda
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
0f0b7a0 to
751858d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 751858d195
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 201cc19f39
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
201cc19 to
8d89c48
Compare
| export function instrumentConstructor<CONTAINER extends { [key: string]: any }, CONSTRUCTOR extends keyof CONTAINER>( | ||
| container: CONTAINER, |
There was a problem hiding this comment.
💬 suggestion: is there a difference between CONTAINER and TARGET? if not, let's use the same term
There was a problem hiding this comment.
It's semantics.
With instrumentMethod the target will also be the this value of instrumentation / original, so this is TARGET, I can wrap my head around this one.
With instrumentConstructor, in the normal usage (when it's called with new), the this value refers to the instance being constructed, "target" feels weird in this case, since we're really interested in the (global) object holding the reference to the function we're instrumenting.
Wdyt?
There was a problem hiding this comment.
Could it make sense to use CONTAINER for both instrumentMethod and instrumentConstructor?
Since the type parameter describes the object holding the reference and the this value is already surfaced through target in InstrumentedMethodCall for callers who need it.
There was a problem hiding this comment.
I would leave it as is, it makes sense to have targetPrototype / TARGET for instrumentMethod and container / CONTAINER for instrumentConstructor.
I'll wait for a third pair of eyes to come by.
…d method after stop
8d89c48 to
a191d86
Compare

Motivation
In order to instrument WebSocket connections, we need to wrap the
WebSocketconstructor, so far theinstrumentMethodonly supports instrumenting regular methods. This PR adds another utilityinstrumentConstructorsupporting the instrumentation of constructor functions.Changes
instrumentConstructorutility that supports instrumenting constructor functionsinstrumentMethodand newinstrumentConstructorutilsinstrumentConstructorTest instructions
yarn test:unit --spec packages/core/src/tools/instrumentMethod.spec.tsChecklist