Skip to content

[Bug]: Bug in OpenAI OTel Instrumentation? #119

Description

Component

distro

Description

Error:
Image

Distro version: 1.0.1 (built from sources)
Exporter version: 1.0.0-beta.39

App:


import { useMicrosoftOpenTelemetry } from '@microsoft/opentelemetry';
// Instrumentation must occur before other imports
useMicrosoftOpenTelemetry({
    azureMonitor: {
        azureMonitorExporterOptions: {
            connectionString: process.env.APPLICATIONINSIGHTS_CONNECTION_STRING,
        },
        enableLiveMetrics: false,
    },
    instrumentationOptions: {
        bunyan: { enabled: true },
        winston: { enabled: true },
    },
});

import { OpenAIInstrumentation } from '@opentelemetry/instrumentation-openai';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
registerInstrumentations({
    instrumentations: [new OpenAIInstrumentation()],
});

import express from 'express';
import { OpenAI } from 'openai';
import winston from 'winston';
import bunyan from 'bunyan';

const winstonLogger = winston.createLogger({
    level: 'info',
    format: winston.format.combine(winston.format.timestamp(), winston.format.json()),
    transports: [new winston.transports.Console()]
});

const bunyanLogger = bunyan.createLogger({ name: 'express-openai-otel-test-app' });

process.on('uncaughtException', (err) => {
    winstonLogger.error('Uncaught exception in test app', { message: err.message, stack: err.stack });
});

process.on('unhandledRejection', (reason) => {
    winstonLogger.error('Unhandled rejection in test app', { reason: reason instanceof Error ? reason.message : reason });
});

const app = express();
const port = Number(process.env.PORT || process.env.NODE_TEST_APP_PORT || 5000);

const client = new OpenAI({
    apiKey: process.env.OPENAI_API_KEY,
    baseURL: 'https://naarkalg-sw.cognitiveservices.azure.com/openai/v1/'
});

app.get('/', (_req, res) => {
    winstonLogger.info('Received request for root endpoint');
    res.status(200).send('Hello from the Express OpenAI OTel instrumentation test app');
});

app.get('/dependencies', async (_req, res, next) => {
    winstonLogger.info('Received request for dependencies endpoint');
    try {
        const completion = await client.chat.completions.create({
            model: 'gpt-4o-mini',
            messages: [
                { role: 'system', content: 'You are a helpful assistant. Respond in one sentence.' },
                { role: 'user', content: 'What is the capital of France?' },
            ],
            max_tokens: 50,
        });
        const answer = completion.choices[0].message.content;
        winstonLogger.info('OpenAI dependency request completed', { answer });
        res.status(200).send(`OpenAI dependency request completed: ${answer}`);
    } catch (err) {
        winstonLogger.error('OpenAI dependency request failed', { message: err.message });
        next(err);
    }
});

app.get('/exceptions', (_req, res) => {
    winstonLogger.info('Received request for exceptions endpoint');
    res.status(500).send('Triggering exception');
    setImmediate(() => {
        throw new Error('Intentional test error from Express OpenAI OTel app');
    });
});

app.get('/logs', (_req, res) => {
    console.log('Console log message from Express OpenAI OTel test app');
    console.warn('Console warn message from Express OpenAI OTel test app');
    console.info('Console info message from Express OpenAI OTel test app');

    winstonLogger.info('Winston info message from Express OpenAI OTel test app');
    winstonLogger.warn('Winston warn message from Express OpenAI OTel test app');
    winstonLogger.error('Winston error message from Express OpenAI OTel test app');

    bunyanLogger.info('Bunyan info message from Express OpenAI OTel test app');
    bunyanLogger.warn('Bunyan warn message from Express OpenAI OTel test app');
    bunyanLogger.error('Bunyan error message from Express OpenAI OTel test app');

    res.status(200).send('Logs generated with console, winston, and bunyan');
});

app.get('/logs/complex', (_req, res) => {
    const complexObject = {
        userId: 'e2e-test-user-42',
        action: 'complex-object-serialization-test',
        metadata: {
            nested: {
                level: 3,
                tags: ['alpha', 'beta', 'gamma'],
                config: { enabled: true, retryCount: 5, timeout: 30000 }
            },
            timestamp: '2026-01-15T12:00:00.000Z',
            scores: [99.5, 87.3, 100.0]
        },
        items: [
            { id: 1, name: 'item-one', active: true },
            { id: 2, name: 'item-two', active: false }
        ],
        nullField: null,
        emptyString: ''
    };

    console.log('ComplexObjectTest-Console', complexObject);
    winstonLogger.info('ComplexObjectTest-Winston', { complexPayload: complexObject });
    bunyanLogger.info({ complexPayload: complexObject }, 'ComplexObjectTest-Bunyan');

    res.status(200).json({ message: 'Complex object logs generated', objectKeys: Object.keys(complexObject) });
});

app.use((err, _req, res, next) => {
    winstonLogger.error('Express error handler caught exception', { message: err.message, stack: err.stack });
    if (res.headersSent) {
        return next(err);
    }
    res.status(500).send('Intentional test error');
});

app.listen(port, () => {
    winstonLogger.info(`Express OpenAI OTel test app listening on port ${port}`);
});

Expected Behavior

Should run without type error

Steps to Reproduce

  1. clone distro
  2. pnpm run build at root
  3. create tarball with pnpm pack
  4. pnpm install
  5. pnpm run build
  6. node dist/app.js

Environment

Windows
Distro version: 1.0.1 (built from sources)
Exporter version: 1.0.0-beta.39

Additional Context

No response

Activity

  1. jeremydvoss commented on May 6, 2026

    @jeremydvoss
    MemberAuthor

    Some more details about the different errors I get

    Scenario 1: simple pnpm run build

    repro:
    pnpm run build
    output:

    'rimraf' is not recognized as an internal or external command,
    operable program or batch file.
     ELIFECYCLE  Command failed with exit code 1.
    

    Scenario 2: Install peers before build

    repro:

    pnpm install --config.auto-install-peers=true
    pnpm run build
    

    output:

    src/genai/instrumentations/openai/openAIAgentsTraceProcessor.ts:20:8 - error TS2307: Cannot find module '@openai/agents-core' or its corresponding type declarations.
    20 } from "@openai/agents-core";
              ~~~~~~~~~~~~~~~~~~~~~
    src/genai/instrumentations/openai/utils.ts:6:51 - error TS2307: Cannot find module '@openai/agents-core' or its corresponding type declarations.
    6 import type { Span as AgentsSpan, SpanData } from "@openai/agents-core";
                                                        ~~~~~~~~~~~~~~~~~~~~~
    Found 2 errors in 2 files.
    Errors  Files
         1  src/genai/instrumentations/openai/openAIAgentsTraceProcessor.ts:20
         1  src/genai/instrumentations/openai/utils.ts:6
     ELIFECYCLE  Command failed with exit code 2.
    

    Scenario 3: Install openai agents-core first

    Repro:

    pnpm install --config.auto-install-peers=true
    pnpm add -D @openai/agents-core
    Pnpm run build
    

    Output:

      Types of property 'onTraceStart' are incompatible.
        Type '(_trace: Trace) => Promise<void>' is not comparable to type '(trace: Trace) => Promise<void>'.
          Types of parameters '_trace' and 'trace' are incompatible.
            Type 'import("C:/Users/jeremyvoss/workplace/opentelemetry-distro-javascript/node_modules/.pnpm/@openai+agents-core@0.8.5_@_a7e194fe3552aa075c4e455ccd0d128d/node_modules/@openai/agents-core/dist/tracing/traces").Trace' is not comparable to type 'import("C:/Users/jeremyvoss/workplace/opentelemetry-distro-javascript/node_modules/.pnpm/@openai+agents-core@0.9.1_@_a54df637cafab6a0b1a986d0f8ba7605/node_modules/@openai/agents-core/dist/tracing/traces").Trace'.
              Property '#private' in type 'Trace' refers to a different member that cannot be accessed from within type 'Trace'.
    
    95       setTraceProcessors([this.processor as TracingProcessor]);
    
  2. added a commit that references this issue on May 6, 2026
    106c73f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingdistroRelated to the OpenTelemetry distro

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions