Skip to content

pg: cannot instrument an ESM-imported pg #1693

@mjsalinger

Description

@mjsalinger

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

node --experimental-loader=@opentelemetry/instrumentation/hook.mjs ./src/index.js",

What did you expect to see?

Node start and instrumentation produced for pg module

What did you see instead?

/Users/mjsalinger/Development/platform/api/backend-api-service/node_modules/@opentelemetry/instrumentation-pg/build/src/instrumentation.js:33
            if ((0, instrumentation_1.isWrapped)(moduleExports.Client.prototype.query)) {
                                                                      ^

TypeError: Cannot read properties of undefined (reading 'prototype')
    at InstrumentationNodeModuleDefinition.patch (/Users/mjsalinger/Development/platform/api/backend-api-service/node_modules/@opentelemetry/instrumentation-pg/build/src/instrumentation.js:33:71)
    at PgInstrumentation._onRequire (/Users/mjsalinger/Development/platform/api/backend-api-service/node_modules/@opentelemetry/instrumentation/build/src/platform/node/instrumentation.js:153:39)
    at hookFn (/Users/mjsalinger/Development/platform/api/backend-api-service/node_modules/@opentelemetry/instrumentation/build/src/platform/node/instrumentation.js:194:29)
    at callHookFn (/Users/mjsalinger/Development/platform/api/backend-api-service/node_modules/import-in-the-middle/index.js:28:22)
    at Hook._iitmHook (/Users/mjsalinger/Development/platform/api/backend-api-service/node_modules/import-in-the-middle/index.js:76:11)
    at /Users/mjsalinger/Development/platform/api/backend-api-service/node_modules/import-in-the-middle/lib/register.js:29:31
    at Array.forEach (<anonymous>)
    at register (/Users/mjsalinger/Development/platform/api/backend-api-service/node_modules/import-in-the-middle/lib/register.js:29:15)
    at file:///Users/mjsalinger/Development/platform/api/backend-api-service/node_modules/pg/lib/index.js?iitm=true:13:1
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)

Additional context

It appears that the pg instrumentation may need to be updated to properly handle ESM imports. Seems possibly similar to #1692

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghas:reproducerThis bug/feature has a minimal reproduction providedpkg:instrumentation-pgpriority:p1Bugs which cause problems in end-user applications such as crashes, data inconsistencies

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions