admin管理员组

文章数量:1122832

I am trying to build a bespoke OTEL package for our internal applications, but run into a weird type mismatch error, that I cannot explain to myself.

export class OtelConfigurator {
    otelEndpoint: string;
    sdkConfiguration: Partial<NodeSDKConfiguration>;
    sdk: NodeSDK | undefined;
    metadata: Metadata;

    constructor({ authHeader, serviceName, serviceVersion, otelCollectorEndpoint, loglevel }: obsProps) {
    // omitted
    }
    
    enableMetrics(additionalConfig?: OTLPGRPCExporterConfigNode) {
        const config: OTLPGRPCExporterConfigNode = {
            url: `${this.otelEndpoint}/v1/metrics`,
            metadata: this.metadata,
            ...additionalConfig,
        };

        const exporter = new OTLPMetricExporter(config);
        this.sdkConfiguration.metricReader = new PeriodicExportingMetricReader({
            exporter,
        });
    }
}

The error happens at the following line:

    this.sdkConfiguration.metricReader = new PeriodicExportingMetricReader({
            exporter,
    });

Type 'PeriodicExportingMetricReader' is not assignable to type 'MetricReader'. Types have separate declarations of a private property '_shutdown'.ts(2322)

Which is weird since the PeriodicExportingMetricReader extends the Metric Reader:

export declare class PeriodicExportingMetricReader extends MetricReader {
  
}

And also the docs demonstrate this usage:

So my best guess is, that I have mismatching versions, but can't find an error there either:

"peerDependencies": {
    "@grpc/grpc-js": "^1.12.2",
    "@opentelemetry/api": "^1.9.0",
    "@opentelemetry/auto-instrumentations-node": "0.53.0",
    "@opentelemetry/exporter-trace-otlp-grpc": "0.53.0",
    "@opentelemetry/exporter-metrics-otlp-grpc": "0.53.0",
    "@opentelemetry/instrumentation-dataloader": "^0.12.0",
    "@opentelemetry/instrumentation-graphql": "^0.43.0",
    "@opentelemetry/instrumentation-grpc": "0.53.0",
    "@opentelemetry/instrumentation-http": "0.53.0",
    "@opentelemetry/instrumentation-ioredis": "^0.43.0",
    "@opentelemetry/instrumentation-net": "^0.39.0",
    "@opentelemetry/instrumentation-pino": "^0.42.0",
    "@opentelemetry/sdk-metrics": "1.28.0",
    "@opentelemetry/sdk-node": "0.53.0",
    "@opentelemetry/sdk-trace-node": "1.26.0",
    "@opentelemetry/semantic-conventions": "1.26"
},

What am I doing wrong here?

本文标签: