-
Notifications
You must be signed in to change notification settings - Fork 236
Description
Bug description
@posthog/ai declares @opentelemetry/exporter-trace-otlp-http as an optional peer dependency in peerDependenciesMeta, but the main entry point unconditionally requires it:
CJS (dist/index.cjs, line 6):
var exporterTraceOtlpHttp = require('@opentelemetry/exporter-trace-otlp-http');ESM (dist/index.mjs, line 5):
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';This causes a MODULE_NOT_FOUND crash at import time for any consumer that doesn't install the OpenTelemetry package — even if they only use withTracing or LangChainCallbackHandler, which have nothing to do with OpenTelemetry.
Steps to reproduce
- Install
@posthog/aiwithout@opentelemetry/exporter-trace-otlp-http - Import anything from the package:
import { withTracing } from '@posthog/ai';
- Application crashes:
Error: Cannot find module '@opentelemetry/exporter-trace-otlp-http'
Root cause
PostHogTraceExporter (which extends OTLPTraceExporter) is bundled into the main dist/index.cjs and dist/index.mjs entry points. Because it extends the OTel base class, the import must resolve at module load time — making the "optional" declaration in peerDependenciesMeta ineffective at runtime.
The sub-entry point @posthog/ai/otel already exists and correctly isolates this dependency. The issue is that the main entry point re-exports it as well.
Suggested fix
Any of these would work:
- Remove
PostHogTraceExporterfrom the main entry point — keep it only in@posthog/ai/otel(least invasive) - Lazy-load the dependency inside
PostHogTraceExporter's constructor via dynamicrequire() - Wrap the top-level require in try/catch and throw a descriptive error only when
PostHogTraceExporteris actually instantiated
Environment
@posthog/ai: 7.12.0- Node.js: v22.22.0
- Package manager: Yarn 1.22.22