-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pg: cannot instrument an ESM-imported pg #1693
Labels
bug
Something isn't working
has:reproducer
This bug/feature has a minimal reproduction provided
pkg:instrumentation-pg
priority:p1
Bugs which cause problems in end-user applications such as crashes, data inconsistencies
Comments
Is there anyone who can take a look at this? |
1 task
I can reproduce with this:
A starter fix is: diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts
index f47b1e81..b42da2b8 100644
--- a/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts
+++ b/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts
@@ -66,7 +66,12 @@ export class PgInstrumentation extends InstrumentationBase {
const modulePG = new InstrumentationNodeModuleDefinition<typeof pgTypes>(
'pg',
['8.*'],
- moduleExports => {
+ // XXX type any, do better
+ (module: any) => {
+ const moduleExports: typeof pgTypes =
+ module[Symbol.toStringTag] === 'Module'
+ ? module.default // ESM
+ : module; // CommonJS
if (isWrapped(moduleExports.Client.prototype.query)) {
this._unwrap(moduleExports.Client.prototype, 'query');
}
@@ -87,9 +92,14 @@ export class PgInstrumentation extends InstrumentationBase {
this._getClientConnectPatch() as any
);
- return moduleExports;
+ return module;
},
- moduleExports => {
+ // XXX type any, do better
+ (module: any) => {
+ const moduleExports: typeof pgTypes =
+ module[Symbol.toStringTag] === 'Module'
+ ? module.default // ESM
+ : module; // CommonJS
if (isWrapped(moduleExports.Client.prototype.query)) {
this._unwrap(moduleExports.Client.prototype, 'query');
} I have some TypeScript fighting to work through and, as with #1694, a decision to make on testing. I'll start a PR. |
2 tasks
pichlermarc
added
priority:p1
Bugs which cause problems in end-user applications such as crashes, data inconsistencies
pkg:instrumentation-pg
has:reproducer
This bug/feature has a minimal reproduction provided
labels
Oct 11, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Something isn't working
has:reproducer
This bug/feature has a minimal reproduction provided
pkg:instrumentation-pg
priority:p1
Bugs which cause problems in end-user applications such as crashes, data inconsistencies
What version of OpenTelemetry are you using?
honeycomb/opentelemetry-node 0.5.0
opentelemetry/auto-instrumentations-node 0.39.2
opentelemetry/api 1.4.1
What version of Node are you using?
16.20.2
What did you do?
Started telemetry with auto-instrumentation enabled
Started node with
What did you expect to see?
Node start and instrumentation produced for pg module
What did you see instead?
Additional context
It appears that the pg instrumentation may need to be updated to properly handle ESM imports. Seems possibly similar to #1692
The text was updated successfully, but these errors were encountered: