Skip to content
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

InstrumentationBase#init triggers cascading errors #4712

Closed
DeJayDev opened this issue May 15, 2024 · 1 comment · May be fixed by #4833
Closed

InstrumentationBase#init triggers cascading errors #4712

DeJayDev opened this issue May 15, 2024 · 1 comment · May be fixed by #4833
Labels
bug Something isn't working triage

Comments

@DeJayDev
Copy link

DeJayDev commented May 15, 2024

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[];
      ~~~~
@DeJayDev DeJayDev added bug Something isn't working triage labels May 15, 2024
@pichlermarc
Copy link
Member

    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

@pichlermarc pichlermarc closed this as not planned Won't fix, can't repro, duplicate, stale May 24, 2024
alecmev added a commit to alecmev/opentelemetry-js that referenced this issue Jun 30, 2024
TypeScript emits InstrumentationNodeModuleDefinition with " | undefined"
for some reason, making it incompatible with
InstrumentationModuleDefinition under exactOptionalPropertyTypes.
@alecmev alecmev mentioned this issue Jun 30, 2024
7 tasks
alecmev added a commit to alecmev/opentelemetry-js that referenced this issue Jul 5, 2024
TypeScript emits InstrumentationNodeModuleDefinition with " | undefined"
for some reason, making it incompatible with
InstrumentationModuleDefinition under exactOptionalPropertyTypes.
alecmev added a commit to alecmev/opentelemetry-js that referenced this issue Jul 16, 2024
TypeScript emits InstrumentationNodeModuleDefinition with " | undefined"
for some reason, making it incompatible with
InstrumentationModuleDefinition under exactOptionalPropertyTypes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants