Skip to content

Allow registerOTel to pass different logRecordProcessors #166

@JerryLikeCoding

Description

@JerryLikeCoding

This is the urgent issue for compatibility for the typing.

Issue: Currently the registerOTel() only allow to pass the type LogRecordProcessor. But the opentelemetry library has more specific types (eg. BatchLogRecordProcessor). And it is causing the type checking issues.

Target: We should update the registerOTel and allow it to pass more specific types.

Reproduce: The below is the code:

import {
  BatchLogRecordProcessor,
  LogRecordExporter,
} from '@opentelemetry/sdk-logs';
import { registerOTel } from '@vercel/otel';

const logRecordProcessor = new BatchLogRecordProcessor(
  logExporter as LogRecordExporter
);

registerOTel({
  serviceName, // use your own service name
  traceExporter, // use your own trace exporter
  logRecordProcessor,
});

And then we can see the error:

Type 'BatchLogRecordProcessor' is not assignable to type 'LogRecordProcessor'.
  Types of property 'onEmit' are incompatible.
    Type '(logRecord: LogRecord) => void' is not assignable to type '(logRecord: LogRecord, context?: Context | undefined) => void'.
      Types of parameters 'logRecord' and 'logRecord' are incompatible.
        Type 'import("/Users/jerry.huang/Documents/GitHub/unloan-web/node_modules/.pnpm/@opentelemetry+sdk-logs@0.200.0_@opentelemetry+api@1.8.0/node_modules/@opentelemetry/sdk-logs/build/src/LogRecord").LogRecord' is not assignable to type 'import("/Users/jerry.huang/Documents/GitHub/unloan-web/node_modules/.pnpm/@opentelemetry+sdk-logs@0.50.0_@opentelemetry+api-logs@0.50.0_@opentelemetry+api@1.8.0/node_modules/@opentelemetry/sdk-logs/build/src/LogRecord").LogRecord'.
          Types of property 'attributes' are incompatible.
            Type 'import("/Users/jerry.huang/Documents/GitHub/unloan-web/node_modules/.pnpm/@opentelemetry+api-logs@0.200.0/node_modules/@opentelemetry/api-logs/build/src/types/AnyValue").AnyValueMap' is not assignable to type 'import("/Users/jerry.huang/Documents/GitHub/unloan-web/node_modules/.pnpm/@opentelemetry+api-logs@0.50.0/node_modules/@opentelemetry/api-logs/build/src/types/AnyValue").AnyValueMap'.
              'string' index signatures are incompatible.
                Type 'AnyValue' is not assignable to type 'AnyValue | undefined'.
                  Type 'null' is not assignable to type 'AnyValue | undefined'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions