open-telemetry / opentelemetry-js

OpenTelemetry JavaScript Client

Home Page:https://opentelemetry.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

InstrumentationBase#init triggers cascading errors

DeJayDev opened this issue · comments

What happened?

Steps to Reproduce

  1. Install any OTel Instrumentation and the OTel API from this package
  2. Attempt a TypeScript build.

Expected Result

The app builds

Actual Result

The app triggers a build error for every individual instrumentation installed.

Additional Details

In this example, the following instrumentations are installed through sentry@1.8.0:

amqplib
aws
bunyan
cassandra
connect
cucumber
dataloader
dns
express
fastify
fs
generic
graphql
grpc
hapi
http
ioredis
knex
koa
lru
memcached
mongodb
mysql2
mysql
nestjs
net
pg
pino
redis
redis
restify
router
socket
tedious
winston

This was reproduced with pnpm, npm and bun.
For readability, the provided log comes from npm.

I can only reproduce this using tsc. The provided setup code does not provide any issues when ran with tsx and the Buntime (bun index.ts). I assume this is because tsx and the Buntime do the equiviliant of tsc's skipLibCheck.

OpenTelemetry Setup Code

import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { ConsoleMetricExporter, PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
import { NodeSDK } from "@opentelemetry/sdk-node";
import { ConsoleSpanExporter } from "@opentelemetry/sdk-trace-node";
import * as Sentry from "@sentry/node";

const sentry = 	Sentry.init({
    tracesSampleRate: 1,
    dsn: process.env.SENTRY_DSN ?? "- )",
});

const otel = new NodeSDK({
    traceExporter: new ConsoleSpanExporter(),
    metricReader: new PeriodicExportingMetricReader({
        exporter: new ConsoleMetricExporter()
    }),
    instrumentations: [getNodeAutoInstrumentations()]
})

otel.start();

console.log('hey')

package.json

{
  "dependencies": {
    "@opentelemetry/api": "^1.8.0",
    "@opentelemetry/auto-instrumentations-node": "^0.46.1",
    "@opentelemetry/sdk-metrics": "^1.24.1",
    "@opentelemetry/sdk-node": "^0.51.1",
    "@opentelemetry/sdk-trace-node": "^1.24.1",
    "@sentry/node": "^8.0.0",
    "@sentry/types": "^8.0.0",
    "typescript": "^5.4.5"
  },
  "packageManager": "pnpm@9.1.1+sha256.9551e803dcb7a1839fdf5416153a844060c7bce013218ce823410532504ac10b"
}

Relevant log output

node_modules/@opentelemetry/instrumentation-amqplib/build/src/amqplib.d.ts:7:15 - error TS2416: Property 'init' in type 'AmqplibInstrumentation' is not assignable to the same property in base type 'InstrumentationBase'.
  Type '() => InstrumentationNodeModuleDefinition' is not assignable to type '() => void | InstrumentationModuleDefinition | InstrumentationModuleDefinition[]'.
    Type 'InstrumentationNodeModuleDefinition' is not assignable to type 'void | InstrumentationModuleDefinition | InstrumentationModuleDefinition[]'.
      Type 'InstrumentationNodeModuleDefinition' is not assignable to type 'InstrumentationModuleDefinition' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
        Types of property 'patch' are incompatible.
          Type '((exports: any, moduleVersion?: string | undefined) => any) | undefined' is not assignable to type '(moduleExports: any, moduleVersion?: string | undefined) => any'.
            Type 'undefined' is not assignable to type '(moduleExports: any, moduleVersion?: string | undefined) => any'.

7     protected init(): InstrumentationNodeModuleDefinition;
                ~~~~

node_modules/@opentelemetry/instrumentation-aws-lambda/build/src/instrumentation.d.ts:11:5 - error TS2416: Property 'init' in type 'AwsLambdaInstrumentation' is not assignable to the same property in base type 'InstrumentationBase'.
  Type '() => InstrumentationNodeModuleDefinition[]' is not assignable to type '() => void | InstrumentationModuleDefinition | InstrumentationModuleDefinition[]'.
    Type 'InstrumentationNodeModuleDefinition[]' is not assignable to type 'void | InstrumentationModuleDefinition | InstrumentationModuleDefinition[]'.
      Type 'InstrumentationNodeModuleDefinition[]' is not assignable to type 'InstrumentationModuleDefinition[]'.
        Type 'InstrumentationNodeModuleDefinition' is not assignable to type 'InstrumentationModuleDefinition' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.

11     init(): InstrumentationNodeModuleDefinition[];
       ~~~~

node_modules/@opentelemetry/instrumentation-bunyan/build/src/instrumentation.d.ts:5:15 - error TS2416: Property 'init' in type 'BunyanInstrumentation' is not assignable to the same property in base type 'InstrumentationBase'.
  Type '() => InstrumentationNodeModuleDefinition[]' is not assignable to type '() => void | InstrumentationModuleDefinition | InstrumentationModuleDefinition[]'.
    Type 'InstrumentationNodeModuleDefinition[]' is not assignable to type 'void | InstrumentationModuleDefinition | InstrumentationModuleDefinition[]'.

5     protected init(): InstrumentationNodeModuleDefinition[];
                ~~~~

node_modules/@opentelemetry/instrumentation-cassandra-driver/build/src/instrumentation.d.ts:6:15 - error TS2416: Property 'init' in type 'CassandraDriverInstrumentation' is not assignable to the same property in base type 'InstrumentationBase'.
  Type '() => InstrumentationNodeModuleDefinition' is not assignable to type '() => void | InstrumentationModuleDefinition | InstrumentationModuleDefinition[]'.
    Type 'InstrumentationNodeModuleDefinition' is not assignable to type 'void | InstrumentationModuleDefinition | InstrumentationModuleDefinition[]'.

6     protected init(): InstrumentationNodeModuleDefinition;
                ~~~~

node_modules/@opentelemetry/instrumentation-connect/build/src/instrumentation.d.ts:9:5 - error TS2416: Property 'init' in type 'ConnectInstrumentation' is not assignable to the same property in base type 'InstrumentationBase'.
  Type '() => InstrumentationNodeModuleDefinition[]' is not assignable to type '() => void | InstrumentationModuleDefinition | InstrumentationModuleDefinition[]'.
    Type 'InstrumentationNodeModuleDefinition[]' is not assignable to type 'void | InstrumentationModuleDefinition | InstrumentationModuleDefinition[]'.

9     init(): InstrumentationNodeModuleDefinition[];
      ~~~~

node_modules/@opentelemetry/instrumentation-cucumber/build/src/instrumentation.d.ts:6:5 - error TS2416: Property 'init' in type 'CucumberInstrumentation' is not assignable to the same property in base type 'InstrumentationBase'.
  Type '() => InstrumentationNodeModuleDefinition[]' is not assignable to type '() => void | InstrumentationModuleDefinition | InstrumentationModuleDefinition[]'.
    Type 'InstrumentationNodeModuleDefinition[]' is not assignable to type 'void | InstrumentationModuleDefinition | InstrumentationModuleDefinition[]'.

6     init(): InstrumentationNodeModuleDefinition[];
      ~~~~
    Type 'InstrumentationNodeModuleDefinition' is not assignable to type 'InstrumentationModuleDefinition' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.

Closing this as it looks like a duplicate of #3713