Skip to content

ioredis: cannot instrument an ESM-imported ioredis #1692

@synchrone

Description

@synchrone

What version of OpenTelemetry are you using?

        "@opentelemetry/auto-instrumentations-node": "0.39.2",
        "@opentelemetry/sdk-node": "0.43.0",
        "@opentelemetry/instrumentation-ioredis": "0.35.1",
        "@opentelemetry/instrumentation": "0.41.2",

What version of Node are you using?

v18.13.0 (18.13.0+dfsg1-1)

What did you do?

create a file test.mjs

import {IORedisInstrumentation} from "@opentelemetry/instrumentation-ioredis";
new IORedisInstrumentation()
import 'ioredis'
setTimeout(() => 0, 1000)

then run:
node --experimental-loader=@opentelemetry/instrumentation/hook.mjs test.mjs

What did you expect to see?

a successfully instrumented ioredis

What did you see instead?

Uncaught TypeError: Cannot read properties of undefined (reading 'sendCommand') instrumentation.js:131

Additional context

when InstrumentationNodeModuleDefinition patch callback runs, it expects require-in-the-middle to provide moduleExports, which is a normal class.
However, in ESM-mode, import-in-the-middle actually provides a Proxy as moduleExports variable, which means moduleExports.prototype is undefined, resulting in an error thrown.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpkg:instrumentation-ioredispriority: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