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

getNodeAutoInstrumentations type error when initializing tracing in TypeScript #2964

Closed
cartermp opened this issue May 12, 2022 · 14 comments
Closed

Comments

@cartermp
Copy link
Contributor

Consider the following express app with tracing initialized from docs/readme:

index.ts:

import express from 'express';
 
const app: express.Application = express();
 
const port: number = 3000;

app.get('/', (_req, _res) => {
    _res.send("TypeScript With Express");
});

app.listen(port, () => {
    console.log(`TypeScript with Express
         http://localhost:${port}/`);
});

tracing.ts:

'use strict';

import { NodeSDK } from '@opentelemetry/sdk-node';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-base';

const traceExporter = new ConsoleSpanExporter();

const sdk = new NodeSDK({
  traceExporter,
  instrumentations: [getNodeAutoInstrumentations()]
});

sdk.start()

And requiring tracing.ts in the npm manifest: "start": "nodemon -r ./tracing.ts index.ts",

a type error is present:

Type 'Instrumentation[]' is not assignable to type 'InstrumentationOption'.
  Type 'Instrumentation[]' is not assignable to type '(typeof InstrumentationBase)[]'.
    Property 'prototype' is missing in type 'Instrumentation' but required in type 'typeof InstrumentationBase'

At face value, type types appear as though they would be compatible. If I change the getNodeAutoInstrumentations() line to cast to any, then everything works as expected.

If I remove the array brackets around and change it to instrumentations: getNodeAutoAutoInstrumentations(), I get a much gnarlier type error:

gnarlier type error
Type 'Instrumentation[]' is not assignable to type 'InstrumentationOption[]'.
  Type 'Instrumentation' is not assignable to type 'InstrumentationOption'.
    Type 'import("/Users/pcarter/scratch/otel-ts/node_modules/@opentelemetry/instrumentation/build/src/types").Instrumentation' is not assignable to type 'import("/Users/pcarter/scratch/otel-ts/node_modules/@opentelemetry/sdk-node/node_modules/@opentelemetry/instrumentation/build/src/types").Instrumentation'.
      Types of property 'setMeterProvider' are incompatible.
        Type '(meterProvider: import("/Users/pcarter/scratch/otel-ts/node_modules/@opentelemetry/api-metrics/build/src/types/MeterProvider").MeterProvider) => void' is not assignable to type '(meterProvider: import("/Users/pcarter/scratch/otel-ts/node_modules/@opentelemetry/sdk-metrics-base/node_modules/@opentelemetry/api-metrics/build/src/types/MeterProvider").MeterProvider) => void'.
          Types of parameters 'meterProvider' and 'meterProvider' are incompatible.
            Type 'import("/Users/pcarter/scratch/otel-ts/node_modules/@opentelemetry/sdk-metrics-base/node_modules/@opentelemetry/api-metrics/build/src/types/MeterProvider").MeterProvider' is not assignable to type 'import("/Users/pcarter/scratch/otel-ts/node_modules/@opentelemetry/api-metrics/build/src/types/MeterProvider").MeterProvider'.
              The types of 'getMeter(...).createObservableGauge' are incompatible between these types.
                Type '(name: string, callback: ObservableCallback, options?: MetricOptions | undefined) => void' is not assignable to type '(name: string, options?: MetricOptions | undefined, callback?: ((observableResult: ObservableResult) => void) | undefined) => ObservableBase'.
                  Types of parameters 'callback' and 'options' are incompatible.
                    Type 'MetricOptions | undefined' is not assignable to type 'ObservableCallback'.
                      Type 'undefined' is not assignable to type 'ObservableCallback'.

I'm not familiar with the otel-js codebase and its recent changes, so I wouldn't know where to look from here.

What version of OpenTelemetry are you using?

"@opentelemetry/auto-instrumentations-node": "^0.28.0"
"@opentelemetry/exporter-trace-otlp-proto": "^0.28.0"
"@opentelemetry/sdk-node": "^0.28.0"

What version of Node are you using?

v16.13.0

@cartermp cartermp added the bug Something isn't working label May 12, 2022
@Flarna
Copy link
Member

Flarna commented May 12, 2022

I'm quite sure this is because no release from @opentelemetry/auto-instrumentations-node was made after the 1.2.0/0.28.0 release from core SDK components.
As a result you get a mix of newer and older components.

If you want to use instrumentations form contrib it's most likely needed to stick on SDK 1.0.0/0.27.0 until a new release is done here.

@cartermp
Copy link
Contributor Author

Thanks @Flarna, that would make sense. I have an older app where this doesn't reproduce.

Are there circumstances where it's not a good idea to do instrumentation package releases after a core package? I'm not familiar with the release strategy here.

(also, would this issue be better in the contrib repo? Apologies if this is in the wrong place)

@Flarna
Copy link
Member

Flarna commented May 13, 2022

The work to get contrib modules released is ongoing. There are quite some changes needed to update dependencies and keep all the various npm modules happy. An the number of people working on this is not that high.

(also, would this issue be better in the contrib repo? Apologies if this is in the wrong place)

Yes and contrib repo would be better in this case but as the people involved are mostly the same it's not that cirical.

@cartermp
Copy link
Contributor Author

Thanks for the explanation @Flarna, I appreciate it! I'll let some folks who ran into this know for now, and keep my eyes peeled for the next release.

@mbrevda
Copy link

mbrevda commented May 17, 2022

I'm quite sure this is because no release from @opentelemetry/auto-instrumentations-node was made after the 1.2.0/0.28.0 release from core SDK components. As a result you get a mix of newer and older components.

If you want to use instrumentations form contrib it's most likely needed to stick on SDK 1.0.0/0.27.0 until a new release is done here.

For those of us that are new, is there a getting started guide that currently works?

@cartermp
Copy link
Contributor Author

The getting started guide as-written should work with the older package versions.

@Flarna
Copy link
Member

Flarna commented May 17, 2022

OTel contrib pacakges were released yesterday but something went wrong and upload to NPM is missing, see open-telemetry/opentelemetry-js-contrib#947

@sstone1
Copy link

sstone1 commented May 30, 2022

This is now happening again with the latest 0.29.0 release:

src/opentelemetry.ts:59:9 - error TS2322: Type 'Instrumentation[]' is not assignable to type 'InstrumentationOption'.

  Type 'Instrumentation[]' is not assignable to type '(typeof InstrumentationBase)[]'.

    Property 'prototype' is missing in type 'Instrumentation' but required in type 'typeof InstrumentationBase'.



 59         getNodeAutoInstrumentations({

            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 60           '@opentelemetry/instrumentation-http': {

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

... 

 62           },

    ~~~~~~~~~~~~

 63         }),

    ~~~~~~~~~~



Found 1 error(s).

@Flarna
Copy link
Member

Flarna commented May 30, 2022

Yes, unfortunately.
Work to update contrib components is ongoing, see open-telemetry/opentelemetry-js-contrib#1042

I fear such compatibility problems will persist as long metrics and instrumentations are in experimental phase.

@AlexRex
Copy link

AlexRex commented Jun 8, 2022

It is working for me with these versions, in case it helps anyone:

    "@opentelemetry/auto-instrumentations-node": "0.28.0",
    "@opentelemetry/sdk-node": "0.27.0",

@dyladan
Copy link
Member

dyladan commented Jun 28, 2022

I believe it should be working with:

"@opentelemetry/auto-instrumentations-node": "^0.31.0"
"@opentelemetry/exporter-trace-otlp-proto": "^0.29.2"
"@opentelemetry/sdk-node": "^0.29.2"

@dyladan
Copy link
Member

dyladan commented Jun 29, 2022

@cartermp can you confirm the above versions work for you?

@dyladan dyladan removed the bug Something isn't working label Jun 29, 2022
@stefee
Copy link

stefee commented Jun 29, 2022

Works for me.

@cartermp
Copy link
Contributor Author

Confirmed it works! Thanks for getting updates plumbed through 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants