@posthog/ai 8.20.2 → 8.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/dist/adk/index.cjs +101 -22
- package/dist/adk/index.cjs.map +1 -1
- package/dist/adk/index.d.ts +7 -0
- package/dist/adk/index.mjs +102 -23
- package/dist/adk/index.mjs.map +1 -1
- package/dist/anthropic/index.cjs +92 -9
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.d.ts +7 -0
- package/dist/anthropic/index.mjs +93 -10
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/claude-agent-sdk/index.cjs +107 -21
- package/dist/claude-agent-sdk/index.cjs.map +1 -1
- package/dist/claude-agent-sdk/index.d.ts +6 -0
- package/dist/claude-agent-sdk/index.mjs +108 -22
- package/dist/claude-agent-sdk/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +92 -9
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.d.ts +7 -0
- package/dist/gemini/index.mjs +92 -9
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/genkit/index.cjs +114 -29
- package/dist/genkit/index.cjs.map +1 -1
- package/dist/genkit/index.d.ts +7 -0
- package/dist/genkit/index.mjs +114 -29
- package/dist/genkit/index.mjs.map +1 -1
- package/dist/index.cjs +90 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.mjs +91 -8
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +75 -7
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.d.ts +7 -0
- package/dist/langchain/index.mjs +75 -7
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/langchain/middleware/index.cjs +75 -7
- package/dist/langchain/middleware/index.cjs.map +1 -1
- package/dist/langchain/middleware/index.d.ts +6 -0
- package/dist/langchain/middleware/index.mjs +75 -7
- package/dist/langchain/middleware/index.mjs.map +1 -1
- package/dist/openai/index.cjs +91 -8
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.d.ts +7 -0
- package/dist/openai/index.mjs +92 -9
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openai-agents/index.cjs +115 -46
- package/dist/openai-agents/index.cjs.map +1 -1
- package/dist/openai-agents/index.d.ts +7 -0
- package/dist/openai-agents/index.mjs +115 -46
- package/dist/openai-agents/index.mjs.map +1 -1
- package/dist/otel/index.browser.cjs.map +1 -1
- package/dist/otel/index.browser.mjs.map +1 -1
- package/dist/otel/index.cjs.map +1 -1
- package/dist/otel/index.d.ts +3 -3
- package/dist/otel/index.mjs.map +1 -1
- package/dist/vercel/index.cjs +90 -7
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.d.ts +6 -0
- package/dist/vercel/index.mjs +91 -8
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/otel/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["redactJson","DEFAULT_OTEL_HOST","normalizeToken","normalizeHost"],"sources":["../../src/sanitization/base64_recognizer.ts","../../src/sanitization/media_type_context.ts","../../src/sanitization/binary_content_redactor.ts","../../src/otel/spans.ts","../../src/typeGuards.ts","../../src/mcpCredentials.ts","../../src/otel/toolDefinitions.ts","../../src/otel/redact.ts","../../src/otel/privacy.ts","../../src/gatewayWarning.ts","../../src/otel/exporter.ts","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/core/2.2.0/b871f22d07b51323f729d44d521414927172cbc0ddfdf1942304eca90488e96b/node_modules/@opentelemetry/core/build/esm/trace/suppress-tracing.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/core/2.2.0/b871f22d07b51323f729d44d521414927172cbc0ddfdf1942304eca90488e96b/node_modules/@opentelemetry/core/build/esm/common/logging-error-handler.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/core/2.2.0/b871f22d07b51323f729d44d521414927172cbc0ddfdf1942304eca90488e96b/node_modules/@opentelemetry/core/build/esm/common/global-error-handler.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/core/2.2.0/b871f22d07b51323f729d44d521414927172cbc0ddfdf1942304eca90488e96b/node_modules/@opentelemetry/core/build/esm/platform/node/environment.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/core/2.2.0/b871f22d07b51323f729d44d521414927172cbc0ddfdf1942304eca90488e96b/node_modules/@opentelemetry/core/build/esm/ExportResult.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/core/2.2.0/b871f22d07b51323f729d44d521414927172cbc0ddfdf1942304eca90488e96b/node_modules/@opentelemetry/core/build/esm/utils/promise.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/core/2.2.0/b871f22d07b51323f729d44d521414927172cbc0ddfdf1942304eca90488e96b/node_modules/@opentelemetry/core/build/esm/utils/callback.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/sdk-trace-base/2.2.0/fa825708a19b4d5944c83585f1de1744c29637446df5cfc986c5a1263b781148/node_modules/@opentelemetry/sdk-trace-base/build/esm/export/BatchSpanProcessorBase.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/sdk-trace-base/2.2.0/fa825708a19b4d5944c83585f1de1744c29637446df5cfc986c5a1263b781148/node_modules/@opentelemetry/sdk-trace-base/build/esm/platform/node/export/BatchSpanProcessor.js","../../src/privacyMode.ts","../../src/otel/requestContext.ts","../../src/otel/processor.ts"],"sourcesContent":["const DATA_URL_PREFIX_RE = /^data:([^;,\\s]+)(?:;[^;,\\s]+)*;base64,/i\nconst BASE64_ALPHABET_RE = /^[A-Za-z0-9+/_=-]+$/\n\nexport type Base64Recognition = { kind: 'data-url'; mediaType: string } | { kind: 'raw' } | { kind: 'none' }\n\nexport class Base64Recognizer {\n recognize(value: string, minLength: number): Base64Recognition {\n const dataUrl = DATA_URL_PREFIX_RE.exec(value)\n if (dataUrl) return { kind: 'data-url', mediaType: dataUrl[1] }\n\n if (value.length < minLength) return { kind: 'none' }\n\n const confidencePrefix = value.slice(0, minLength)\n if (BASE64_ALPHABET_RE.test(confidencePrefix)) {\n return { kind: 'raw' }\n } else {\n return { kind: 'none' }\n }\n }\n}\n","const MIME_HINT_KEYS = ['mediaType', 'media_type', 'mimeType', 'mime_type'] as const\n\nconst STRONG_CONTEXT_KEYS = new Set([\n 'data',\n 'file_data',\n 'fileData',\n 'image_url',\n 'imageUrl',\n 'video_url',\n 'videoUrl',\n 'audio',\n 'audio_data',\n 'audioData',\n 'inline_data',\n 'inlineData',\n 'source',\n 'result',\n])\n\nconst STRONG_CONTEXT_TYPES = new Set([\n 'image',\n 'image_url',\n 'input_image',\n 'audio',\n 'input_audio',\n 'video',\n 'video_url',\n 'file',\n 'input_file',\n 'document',\n 'media',\n 'file-data',\n])\n\nconst FILE_FAMILY_TYPES = new Set(['file', 'input_file', 'document', 'media', 'file-data'])\nconst TYPED_BINARY_DATA_TYPES = new Set(['image', 'audio', 'video', 'document'])\n\nconst KNOWN_AUDIO_FORMATS = new Set(['wav', 'mp3', 'ogg', 'flac', 'm4a', 'aac', 'webm'])\n\nexport class MediaTypeContext {\n static readonly EMPTY = new MediaTypeContext(undefined, undefined)\n\n constructor(\n private readonly parent: Record<string, unknown> | undefined,\n private readonly key: string | undefined,\n private readonly explicitMediaType?: string\n ) {}\n\n inferMediaType(): string | undefined {\n return (\n this.inferFromSiblingMime() ?? this.inferFromSiblingFormat() ?? this.inferFromParentType() ?? this.inferFromKey()\n )\n }\n\n inferFromSiblingMime(): string | undefined {\n if (this.explicitMediaType) return this.explicitMediaType\n if (!this.parent) return undefined\n for (const hint of MIME_HINT_KEYS) {\n const v = this.parent[hint]\n if (typeof v === 'string') return v\n }\n return undefined\n }\n\n inferFromSiblingFormat(): string | undefined {\n if (!this.parent) return undefined\n const fmt = this.parent.format\n if (typeof fmt === 'string' && KNOWN_AUDIO_FORMATS.has(fmt.toLowerCase())) {\n return `audio/${fmt.toLowerCase()}`\n }\n return undefined\n }\n\n inferFromParentType(): string | undefined {\n if (!this.parent) return undefined\n const t = this.parent.type\n if (typeof t !== 'string') return undefined\n if (t === 'image' || t === 'image_url' || t === 'input_image') return 'image'\n if (t === 'audio' || t === 'input_audio') return 'audio'\n if (t === 'video' || t === 'video_url') return 'video'\n if (FILE_FAMILY_TYPES.has(t)) return 'application/octet-stream'\n return undefined\n }\n\n inferFromKey(): string | undefined {\n if (!this.key) return undefined\n const key = this.key.toLowerCase()\n if (key.includes('audio')) return 'audio'\n if (key.includes('video')) return 'video'\n if (key.includes('image')) return 'image'\n if (key.includes('file') || key.includes('document')) return 'application/octet-stream'\n return undefined\n }\n\n hasDefiniteBinaryData(): boolean {\n if (\n this.parent &&\n this.key === 'data' &&\n typeof this.parent.type === 'string' &&\n TYPED_BINARY_DATA_TYPES.has(this.parent.type)\n )\n return true\n if (!this.explicitMediaType && (!this.parent || !this.key || !STRONG_CONTEXT_KEYS.has(this.key))) return false\n const mediaType = this.inferFromSiblingMime()\n return mediaType !== undefined && !mediaType.toLowerCase().startsWith('text/')\n }\n\n signalsBinary(): boolean {\n if (this.explicitMediaType) return true\n if (this.parent) {\n for (const hint of MIME_HINT_KEYS) {\n if (typeof this.parent[hint] === 'string') return true\n }\n const fmt = this.parent.format\n if (typeof fmt === 'string' && KNOWN_AUDIO_FORMATS.has(fmt.toLowerCase())) return true\n const t = this.parent.type\n if (typeof t === 'string' && STRONG_CONTEXT_TYPES.has(t)) return true\n }\n if (this.key && STRONG_CONTEXT_KEYS.has(this.key)) return true\n return false\n }\n}\n","import { Base64Recognizer } from './base64_recognizer'\nimport { MediaTypeContext } from './media_type_context'\n\nconst STRONG_CONTEXT_MIN_LENGTH = 64\nconst WEAK_CONTEXT_MIN_LENGTH = 1024\nconst MAX_NODES = 10_000\nconst TRUNCATED = '[Truncated]'\n\nexport class BinaryContentRedactor {\n private ancestors: WeakSet<object> = new WeakSet()\n private remainingNodes = MAX_NODES\n\n constructor(private readonly recognizer: Base64Recognizer = new Base64Recognizer()) {}\n\n redact<T>(value: T, mediaType?: string): T\n redact(value: unknown, mediaType?: string): unknown {\n this.ancestors = new WeakSet()\n this.remainingNodes = MAX_NODES\n return this.walk(value, mediaType ? new MediaTypeContext(undefined, undefined, mediaType) : MediaTypeContext.EMPTY)\n }\n\n /** Redact one leaf while a caller owns bounded, type-preserving traversal. @internal */\n redactLeaf(value: string | Uint8Array, context: MediaTypeContext): string {\n return typeof value === 'string' ? this.redactString(value, context) : this.placeholderFor(context.inferMediaType())\n }\n\n private walk(value: unknown, ctx: MediaTypeContext): unknown {\n if (value === null || value === undefined) return value\n if (typeof value === 'string') return this.redactLeaf(value, ctx)\n if (typeof value !== 'object') return value\n\n // Buffer extends Uint8Array, so this branch catches both.\n if (typeof Uint8Array !== 'undefined' && value instanceof Uint8Array) {\n return this.redactLeaf(value, ctx)\n }\n\n if (this.ancestors.has(value)) return null\n // Shared references are walked once per path, so the unfolded tree can be exponentially larger than the input.\n if (this.remainingNodes <= 0) return TRUNCATED\n this.remainingNodes--\n this.ancestors.add(value)\n try {\n if (Array.isArray(value)) {\n return value.map((item) => this.walk(item, ctx))\n }\n\n const obj = value as Record<string, unknown>\n const out: Record<string, unknown> = {}\n for (const k of Object.keys(obj)) {\n Object.defineProperty(out, k, {\n value: this.walk(obj[k], new MediaTypeContext(obj, k)),\n enumerable: true,\n writable: true,\n configurable: true,\n })\n }\n return out\n } finally {\n this.ancestors.delete(value)\n }\n }\n\n private redactString(value: string, ctx: MediaTypeContext): string {\n const hasDefiniteBinaryData = ctx.hasDefiniteBinaryData()\n const recognitionValue = hasDefiniteBinaryData ? value.replace(/[\\r\\n]/g, '') : value\n const minLength = hasDefiniteBinaryData\n ? Math.min(recognitionValue.length, STRONG_CONTEXT_MIN_LENGTH)\n : ctx.signalsBinary()\n ? STRONG_CONTEXT_MIN_LENGTH\n : WEAK_CONTEXT_MIN_LENGTH\n const recognition = this.recognizer.recognize(recognitionValue, minLength)\n switch (recognition.kind) {\n case 'data-url':\n return this.placeholderFor(recognition.mediaType)\n case 'raw':\n return this.placeholderFor(ctx.inferMediaType())\n case 'none':\n return value\n }\n }\n\n private placeholderFor(mediaType?: string): string {\n if (!mediaType) return '[base64 redacted]'\n if (mediaType === 'application/octet-stream') return '[base64 file redacted]'\n return `[base64 ${mediaType} redacted]`\n }\n}\n","import type { Attributes } from '@opentelemetry/api'\nimport type { ReadableSpan, TimedEvent } from './types'\n\nconst AI_SPAN_PREFIXES = ['gen_ai.', 'llm.', 'ai.', 'traceloop.'] as const\n\n/**\n * Returns `true` when the span is AI-related — its name or any attribute\n * key starts with `gen_ai.`, `llm.`, `ai.`, or `traceloop.`.\n */\nexport function isAISpan(span: ReadableSpan): boolean {\n if (AI_SPAN_PREFIXES.some((prefix) => span.name.startsWith(prefix))) {\n return true\n }\n const attributes = span.attributes\n if (attributes) {\n return Object.keys(attributes).some((key) => AI_SPAN_PREFIXES.some((prefix) => key.startsWith(prefix)))\n }\n return false\n}\n\n/** Copies rather than mutates: the span is shared across every registered processor/exporter. */\nexport function withAttributes(span: ReadableSpan, attributes: Attributes, events?: TimedEvent[]): ReadableSpan {\n return Object.create(span, {\n attributes: { value: attributes, enumerable: true, configurable: true },\n ...(events ? { events: { value: events, enumerable: true, configurable: true } } : {}),\n })\n}\n","// Type guards for safer type checking\n\nexport const isString = (value: unknown): value is string => {\n return typeof value === 'string'\n}\n\nexport const isObject = (value: unknown): value is Record<string, unknown> => {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n","import { isObject } from './typeGuards'\n\nconst MCP_CREDENTIAL_FIELDS = ['headers', 'authorization']\n\n// Vercel AI SDK provider tools that configure a remote MCP server, keyed by their `id`.\nconst MCP_PROVIDER_TOOL_IDS = new Set(['openai.mcp', 'xai.mcp', 'google.mcp_server'])\n\nconst isMcpProviderTool = (tool: Record<string, unknown>): boolean =>\n (tool.type === 'provider' || tool.type === 'provider-defined') &&\n typeof tool.id === 'string' &&\n MCP_PROVIDER_TOOL_IDS.has(tool.id)\n\nconst withoutMcpCredentials = (config: Record<string, unknown>): Record<string, unknown> => {\n const redacted: Record<string, unknown> = { ...config }\n for (const field of MCP_CREDENTIAL_FIELDS) {\n if (field in redacted) {\n redacted[field] = '[REDACTED]'\n }\n }\n return redacted\n}\n\n/** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */\nexport function redactMcpToolDefinition(tool: unknown): unknown {\n if (!isObject(tool)) {\n return tool\n }\n if (tool.type === 'mcp') {\n return withoutMcpCredentials(tool)\n }\n if (isMcpProviderTool(tool) && isObject(tool.args)) {\n return { ...tool, args: withoutMcpCredentials(tool.args) }\n }\n return tool\n}\n\nexport function redactMcpToolCredentials(tools: unknown): unknown {\n return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools\n}\n","import type { AttributeValue } from '@opentelemetry/api'\n\nimport { redactMcpToolCredentials, redactMcpToolDefinition } from '../mcpCredentials'\n\n// Instrumentations serialize tool definitions, remote MCP tools and their credentials included,\n// as a JSON array, an array of JSON tools, or one JSON tool per attribute.\nconst TOOL_DEFINITION_ATTRIBUTES = new Set(['gen_ai.tool.definitions', 'ai.prompt.tools'])\nconst TOOL_DEFINITION_PATTERN = /^llm\\.tools\\.\\d+\\.tool\\.json_schema$/\n\nexport const isToolDefinitionAttribute = (key: string): boolean =>\n TOOL_DEFINITION_ATTRIBUTES.has(key) || TOOL_DEFINITION_PATTERN.test(key)\n\nconst parseToolDefinitionJson = (value: string): object | undefined => {\n try {\n const parsed: unknown = JSON.parse(value)\n return parsed !== null && typeof parsed === 'object' ? parsed : undefined\n } catch {\n return undefined\n }\n}\n\nconst redactJson = (value: string): string => {\n const parsed = parseToolDefinitionJson(value)\n if (parsed === undefined) {\n return value\n }\n const redacted = JSON.stringify(\n Array.isArray(parsed) ? redactMcpToolCredentials(parsed) : redactMcpToolDefinition(parsed)\n )\n return redacted === JSON.stringify(parsed) ? value : redacted\n}\n\n/** Replaces MCP credentials in a tool definition attribute; values that are not JSON are kept as is. */\nexport function redactToolDefinitionCredentials(value: AttributeValue): AttributeValue {\n if (typeof value === 'string') {\n return redactJson(value)\n }\n if (Array.isArray(value) && value.every((item) => typeof item === 'string' || item == null)) {\n const redacted = value.map((item) => (typeof item === 'string' ? redactJson(item) : item))\n return redacted.some((item, index) => item !== value[index]) ? redacted : value\n }\n return value\n}\n\n/** Drops the parts of a tool definition attribute that are not JSON, since their credentials cannot be found. */\nexport function withoutUnparseableToolDefinitions(value: AttributeValue): AttributeValue | undefined {\n if (typeof value === 'string') {\n return parseToolDefinitionJson(value) === undefined ? undefined : value\n }\n if (Array.isArray(value)) {\n return value.filter(\n (item): item is string => typeof item === 'string' && parseToolDefinitionJson(item) !== undefined\n )\n }\n return undefined\n}\n","import type { Attributes, AttributeValue } from '@opentelemetry/api'\nimport type { ReadableSpan, TimedEvent } from './types'\n\nimport { BinaryContentRedactor } from '../sanitization/binary_content_redactor'\nimport { withAttributes } from './spans'\nimport { isToolDefinitionAttribute, redactToolDefinitionCredentials } from './toolDefinitions'\n\n// Deliberately always redacts here — the OTLP export path has no per-client passthrough gate.\nconst redactor = new BinaryContentRedactor()\n\nexport function redactSpan(span: ReadableSpan): ReadableSpan {\n const attributes = span.attributes ? redactAttributes(span.attributes) : span.attributes\n const events = span.events ? redactEvents(span.events) : span.events\n if (attributes === span.attributes && events === span.events) {\n return span\n }\n return withAttributes(span, attributes, events)\n}\n\nfunction redactAttributes(attributes: Attributes): Attributes {\n let changed = false\n const out: Attributes = {}\n for (const key of Object.keys(attributes)) {\n const original = attributes[key]\n const value =\n original !== undefined && isToolDefinitionAttribute(key) ? redactToolDefinitionCredentials(original) : original\n const redacted = value === undefined ? value : redactAttributeValue(value)\n if (redacted !== original) {\n changed = true\n }\n out[key] = redacted\n }\n return changed ? out : attributes\n}\n\nfunction redactEvents(events: TimedEvent[]): TimedEvent[] {\n let changed = false\n const out = events.map((event) => {\n if (!event.attributes) {\n return event\n }\n const attributes = redactAttributes(event.attributes)\n if (attributes === event.attributes) {\n return event\n }\n changed = true\n return { ...event, attributes }\n })\n return changed ? out : events\n}\n\nfunction redactAttributeValue(value: AttributeValue): AttributeValue {\n if (typeof value === 'string') {\n return redactString(value)\n }\n if (isStringArray(value)) {\n let changed = false\n const out = value.map((item) => {\n if (typeof item !== 'string') {\n return item\n }\n const redacted = redactString(item)\n if (redacted !== item) {\n changed = true\n }\n return redacted\n })\n return changed ? out : value\n }\n return value\n}\n\nfunction isStringArray(value: AttributeValue): value is Array<string | null | undefined> {\n return Array.isArray(value) && value.every((item) => typeof item !== 'number' && typeof item !== 'boolean')\n}\n\nfunction redactString(value: string): string {\n const trimmed = value.trimStart()\n if (trimmed.startsWith('{') || trimmed.startsWith('[')) {\n const redacted = redactJson(value)\n if (redacted !== undefined) {\n return redacted\n }\n }\n return redactor.redact(value)\n}\n\nfunction redactJson(value: string): string | undefined {\n let parsed: unknown\n try {\n parsed = JSON.parse(value)\n } catch {\n return undefined\n }\n if (parsed === null || typeof parsed !== 'object') {\n return undefined\n }\n const redactedStr = JSON.stringify(redactor.redact(parsed))\n // Preserve the original string (and its formatting) when nothing was redacted.\n return redactedStr === JSON.stringify(parsed) ? value : redactedStr\n}\n","import type { Attributes } from '@opentelemetry/api'\nimport type { ReadableSpan, TimedEvent } from './types'\n\nimport { withAttributes } from './spans'\nimport { isToolDefinitionAttribute, withoutUnparseableToolDefinitions } from './toolDefinitions'\n\n// Every attribute PostHog ingestion turns into prompt, output, tool call or error text. Ingestion\n// keeps unmapped attributes as event properties, so this also covers attributes it does not map.\nconst CONTENT_ATTRIBUTES = new Set([\n // Vercel AI SDK\n 'ai.prompt',\n 'ai.prompt.messages',\n 'ai.response.text',\n 'ai.response.object',\n 'ai.response.toolCalls',\n 'ai.response.reasoning',\n 'ai.response.reasoningDetails',\n 'ai.response.files',\n 'ai.toolCall.args',\n 'ai.toolCall.result',\n 'ai.value',\n 'ai.values',\n 'ai.embedding',\n 'ai.embeddings',\n 'ai.documents',\n 'ai.request.text',\n 'ai.decision.state',\n 'ai.decision.questions',\n 'ai.decision.answers',\n // OpenTelemetry GenAI semantic conventions\n 'gen_ai.input.messages',\n 'gen_ai.output.messages',\n 'gen_ai.system_instructions',\n 'gen_ai.prompt',\n 'gen_ai.completion',\n 'gen_ai.tool.call.arguments',\n 'gen_ai.tool.call.result',\n 'gen_ai.retrieval.documents',\n 'gen_ai.retrieval.query.text',\n 'gen_ai.memory.query.text',\n 'gen_ai.memory.records',\n 'gen_ai.evaluation.explanation',\n // Traceloop / OpenLLMetry\n 'traceloop.entity.input',\n 'traceloop.entity.output',\n 'traceloop.prompt.template',\n 'gen_ai.task.input',\n 'gen_ai.task.output',\n 'gen_ai.guardrail.input',\n 'gen_ai.guardrail.output',\n 'gen_ai.guardrail.error.message',\n 'gen_ai.response.revised_prompt',\n 'mcp.response.value',\n 'db.marqo.search.query',\n // Anthropic\n 'anthropic.tool_result.content',\n // Pydantic AI / Logfire\n 'pydantic_ai.all_messages',\n 'final_result',\n 'tool_arguments',\n 'tool_response',\n 'events',\n 'model_request_parameters',\n 'inputs',\n 'prompt',\n // OpenInference\n 'input.value',\n 'output.value',\n 'llm.function_call',\n 'llm.prompt_template.template',\n 'llm.prompt_template.variables',\n // Holds request parameters such as Responses `instructions`.\n 'llm.invocation_parameters',\n 'reranker.query',\n // Langfuse\n 'langfuse.trace.input',\n 'langfuse.trace.output',\n 'langfuse.observation.input',\n 'langfuse.observation.output',\n 'langfuse.observation.status_message',\n 'langfuse.experiment.item.expected_output',\n // Errors\n 'exception.message',\n 'exception.stacktrace',\n 'error.message',\n])\n\nconst CONTENT_ATTRIBUTE_PREFIXES = [\n 'gen_ai.prompt.',\n 'gen_ai.completion.',\n 'llm.prompts.',\n 'llm.completions.',\n 'llm.input_messages.',\n 'llm.output_messages.',\n 'llm.choices.',\n 'traceloop.prompt.template_variables.',\n]\n\nconst CONTENT_ATTRIBUTE_PATTERNS = [\n /^db\\.chroma\\.(query|get|delete)\\.where_document$/,\n /^embedding\\.embeddings\\.\\d+\\.embedding\\.(text|vector)$/,\n /^retrieval\\.documents\\.\\d+\\.document\\.(content|metadata)$/,\n /^reranker\\.(input|output)_documents\\.\\d+\\.document\\.content$/,\n /^(input|output)\\.images\\.\\d+\\.image\\.url$/,\n /^mastra\\.[a-z_]+\\.(input|output)$/,\n]\n\n// Prompt management metadata that shares the `gen_ai.prompt.` prefix with prompt content.\nconst NON_CONTENT_ATTRIBUTES = new Set(['gen_ai.prompt.name', 'gen_ai.prompt.version'])\n\n// Ingestion only reads exception events. Every other event (GenAI semconv messages, vector\n// database results, framework logs) can carry content.\nconst EXCEPTION_EVENT_NAME = 'exception'\n\nconst PROVIDER_METADATA_ATTRIBUTE = 'ai.response.providerMetadata'\n\nconst isContentAttribute = (key: string): boolean =>\n !NON_CONTENT_ATTRIBUTES.has(key) &&\n (CONTENT_ATTRIBUTES.has(key) ||\n CONTENT_ATTRIBUTE_PREFIXES.some((prefix) => key.startsWith(prefix) || prefix === `${key}.`) ||\n CONTENT_ATTRIBUTE_PATTERNS.some((pattern) => pattern.test(key)))\n\n// Provider metadata can carry content, such as Google grounding search queries. Ingestion only\n// reads the Vercel AI Gateway cost from it.\nfunction gatewayCostOnly(value: unknown): string | undefined {\n if (typeof value !== 'string') {\n return undefined\n }\n try {\n const cost: unknown = JSON.parse(value)?.gateway?.cost\n return typeof cost === 'number' || typeof cost === 'string' ? JSON.stringify({ gateway: { cost } }) : undefined\n } catch {\n return undefined\n }\n}\n\nfunction stripAttributes(attributes: Attributes): Attributes {\n const out: Attributes = {}\n for (const [key, value] of Object.entries(attributes)) {\n if (isContentAttribute(key)) {\n continue\n }\n if (isToolDefinitionAttribute(key)) {\n const definitions = value === undefined ? undefined : withoutUnparseableToolDefinitions(value)\n if (definitions !== undefined) {\n out[key] = definitions\n }\n continue\n }\n if (key === PROVIDER_METADATA_ATTRIBUTE) {\n const metadata = gatewayCostOnly(value)\n if (metadata !== undefined) {\n out[key] = metadata\n }\n continue\n }\n out[key] = value\n }\n return out\n}\n\nfunction stripEvents(events: TimedEvent[]): TimedEvent[] {\n return events\n .filter((event) => event.name === EXCEPTION_EVENT_NAME)\n .map((event) => (event.attributes ? { ...event, attributes: stripAttributes(event.attributes) } : event))\n}\n\n/** Returns a copy of the span without the attributes, events and status message that carry content. */\nexport function stripContent(span: ReadableSpan): ReadableSpan {\n const stripped = withAttributes(\n span,\n span.attributes ? stripAttributes(span.attributes) : span.attributes,\n span.events ? stripEvents(span.events) : span.events\n )\n if (span.status?.message) {\n Object.defineProperty(stripped, 'status', {\n value: { code: span.status.code },\n enumerable: true,\n configurable: true,\n })\n }\n return stripped\n}\n","// Warn when a wrapper's base_url points at the PostHog AI Gateway: the gateway\n// emits its own $ai_generation, so each call would be captured (and, for billable\n// products, billed) twice. We only warn — the wrapper's event carries data the\n// gateway never sees (groups, custom properties, trace hierarchy).\n\n// Keep in sync with the gateway's deployed hosts (see services/llm-gateway in the\n// main repo). gateway.us.posthog.com is live today; the rest are listed ahead of\n// any traffic moving to them.\nexport const POSTHOG_AI_GATEWAY_HOSTS: readonly string[] = [\n 'gateway.posthog.com',\n 'gateway.us.posthog.com',\n 'gateway.eu.posthog.com',\n 'ai-gateway.us.posthog.com',\n 'ai-gateway.eu.posthog.com',\n]\n\n// Swap for the dedicated AI Gateway page once it ships.\nconst GATEWAY_DOCS_URL = 'https://posthog.com/docs/ai-observability'\n\nconst extractHost = (baseURL: string): string | undefined => {\n try {\n // Tolerate bare hosts that omit a scheme, e.g. \"gateway.us.posthog.com/v1\".\n const hasScheme = /^[a-z][a-z0-9+.-]*:\\/\\//i.test(baseURL)\n return new URL(hasScheme ? baseURL : `https://${baseURL}`).hostname.toLowerCase()\n } catch {\n return undefined\n }\n}\n\nexport const isPostHogAiGatewayUrl = (baseURL: string | undefined | null): boolean => {\n if (!baseURL) {\n return false\n }\n const host = extractHost(baseURL)\n return host !== undefined && POSTHOG_AI_GATEWAY_HOSTS.includes(host)\n}\n\n// Warns on every gateway call by design: the misconfiguration is impossible to\n// miss that way, and a doubled bill is worse than noisy logs.\nexport const warnIfPostHogAiGateway = (baseURL: string | undefined | null): void => {\n if (!isPostHogAiGatewayUrl(baseURL)) {\n return\n }\n console.warn(\n '[PostHog] The PostHog AI wrapper is pointed at the PostHog AI Gateway. ' +\n 'Both capture $ai_generation, so every call is double-counted and double-billed. ' +\n `Use one or the other — see ${GATEWAY_DOCS_URL}.`\n )\n}\n\n// OTel spans don't pass through captureAiGeneration, so detect the gateway from\n// the span's host/URL attributes instead. These follow the GenAI / HTTP semantic\n// conventions: `server.address` is a bare host, `url.full` a full URL, both of\n// which isPostHogAiGatewayUrl accepts.\nconst OTEL_GATEWAY_URL_ATTRIBUTES = ['server.address', 'url.full'] as const\n\nexport const warnIfPostHogAiGatewayOtelAttributes = (attributes: Record<string, unknown> | undefined): void => {\n if (!attributes) {\n return\n }\n for (const key of OTEL_GATEWAY_URL_ATTRIBUTES) {\n const value = attributes[key]\n if (typeof value === 'string' && isPostHogAiGatewayUrl(value)) {\n warnIfPostHogAiGateway(value)\n return\n }\n }\n}\n","import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'\nimport type { ReadableSpan } from './types'\n\nimport { redactSpan } from './redact'\nimport { stripContent } from './privacy'\nimport { isAISpan } from './spans'\nimport { warnIfPostHogAiGatewayOtelAttributes } from '../gatewayWarning'\n\nconst DEFAULT_OTEL_HOST = 'https://us.i.posthog.com'\n// OpenTelemetry's ExportResultCode.SUCCESS is 0. Keep this local so loading the\n// published subpath does not require the exporter package's transitive dependencies.\nconst EXPORT_SUCCESS = 0\n\nfunction normalizeToken(value?: unknown): string {\n return typeof value === 'string' ? value.trim() : ''\n}\n\nfunction normalizeHost(value?: unknown): string {\n const normalizedValue = typeof value === 'string' ? value.trim() : ''\n return normalizedValue || DEFAULT_OTEL_HOST\n}\n\n/**\n * Options for the PostHogTraceExporter. `projectToken` is required; a blank token disables the\n * exporter as a defensive no-op. You can also optionally override the `host` URL. `host` defaults to `https://us.i.posthog.com`.\n *\n * @example\n * ```ts\n * import { PostHogTraceExporter } from '@posthog/ai/otel'\n *\n * new PostHogTraceExporter({ projectToken: 'phc_...' })\n * ```\n *\n * @example\n * ```ts\n * import { PostHogTraceExporter } from '@posthog/ai/otel'\n *\n * new PostHogTraceExporter({ projectToken: 'phc_...', host: 'https://eu.i.posthog.com' })\n * ```\n */\nexport type PostHogTraceExporterOptions = {\n projectToken: string\n host?: string\n /** Drop prompts, outputs, tool arguments and results, and error messages from exported spans. Defaults to false. */\n privacyMode?: boolean\n}\n\n/**\n * An OpenTelemetry `TraceExporter` that sends AI traces to PostHog's OTLP\n * ingestion endpoint. PostHog converts `gen_ai.*` spans into\n * `$ai_generation` events server-side.\n *\n * Only AI-related spans (those whose name or attribute keys start with\n * `gen_ai.`, `llm.`, `ai.`, or `traceloop.`) are exported; all other\n * spans are silently dropped.\n *\n * Use this when the API you're integrating with only accepts a\n * `TraceExporter` (e.g. Vercel's `registerOTel`) or when you need to\n * plug PostHog into an existing processor chain. Otherwise prefer\n * {@link PostHogSpanProcessor}, which is self-contained.\n *\n * `projectToken` is required; a blank token disables the exporter as a defensive no-op.\n * You can also optionally override the `host` URL.\n *\n * Exporters only see finished spans, so they can't add per-request PostHog context;\n * use {@link PostHogSpanProcessor} with `client` for that.\n *\n * @example\n * ```ts\n * import { PostHogTraceExporter } from '@posthog/ai/otel'\n * import { registerOTel } from '@vercel/otel'\n *\n * registerOTel({\n * serviceName: 'my-app',\n * traceExporter: new PostHogTraceExporter({ projectToken: 'phc_...' }),\n * })\n * ```\n */\nexport class PostHogTraceExporter extends OTLPTraceExporter {\n private readonly disabled: boolean\n private readonly privacyMode: boolean\n\n constructor(options: PostHogTraceExporterOptions) {\n const token = normalizeToken(options.projectToken)\n const disabled = !token\n const host = token ? new URL(normalizeHost(options.host)).origin : DEFAULT_OTEL_HOST\n super({\n url: `${host}/i/v0/ai/otel`,\n headers: token\n ? {\n Authorization: `Bearer ${token}`,\n }\n : {},\n })\n\n this.disabled = disabled\n this.privacyMode = options.privacyMode === true\n if (this.disabled) {\n console.warn('[PostHogTraceExporter] projectToken is missing or blank; the exporter will be disabled.')\n }\n }\n\n override export(spans: ReadableSpan[], resultCallback: (result: { code: number; error?: Error }) => void): void {\n if (this.disabled) {\n // Intentionally report success: missing or blank tokens disable exporting as a compatibility no-op.\n // Reporting failure would make OpenTelemetry treat every span as an export error.\n resultCallback({ code: EXPORT_SUCCESS })\n return\n }\n\n const aiSpans = spans.filter(isAISpan)\n if (aiSpans.length === 0) {\n resultCallback({ code: EXPORT_SUCCESS })\n return\n }\n for (const span of aiSpans) {\n warnIfPostHogAiGatewayOtelAttributes(span.attributes)\n }\n const shareable = this.privacyMode ? aiSpans.map(stripContent) : aiSpans\n super.export(shareable.map(redactSpan), resultCallback)\n }\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createContextKey } from '@opentelemetry/api';\nconst SUPPRESS_TRACING_KEY = createContextKey('OpenTelemetry SDK Context Key SUPPRESS_TRACING');\nexport function suppressTracing(context) {\n return context.setValue(SUPPRESS_TRACING_KEY, true);\n}\nexport function unsuppressTracing(context) {\n return context.deleteValue(SUPPRESS_TRACING_KEY);\n}\nexport function isTracingSuppressed(context) {\n return context.getValue(SUPPRESS_TRACING_KEY) === true;\n}\n//# sourceMappingURL=suppress-tracing.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { diag } from '@opentelemetry/api';\n/**\n * Returns a function that logs an error using the provided logger, or a\n * console logger if one was not provided.\n */\nexport function loggingErrorHandler() {\n return (ex) => {\n diag.error(stringifyException(ex));\n };\n}\n/**\n * Converts an exception into a string representation\n * @param {Exception} ex\n */\nfunction stringifyException(ex) {\n if (typeof ex === 'string') {\n return ex;\n }\n else {\n return JSON.stringify(flattenException(ex));\n }\n}\n/**\n * Flattens an exception into key-value pairs by traversing the prototype chain\n * and coercing values to strings. Duplicate properties will not be overwritten;\n * the first insert wins.\n */\nfunction flattenException(ex) {\n const result = {};\n let current = ex;\n while (current !== null) {\n Object.getOwnPropertyNames(current).forEach(propertyName => {\n if (result[propertyName])\n return;\n const value = current[propertyName];\n if (value) {\n result[propertyName] = String(value);\n }\n });\n current = Object.getPrototypeOf(current);\n }\n return result;\n}\n//# sourceMappingURL=logging-error-handler.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { loggingErrorHandler } from './logging-error-handler';\n/** The global error handler delegate */\nlet delegateHandler = loggingErrorHandler();\n/**\n * Set the global error handler\n * @param {ErrorHandler} handler\n */\nexport function setGlobalErrorHandler(handler) {\n delegateHandler = handler;\n}\n/**\n * Return the global error handler\n * @param {Exception} ex\n */\nexport function globalErrorHandler(ex) {\n try {\n delegateHandler(ex);\n }\n catch { } // eslint-disable-line no-empty\n}\n//# sourceMappingURL=global-error-handler.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { diag } from '@opentelemetry/api';\nimport { inspect } from 'util';\n/**\n * Retrieves a number from an environment variable.\n * - Returns `undefined` if the environment variable is empty, unset, contains only whitespace, or is not a number.\n * - Returns a number in all other cases.\n *\n * @param {string} key - The name of the environment variable to retrieve.\n * @returns {number | undefined} - The number value or `undefined`.\n */\nexport function getNumberFromEnv(key) {\n const raw = process.env[key];\n if (raw == null || raw.trim() === '') {\n return undefined;\n }\n const value = Number(raw);\n if (isNaN(value)) {\n diag.warn(`Unknown value ${inspect(raw)} for ${key}, expected a number, using defaults`);\n return undefined;\n }\n return value;\n}\n/**\n * Retrieves a string from an environment variable.\n * - Returns `undefined` if the environment variable is empty, unset, or contains only whitespace.\n *\n * @param {string} key - The name of the environment variable to retrieve.\n * @returns {string | undefined} - The string value or `undefined`.\n */\nexport function getStringFromEnv(key) {\n const raw = process.env[key];\n if (raw == null || raw.trim() === '') {\n return undefined;\n }\n return raw;\n}\n/**\n * Retrieves a boolean value from an environment variable.\n * - Trims leading and trailing whitespace and ignores casing.\n * - Returns `false` if the environment variable is empty, unset, or contains only whitespace.\n * - Returns `false` for strings that cannot be mapped to a boolean.\n *\n * @param {string} key - The name of the environment variable to retrieve.\n * @returns {boolean} - The boolean value or `false` if the environment variable is unset empty, unset, or contains only whitespace.\n */\nexport function getBooleanFromEnv(key) {\n const raw = process.env[key]?.trim().toLowerCase();\n if (raw == null || raw === '') {\n // NOTE: falling back to `false` instead of `undefined` as required by the specification.\n // If you have a use-case that requires `undefined`, consider using `getStringFromEnv()` and applying the necessary\n // normalizations in the consuming code.\n return false;\n }\n if (raw === 'true') {\n return true;\n }\n else if (raw === 'false') {\n return false;\n }\n else {\n diag.warn(`Unknown value ${inspect(raw)} for ${key}, expected 'true' or 'false', falling back to 'false' (default)`);\n return false;\n }\n}\n/**\n * Retrieves a list of strings from an environment variable.\n * - Uses ',' as the delimiter.\n * - Trims leading and trailing whitespace from each entry.\n * - Excludes empty entries.\n * - Returns `undefined` if the environment variable is empty or contains only whitespace.\n * - Returns an empty array if all entries are empty or whitespace.\n *\n * @param {string} key - The name of the environment variable to retrieve.\n * @returns {string[] | undefined} - The list of strings or `undefined`.\n */\nexport function getStringListFromEnv(key) {\n return getStringFromEnv(key)\n ?.split(',')\n .map(v => v.trim())\n .filter(s => s !== '');\n}\n//# sourceMappingURL=environment.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport var ExportResultCode;\n(function (ExportResultCode) {\n ExportResultCode[ExportResultCode[\"SUCCESS\"] = 0] = \"SUCCESS\";\n ExportResultCode[ExportResultCode[\"FAILED\"] = 1] = \"FAILED\";\n})(ExportResultCode || (ExportResultCode = {}));\n//# sourceMappingURL=ExportResult.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport class Deferred {\n _promise;\n _resolve;\n _reject;\n constructor() {\n this._promise = new Promise((resolve, reject) => {\n this._resolve = resolve;\n this._reject = reject;\n });\n }\n get promise() {\n return this._promise;\n }\n resolve(val) {\n this._resolve(val);\n }\n reject(err) {\n this._reject(err);\n }\n}\n//# sourceMappingURL=promise.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Deferred } from './promise';\n/**\n * Bind the callback and only invoke the callback once regardless how many times `BindOnceFuture.call` is invoked.\n */\nexport class BindOnceFuture {\n _callback;\n _that;\n _isCalled = false;\n _deferred = new Deferred();\n constructor(_callback, _that) {\n this._callback = _callback;\n this._that = _that;\n }\n get isCalled() {\n return this._isCalled;\n }\n get promise() {\n return this._deferred.promise;\n }\n call(...args) {\n if (!this._isCalled) {\n this._isCalled = true;\n try {\n Promise.resolve(this._callback.call(this._that, ...args)).then(val => this._deferred.resolve(val), err => this._deferred.reject(err));\n }\n catch (err) {\n this._deferred.reject(err);\n }\n }\n return this._deferred.promise;\n }\n}\n//# sourceMappingURL=callback.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { context, diag, TraceFlags } from '@opentelemetry/api';\nimport { BindOnceFuture, ExportResultCode, getNumberFromEnv, globalErrorHandler, suppressTracing, } from '@opentelemetry/core';\n/**\n * Implementation of the {@link SpanProcessor} that batches spans exported by\n * the SDK then pushes them to the exporter pipeline.\n */\nexport class BatchSpanProcessorBase {\n _exporter;\n _maxExportBatchSize;\n _maxQueueSize;\n _scheduledDelayMillis;\n _exportTimeoutMillis;\n _isExporting = false;\n _finishedSpans = [];\n _timer;\n _shutdownOnce;\n _droppedSpansCount = 0;\n constructor(_exporter, config) {\n this._exporter = _exporter;\n this._maxExportBatchSize =\n typeof config?.maxExportBatchSize === 'number'\n ? config.maxExportBatchSize\n : (getNumberFromEnv('OTEL_BSP_MAX_EXPORT_BATCH_SIZE') ?? 512);\n this._maxQueueSize =\n typeof config?.maxQueueSize === 'number'\n ? config.maxQueueSize\n : (getNumberFromEnv('OTEL_BSP_MAX_QUEUE_SIZE') ?? 2048);\n this._scheduledDelayMillis =\n typeof config?.scheduledDelayMillis === 'number'\n ? config.scheduledDelayMillis\n : (getNumberFromEnv('OTEL_BSP_SCHEDULE_DELAY') ?? 5000);\n this._exportTimeoutMillis =\n typeof config?.exportTimeoutMillis === 'number'\n ? config.exportTimeoutMillis\n : (getNumberFromEnv('OTEL_BSP_EXPORT_TIMEOUT') ?? 30000);\n this._shutdownOnce = new BindOnceFuture(this._shutdown, this);\n if (this._maxExportBatchSize > this._maxQueueSize) {\n diag.warn('BatchSpanProcessor: maxExportBatchSize must be smaller or equal to maxQueueSize, setting maxExportBatchSize to match maxQueueSize');\n this._maxExportBatchSize = this._maxQueueSize;\n }\n }\n forceFlush() {\n if (this._shutdownOnce.isCalled) {\n return this._shutdownOnce.promise;\n }\n return this._flushAll();\n }\n // does nothing.\n onStart(_span, _parentContext) { }\n onEnd(span) {\n if (this._shutdownOnce.isCalled) {\n return;\n }\n if ((span.spanContext().traceFlags & TraceFlags.SAMPLED) === 0) {\n return;\n }\n this._addToBuffer(span);\n }\n shutdown() {\n return this._shutdownOnce.call();\n }\n _shutdown() {\n return Promise.resolve()\n .then(() => {\n return this.onShutdown();\n })\n .then(() => {\n return this._flushAll();\n })\n .then(() => {\n return this._exporter.shutdown();\n });\n }\n /** Add a span in the buffer. */\n _addToBuffer(span) {\n if (this._finishedSpans.length >= this._maxQueueSize) {\n // limit reached, drop span\n if (this._droppedSpansCount === 0) {\n diag.debug('maxQueueSize reached, dropping spans');\n }\n this._droppedSpansCount++;\n return;\n }\n if (this._droppedSpansCount > 0) {\n // some spans were dropped, log once with count of spans dropped\n diag.warn(`Dropped ${this._droppedSpansCount} spans because maxQueueSize reached`);\n this._droppedSpansCount = 0;\n }\n this._finishedSpans.push(span);\n this._maybeStartTimer();\n }\n /**\n * Send all spans to the exporter respecting the batch size limit\n * This function is used only on forceFlush or shutdown,\n * for all other cases _flush should be used\n * */\n _flushAll() {\n return new Promise((resolve, reject) => {\n const promises = [];\n // calculate number of batches\n const count = Math.ceil(this._finishedSpans.length / this._maxExportBatchSize);\n for (let i = 0, j = count; i < j; i++) {\n promises.push(this._flushOneBatch());\n }\n Promise.all(promises)\n .then(() => {\n resolve();\n })\n .catch(reject);\n });\n }\n _flushOneBatch() {\n this._clearTimer();\n if (this._finishedSpans.length === 0) {\n return Promise.resolve();\n }\n return new Promise((resolve, reject) => {\n const timer = setTimeout(() => {\n // don't wait anymore for export, this way the next batch can start\n reject(new Error('Timeout'));\n }, this._exportTimeoutMillis);\n // prevent downstream exporter calls from generating spans\n context.with(suppressTracing(context.active()), () => {\n // Reset the finished spans buffer here because the next invocations of the _flush method\n // could pass the same finished spans to the exporter if the buffer is cleared\n // outside the execution of this callback.\n let spans;\n if (this._finishedSpans.length <= this._maxExportBatchSize) {\n spans = this._finishedSpans;\n this._finishedSpans = [];\n }\n else {\n spans = this._finishedSpans.splice(0, this._maxExportBatchSize);\n }\n const doExport = () => this._exporter.export(spans, result => {\n clearTimeout(timer);\n if (result.code === ExportResultCode.SUCCESS) {\n resolve();\n }\n else {\n reject(result.error ??\n new Error('BatchSpanProcessor: span export failed'));\n }\n });\n let pendingResources = null;\n for (let i = 0, len = spans.length; i < len; i++) {\n const span = spans[i];\n if (span.resource.asyncAttributesPending &&\n span.resource.waitForAsyncAttributes) {\n pendingResources ??= [];\n pendingResources.push(span.resource.waitForAsyncAttributes());\n }\n }\n // Avoid scheduling a promise to make the behavior more predictable and easier to test\n if (pendingResources === null) {\n doExport();\n }\n else {\n Promise.all(pendingResources).then(doExport, err => {\n globalErrorHandler(err);\n reject(err);\n });\n }\n });\n });\n }\n _maybeStartTimer() {\n if (this._isExporting)\n return;\n const flush = () => {\n this._isExporting = true;\n this._flushOneBatch()\n .finally(() => {\n this._isExporting = false;\n if (this._finishedSpans.length > 0) {\n this._clearTimer();\n this._maybeStartTimer();\n }\n })\n .catch(e => {\n this._isExporting = false;\n globalErrorHandler(e);\n });\n };\n // we only wait if the queue doesn't have enough elements yet\n if (this._finishedSpans.length >= this._maxExportBatchSize) {\n return flush();\n }\n if (this._timer !== undefined)\n return;\n this._timer = setTimeout(() => flush(), this._scheduledDelayMillis);\n // depending on runtime, this may be a 'number' or NodeJS.Timeout\n if (typeof this._timer !== 'number') {\n this._timer.unref();\n }\n }\n _clearTimer() {\n if (this._timer !== undefined) {\n clearTimeout(this._timer);\n this._timer = undefined;\n }\n }\n}\n//# sourceMappingURL=BatchSpanProcessorBase.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { BatchSpanProcessorBase } from '../../../export/BatchSpanProcessorBase';\nexport class BatchSpanProcessor extends BatchSpanProcessorBase {\n onShutdown() { }\n}\n//# sourceMappingURL=BatchSpanProcessor.js.map","/** @internal */\nexport type PrivacyModeGate = {\n readonly privacyMode?: boolean\n /** Legacy spelling, still honored for callers that set it directly. */\n readonly privacy_mode?: boolean\n /** Read for posthog-node versions that predate the `privacyMode` accessor. */\n readonly options?: { readonly privacyMode?: boolean }\n}\n\n/** Per-call settings can turn redaction on but never off. */\nexport const isPrivacyModeEnabled = (client: PrivacyModeGate | undefined, privacyMode = false): boolean =>\n privacyMode === true ||\n client?.privacyMode === true ||\n client?.privacy_mode === true ||\n client?.options?.privacyMode === true\n","import type { AttributeValue, Attributes } from '@opentelemetry/api'\nimport type { ReadableSpan } from './types'\n\nimport { withAttributes } from './spans'\n\nexport type CapturedContext = {\n distinctId?: string\n sessionId?: string\n properties?: Record<string, unknown>\n}\n\n// Structural so declarations type-check against posthog-node versions that have no getContext.\nexport type PostHogContextSource = {\n getContext?(): CapturedContext | undefined\n}\n\nconst DISTINCT_ID_ATTRIBUTE = 'posthog.distinct_id'\nconst SESSION_ID_ATTRIBUTE = '$session_id'\n\n// Ingestion prefers posthog.distinct_id, so adding it would override the user a span already names.\nconst IDENTITY_ATTRIBUTES = [\n DISTINCT_ID_ATTRIBUTE,\n 'user.id',\n 'ai.telemetry.metadata.posthog_distinct_id',\n 'ai.settings.context.posthog_distinct_id',\n]\n\ntype Primitive = string | number | boolean\n\nfunction isPrimitive(value: unknown): value is Primitive {\n return (\n typeof value === 'string' || typeof value === 'boolean' || (typeof value === 'number' && Number.isFinite(value))\n )\n}\n\nfunction isHomogeneousPrimitiveArray(value: unknown): value is string[] | number[] | boolean[] {\n return Array.isArray(value) && value.every((item) => isPrimitive(item) && typeof item === typeof value[0])\n}\n\nfunction rejectNonFinite(_key: string, value: unknown): unknown {\n if (typeof value === 'number' && !Number.isFinite(value)) {\n throw new TypeError('non-finite number')\n }\n return value\n}\n\nfunction toAttributeValue(value: unknown): AttributeValue | undefined {\n if (value === undefined || value === null || value === '') {\n return undefined\n }\n if (isPrimitive(value) || isHomogeneousPrimitiveArray(value)) {\n return value\n }\n try {\n const json = JSON.stringify(value, rejectNonFinite)\n if (json === undefined || json === 'null') {\n return undefined\n }\n return json.startsWith('\"') ? String(JSON.parse(json)) || undefined : json\n } catch {\n return undefined\n }\n}\n\nfunction hasValues(context: CapturedContext): boolean {\n return Boolean(context.distinctId || context.sessionId || Object.keys(context.properties ?? {}).length > 0)\n}\n\nexport function captureContext(client: PostHogContextSource): CapturedContext | undefined {\n try {\n // posthog-node versions before getContext existed are still within the peer range.\n if (typeof client.getContext !== 'function') {\n return undefined\n }\n const context = client.getContext()\n return context && hasValues(context) ? context : undefined\n } catch {\n // Capturing is best effort and must never break the instrumented call.\n return undefined\n }\n}\n\nfunction toAttributes(context: CapturedContext, spanAttributes: Attributes): Attributes {\n const hasIdentity = IDENTITY_ATTRIBUTES.some((key) => spanAttributes[key] !== undefined)\n const values: Record<string, unknown> = {\n ...(context.distinctId && !hasIdentity ? { [DISTINCT_ID_ATTRIBUTE]: context.distinctId } : {}),\n ...(context.sessionId ? { [SESSION_ID_ATTRIBUTE]: context.sessionId } : {}),\n ...context.properties,\n }\n const attributes: Attributes = {}\n for (const [key, value] of Object.entries(values)) {\n if (hasIdentity && key === DISTINCT_ID_ATTRIBUTE) {\n continue\n }\n const attribute = toAttributeValue(value)\n if (attribute !== undefined) {\n attributes[key] = attribute\n }\n }\n return attributes\n}\n\nexport function withRequestContext(span: ReadableSpan, context: CapturedContext): ReadableSpan {\n try {\n const attributes = toAttributes(context, span.attributes)\n if (Object.keys(attributes).length === 0) {\n return span\n }\n return withAttributes(span, { ...attributes, ...span.attributes })\n } catch {\n // Conversion runs inside span.end() and must never break the instrumented call.\n return span\n }\n}\n","import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'\nimport type { Context } from '@opentelemetry/api'\nimport type { SpanProcessor, ReadableSpan, Span } from './types'\nimport { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base'\n\nimport { redactSpan } from './redact'\nimport { stripContent } from './privacy'\nimport { isPrivacyModeEnabled, type PrivacyModeGate } from '../privacyMode'\nimport { captureContext, withRequestContext, type CapturedContext, type PostHogContextSource } from './requestContext'\nimport { isAISpan } from './spans'\nimport { warnIfPostHogAiGatewayOtelAttributes } from '../gatewayWarning'\n\nconst DEFAULT_OTEL_HOST = 'https://us.i.posthog.com'\n\nfunction normalizeToken(value?: unknown): string {\n return typeof value === 'string' ? value.trim() : ''\n}\n\nfunction normalizeHost(value?: unknown): string {\n const normalizedValue = typeof value === 'string' ? value.trim() : ''\n return normalizedValue || DEFAULT_OTEL_HOST\n}\n\nexport interface PostHogSpanProcessorOptions {\n /**\n * Your PostHog project token (the `phc_...` key). Required; a blank token disables the\n * processor as a defensive no-op.\n */\n projectToken: string\n\n /**\n * PostHog host URL. Defaults to `https://us.i.posthog.com`.\n */\n host?: string\n\n /**\n * Your posthog-node client. When set, each AI span this processor exports gets the distinct ID,\n * session ID (as `$session_id`) and properties from the context entered with `client.withContext()` or\n * `client.enterContext()`. Other processors on the provider don't see them.\n * Attributes already on the span win over properties, which win over the context's IDs.\n * The context is captured when a span starts, but its properties are read when the span ends,\n * so mutating a context object while a span is open shows up in the export.\n * Must be the same posthog-node instance you call `withContext` or `enterContext` on.\n */\n client?: PostHogContextSource & PrivacyModeGate\n\n /**\n * Drop prompts, outputs, tool arguments and results, and error messages from exported spans.\n * Also on when the `client` was created with `privacyMode: true`. Defaults to false.\n */\n privacyMode?: boolean\n\n /**\n * @internal Injected processor for testing — bypasses exporter creation.\n */\n _spanProcessor?: SpanProcessor\n}\n\nclass NoopSpanProcessor implements SpanProcessor {\n onStart(_span: Span, _parentContext: Context): void {\n return\n }\n onEnd(_span: ReadableSpan): void {\n return\n }\n shutdown(): Promise<void> {\n return Promise.resolve()\n }\n forceFlush(): Promise<void> {\n return Promise.resolve()\n }\n}\n\n/**\n * An OpenTelemetry `SpanProcessor` that sends AI traces to PostHog.\n *\n * `projectToken` is required; a blank token disables the processor as a defensive no-op.\n *\n * Internally batches spans and exports them to PostHog's OTLP ingestion\n * endpoint. Only AI-related spans (those whose name or attribute keys\n * start with `gen_ai.`, `llm.`, `ai.`, or `traceloop.`) are exported;\n * all other spans are silently dropped.\n *\n * Request-scoped and serverless runtimes should keep a reference to this\n * processor and await {@link PostHogSpanProcessor.forceFlush} before the request\n * lifecycle ends. This waits for queued exports without sending one request per span.\n *\n * This is the recommended integration point when your setup accepts a\n * `SpanProcessor`. If you need a `TraceExporter` instead (e.g. for\n * Vercel's `registerOTel`), use {@link PostHogTraceExporter}.\n *\n * @example\n * ```ts\n * import { PostHogSpanProcessor } from '@posthog/ai/otel'\n * import { NodeSDK } from '@opentelemetry/sdk-node'\n *\n * const processor = new PostHogSpanProcessor({ projectToken: 'phc_...' })\n * const sdk = new NodeSDK({ spanProcessors: [processor] })\n * sdk.start()\n *\n * // In request-scoped runtimes, wait for queued exports before returning.\n * await processor.forceFlush()\n * ```\n *\n * @example\n * ```ts\n * // Per request: pass your posthog-node client, then wrap the work in a context.\n * const processor = new PostHogSpanProcessor({ projectToken: 'phc_...', client: posthog })\n * await posthog.withContext({ distinctId: user.id, properties: { plan: 'pro' } }, () => handleRequest())\n * ```\n */\nexport class PostHogSpanProcessor implements SpanProcessor {\n private readonly inner: SpanProcessor\n private readonly client?: PostHogContextSource & PrivacyModeGate\n private readonly privacyMode: boolean = false\n private readonly capturedContexts = new WeakMap<ReadableSpan, CapturedContext>()\n\n constructor(options: PostHogSpanProcessorOptions) {\n const token = normalizeToken(options.projectToken)\n if (!token) {\n console.warn('[PostHogSpanProcessor] projectToken is missing or blank; the processor will be disabled.')\n this.inner = new NoopSpanProcessor()\n return\n }\n this.client = options.client\n this.privacyMode = options.privacyMode === true\n\n if (options._spanProcessor) {\n this.inner = options._spanProcessor\n } else {\n const host = new URL(normalizeHost(options.host)).origin\n const exporter = new OTLPTraceExporter({\n url: `${host}/i/v0/ai/otel`,\n headers: {\n Authorization: `Bearer ${token}`,\n },\n })\n this.inner = new BatchSpanProcessor(exporter)\n }\n }\n\n onStart(span: Span, parentContext: Context): void {\n const captured = this.client && captureContext(this.client)\n if (captured) {\n this.capturedContexts.set(span, captured)\n }\n // Forwarded unconditionally — filtering happens in onEnd. We can't filter\n // here because the span hasn't finished yet and may not have AI attributes\n // set. BatchSpanProcessor.onStart is a no-op so this is safe.\n this.inner.onStart(span, parentContext)\n }\n\n onEnd(span: ReadableSpan): void {\n const captured = this.capturedContexts.get(span)\n this.capturedContexts.delete(span)\n if (isAISpan(span)) {\n warnIfPostHogAiGatewayOtelAttributes(span.attributes)\n const contextual = captured ? withRequestContext(span, captured) : span\n const shareable = isPrivacyModeEnabled(this.client, this.privacyMode) ? stripContent(contextual) : contextual\n this.inner.onEnd(redactSpan(shareable))\n }\n }\n\n shutdown(): Promise<void> {\n return this.inner.shutdown()\n }\n\n forceFlush(): Promise<void> {\n return this.inner.forceFlush()\n }\n}\n"],"x_google_ignoreList":[11,12,13,14,15,16,17,18,19],"mappings":";;;;;AAAA,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAI3B,IAAa,mBAAb,MAA8B;CAC5B,UAAU,OAAe,WAAsC;EAC7D,MAAM,UAAU,mBAAmB,KAAK,KAAK;EAC7C,IAAI,SAAS,OAAO;GAAE,MAAM;GAAY,WAAW,QAAQ;EAAG;EAE9D,IAAI,MAAM,SAAS,WAAW,OAAO,EAAE,MAAM,OAAO;EAEpD,MAAM,mBAAmB,MAAM,MAAM,GAAG,SAAS;EACjD,IAAI,mBAAmB,KAAK,gBAAgB,GAC1C,OAAO,EAAE,MAAM,MAAM;OAErB,OAAO,EAAE,MAAM,OAAO;CAE1B;AACF;;;ACnBA,MAAM,iBAAiB;CAAC;CAAa;CAAc;CAAY;AAAW;AAE1E,MAAM,sCAAsB,IAAI,IAAI;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;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AkB;IACrC,KAAK,GAAG,KAAK;IACb,SAAS,EACP,eAAe,UAAU,QAC3B;GACF,CAAC;GACD,KAAK,QAAQ,IAAI,mBAAmB,QAAQ;EAC9C;CACF;CAEA,QAAQ,MAAY,eAA8B;EAChD,MAAM,WAAW,KAAK,UAAU,eAAe,KAAK,MAAM;EAC1D,IAAI,UACF,KAAK,iBAAiB,IAAI,MAAM,QAAQ;EAK1C,KAAK,MAAM,QAAQ,MAAM,aAAa;CACxC;CAEA,MAAM,MAA0B;EAC9B,MAAM,WAAW,KAAK,iBAAiB,IAAI,IAAI;EAC/C,KAAK,iBAAiB,OAAO,IAAI;EACjC,IAAI,SAAS,IAAI,GAAG;GAClB,qCAAqC,KAAK,UAAU;GACpD,MAAM,aAAa,WAAW,mBAAmB,MAAM,QAAQ,IAAI;GACnE,MAAM,YAAY,qBAAqB,KAAK,QAAQ,KAAK,WAAW,IAAI,aAAa,UAAU,IAAI;GACnG,KAAK,MAAM,MAAM,WAAW,SAAS,CAAC;EACxC;CACF;CAEA,WAA0B;EACxB,OAAO,KAAK,MAAM,SAAS;CAC7B;CAEA,aAA4B;EAC1B,OAAO,KAAK,MAAM,WAAW;CAC/B;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["redactJson","DEFAULT_OTEL_HOST","normalizeToken","normalizeHost"],"sources":["../../src/sanitization/base64_recognizer.ts","../../src/sanitization/media_type_context.ts","../../src/sanitization/binary_content_redactor.ts","../../src/otel/spans.ts","../../src/typeGuards.ts","../../src/mcpCredentials.ts","../../src/otel/toolDefinitions.ts","../../src/otel/redact.ts","../../src/otel/privacy.ts","../../src/gatewayWarning.ts","../../src/otel/exporter.ts","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/core/2.2.0/b871f22d07b51323f729d44d521414927172cbc0ddfdf1942304eca90488e96b/node_modules/@opentelemetry/core/build/esm/trace/suppress-tracing.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/core/2.2.0/b871f22d07b51323f729d44d521414927172cbc0ddfdf1942304eca90488e96b/node_modules/@opentelemetry/core/build/esm/common/logging-error-handler.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/core/2.2.0/b871f22d07b51323f729d44d521414927172cbc0ddfdf1942304eca90488e96b/node_modules/@opentelemetry/core/build/esm/common/global-error-handler.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/core/2.2.0/b871f22d07b51323f729d44d521414927172cbc0ddfdf1942304eca90488e96b/node_modules/@opentelemetry/core/build/esm/platform/node/environment.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/core/2.2.0/b871f22d07b51323f729d44d521414927172cbc0ddfdf1942304eca90488e96b/node_modules/@opentelemetry/core/build/esm/ExportResult.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/core/2.2.0/b871f22d07b51323f729d44d521414927172cbc0ddfdf1942304eca90488e96b/node_modules/@opentelemetry/core/build/esm/utils/promise.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/core/2.2.0/b871f22d07b51323f729d44d521414927172cbc0ddfdf1942304eca90488e96b/node_modules/@opentelemetry/core/build/esm/utils/callback.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/sdk-trace-base/2.2.0/fa825708a19b4d5944c83585f1de1744c29637446df5cfc986c5a1263b781148/node_modules/@opentelemetry/sdk-trace-base/build/esm/export/BatchSpanProcessorBase.js","../../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@opentelemetry/sdk-trace-base/2.2.0/fa825708a19b4d5944c83585f1de1744c29637446df5cfc986c5a1263b781148/node_modules/@opentelemetry/sdk-trace-base/build/esm/platform/node/export/BatchSpanProcessor.js","../../src/privacyMode.ts","../../src/otel/requestContext.ts","../../src/otel/processor.ts"],"sourcesContent":["const DATA_URL_PREFIX_RE = /^data:([^;,\\s]+)(?:;[^;,\\s]+)*;base64,/i\nconst BASE64_ALPHABET_RE = /^[A-Za-z0-9+/_=-]+$/\n\nexport type Base64Recognition = { kind: 'data-url'; mediaType: string } | { kind: 'raw' } | { kind: 'none' }\n\nexport class Base64Recognizer {\n recognize(value: string, minLength: number): Base64Recognition {\n const dataUrl = DATA_URL_PREFIX_RE.exec(value)\n if (dataUrl) return { kind: 'data-url', mediaType: dataUrl[1] }\n\n if (value.length < minLength) return { kind: 'none' }\n\n const confidencePrefix = value.slice(0, minLength)\n if (BASE64_ALPHABET_RE.test(confidencePrefix)) {\n return { kind: 'raw' }\n } else {\n return { kind: 'none' }\n }\n }\n}\n","const MIME_HINT_KEYS = ['mediaType', 'media_type', 'mimeType', 'mime_type'] as const\n\nconst STRONG_CONTEXT_KEYS = new Set([\n 'data',\n 'file_data',\n 'fileData',\n 'image_url',\n 'imageUrl',\n 'video_url',\n 'videoUrl',\n 'audio',\n 'audio_data',\n 'audioData',\n 'inline_data',\n 'inlineData',\n 'source',\n 'result',\n])\n\nconst STRONG_CONTEXT_TYPES = new Set([\n 'image',\n 'image_url',\n 'input_image',\n 'audio',\n 'input_audio',\n 'video',\n 'video_url',\n 'file',\n 'input_file',\n 'document',\n 'media',\n 'file-data',\n])\n\nconst FILE_FAMILY_TYPES = new Set(['file', 'input_file', 'document', 'media', 'file-data'])\nconst TYPED_BINARY_DATA_TYPES = new Set(['image', 'audio', 'video', 'document'])\n\nconst KNOWN_AUDIO_FORMATS = new Set(['wav', 'mp3', 'ogg', 'flac', 'm4a', 'aac', 'webm'])\n\nexport class MediaTypeContext {\n static readonly EMPTY = new MediaTypeContext(undefined, undefined)\n\n constructor(\n private readonly parent: Record<string, unknown> | undefined,\n private readonly key: string | undefined,\n private readonly explicitMediaType?: string\n ) {}\n\n inferMediaType(): string | undefined {\n return (\n this.inferFromSiblingMime() ?? this.inferFromSiblingFormat() ?? this.inferFromParentType() ?? this.inferFromKey()\n )\n }\n\n inferFromSiblingMime(): string | undefined {\n if (this.explicitMediaType) return this.explicitMediaType\n if (!this.parent) return undefined\n for (const hint of MIME_HINT_KEYS) {\n const v = this.parent[hint]\n if (typeof v === 'string') return v\n }\n return undefined\n }\n\n inferFromSiblingFormat(): string | undefined {\n if (!this.parent) return undefined\n const fmt = this.parent.format\n if (typeof fmt === 'string' && KNOWN_AUDIO_FORMATS.has(fmt.toLowerCase())) {\n return `audio/${fmt.toLowerCase()}`\n }\n return undefined\n }\n\n inferFromParentType(): string | undefined {\n if (!this.parent) return undefined\n const t = this.parent.type\n if (typeof t !== 'string') return undefined\n if (t === 'image' || t === 'image_url' || t === 'input_image') return 'image'\n if (t === 'audio' || t === 'input_audio') return 'audio'\n if (t === 'video' || t === 'video_url') return 'video'\n if (FILE_FAMILY_TYPES.has(t)) return 'application/octet-stream'\n return undefined\n }\n\n inferFromKey(): string | undefined {\n if (!this.key) return undefined\n const key = this.key.toLowerCase()\n if (key.includes('audio')) return 'audio'\n if (key.includes('video')) return 'video'\n if (key.includes('image')) return 'image'\n if (key.includes('file') || key.includes('document')) return 'application/octet-stream'\n return undefined\n }\n\n hasDefiniteBinaryData(): boolean {\n if (\n this.parent &&\n this.key === 'data' &&\n typeof this.parent.type === 'string' &&\n TYPED_BINARY_DATA_TYPES.has(this.parent.type)\n )\n return true\n if (!this.explicitMediaType && (!this.parent || !this.key || !STRONG_CONTEXT_KEYS.has(this.key))) return false\n const mediaType = this.inferFromSiblingMime()\n return mediaType !== undefined && !mediaType.toLowerCase().startsWith('text/')\n }\n\n signalsBinary(): boolean {\n if (this.explicitMediaType) return true\n if (this.parent) {\n for (const hint of MIME_HINT_KEYS) {\n if (typeof this.parent[hint] === 'string') return true\n }\n const fmt = this.parent.format\n if (typeof fmt === 'string' && KNOWN_AUDIO_FORMATS.has(fmt.toLowerCase())) return true\n const t = this.parent.type\n if (typeof t === 'string' && STRONG_CONTEXT_TYPES.has(t)) return true\n }\n if (this.key && STRONG_CONTEXT_KEYS.has(this.key)) return true\n return false\n }\n}\n","import { Base64Recognizer } from './base64_recognizer'\nimport { MediaTypeContext } from './media_type_context'\n\nconst STRONG_CONTEXT_MIN_LENGTH = 64\nconst WEAK_CONTEXT_MIN_LENGTH = 1024\nconst MAX_NODES = 10_000\nconst TRUNCATED = '[Truncated]'\n\nexport class BinaryContentRedactor {\n private ancestors: WeakSet<object> = new WeakSet()\n private remainingNodes = MAX_NODES\n\n constructor(private readonly recognizer: Base64Recognizer = new Base64Recognizer()) {}\n\n redact<T>(value: T, mediaType?: string): T\n redact(value: unknown, mediaType?: string): unknown {\n this.ancestors = new WeakSet()\n this.remainingNodes = MAX_NODES\n return this.walk(value, mediaType ? new MediaTypeContext(undefined, undefined, mediaType) : MediaTypeContext.EMPTY)\n }\n\n /** Redact one leaf while a caller owns bounded, type-preserving traversal. @internal */\n redactLeaf(value: string | Uint8Array, context: MediaTypeContext): string {\n return typeof value === 'string' ? this.redactString(value, context) : this.placeholderFor(context.inferMediaType())\n }\n\n private walk(value: unknown, ctx: MediaTypeContext): unknown {\n if (value === null || value === undefined) return value\n if (typeof value === 'string') return this.redactLeaf(value, ctx)\n if (typeof value !== 'object') return value\n\n // Buffer extends Uint8Array, so this branch catches both.\n if (typeof Uint8Array !== 'undefined' && value instanceof Uint8Array) {\n return this.redactLeaf(value, ctx)\n }\n\n if (this.ancestors.has(value)) return null\n // Shared references are walked once per path, so the unfolded tree can be exponentially larger than the input.\n if (this.remainingNodes <= 0) return TRUNCATED\n this.remainingNodes--\n this.ancestors.add(value)\n try {\n if (Array.isArray(value)) {\n return value.map((item) => this.walk(item, ctx))\n }\n\n const obj = value as Record<string, unknown>\n const out: Record<string, unknown> = {}\n for (const k of Object.keys(obj)) {\n Object.defineProperty(out, k, {\n value: this.walk(obj[k], new MediaTypeContext(obj, k)),\n enumerable: true,\n writable: true,\n configurable: true,\n })\n }\n return out\n } finally {\n this.ancestors.delete(value)\n }\n }\n\n private redactString(value: string, ctx: MediaTypeContext): string {\n const hasDefiniteBinaryData = ctx.hasDefiniteBinaryData()\n const recognitionValue = hasDefiniteBinaryData ? value.replace(/[\\r\\n]/g, '') : value\n const minLength = hasDefiniteBinaryData\n ? Math.min(recognitionValue.length, STRONG_CONTEXT_MIN_LENGTH)\n : ctx.signalsBinary()\n ? STRONG_CONTEXT_MIN_LENGTH\n : WEAK_CONTEXT_MIN_LENGTH\n const recognition = this.recognizer.recognize(recognitionValue, minLength)\n switch (recognition.kind) {\n case 'data-url':\n return this.placeholderFor(recognition.mediaType)\n case 'raw':\n return this.placeholderFor(ctx.inferMediaType())\n case 'none':\n return value\n }\n }\n\n private placeholderFor(mediaType?: string): string {\n if (!mediaType) return '[base64 redacted]'\n if (mediaType === 'application/octet-stream') return '[base64 file redacted]'\n return `[base64 ${mediaType} redacted]`\n }\n}\n","import type { Attributes } from '@opentelemetry/api'\nimport type { ReadableSpan, TimedEvent } from './types'\n\nconst AI_SPAN_PREFIXES = ['gen_ai.', 'llm.', 'ai.', 'traceloop.'] as const\n\n/**\n * Returns `true` when the span is AI-related — its name or any attribute\n * key starts with `gen_ai.`, `llm.`, `ai.`, or `traceloop.`.\n */\nexport function isAISpan(span: ReadableSpan): boolean {\n if (AI_SPAN_PREFIXES.some((prefix) => span.name.startsWith(prefix))) {\n return true\n }\n const attributes = span.attributes\n if (attributes) {\n return Object.keys(attributes).some((key) => AI_SPAN_PREFIXES.some((prefix) => key.startsWith(prefix)))\n }\n return false\n}\n\n/** Copies rather than mutates: the span is shared across every registered processor/exporter. */\nexport function withAttributes(span: ReadableSpan, attributes: Attributes, events?: TimedEvent[]): ReadableSpan {\n return Object.create(span, {\n attributes: { value: attributes, enumerable: true, configurable: true },\n ...(events ? { events: { value: events, enumerable: true, configurable: true } } : {}),\n })\n}\n","// Type guards for safer type checking\n\nexport const isString = (value: unknown): value is string => {\n return typeof value === 'string'\n}\n\nexport const isObject = (value: unknown): value is Record<string, unknown> => {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n","import { isObject } from './typeGuards'\n\nconst MCP_CREDENTIAL_FIELDS = ['headers', 'authorization']\n\n// Vercel AI SDK provider tools that configure a remote MCP server, keyed by their `id`.\nconst MCP_PROVIDER_TOOL_IDS = new Set(['openai.mcp', 'xai.mcp', 'google.mcp_server'])\n\nconst isMcpProviderTool = (tool: Record<string, unknown>): boolean =>\n (tool.type === 'provider' || tool.type === 'provider-defined') &&\n typeof tool.id === 'string' &&\n MCP_PROVIDER_TOOL_IDS.has(tool.id)\n\nconst withoutMcpCredentials = (config: Record<string, unknown>): Record<string, unknown> => {\n const redacted: Record<string, unknown> = { ...config }\n for (const field of MCP_CREDENTIAL_FIELDS) {\n if (field in redacted) {\n redacted[field] = '[REDACTED]'\n }\n }\n return redacted\n}\n\n/** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */\nexport function redactMcpToolDefinition(tool: unknown): unknown {\n if (!isObject(tool)) {\n return tool\n }\n if (tool.type === 'mcp') {\n return withoutMcpCredentials(tool)\n }\n if (isMcpProviderTool(tool) && isObject(tool.args)) {\n return { ...tool, args: withoutMcpCredentials(tool.args) }\n }\n return tool\n}\n\nexport function redactMcpToolCredentials(tools: unknown): unknown {\n return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools\n}\n","import type { AttributeValue } from '@opentelemetry/api'\n\nimport { redactMcpToolCredentials, redactMcpToolDefinition } from '../mcpCredentials'\n\n// Instrumentations serialize tool definitions, remote MCP tools and their credentials included,\n// as a JSON array, an array of JSON tools, or one JSON tool per attribute.\nconst TOOL_DEFINITION_ATTRIBUTES = new Set(['gen_ai.tool.definitions', 'ai.prompt.tools'])\nconst TOOL_DEFINITION_PATTERN = /^llm\\.tools\\.\\d+\\.tool\\.json_schema$/\n\nexport const isToolDefinitionAttribute = (key: string): boolean =>\n TOOL_DEFINITION_ATTRIBUTES.has(key) || TOOL_DEFINITION_PATTERN.test(key)\n\nconst parseToolDefinitionJson = (value: string): object | undefined => {\n try {\n const parsed: unknown = JSON.parse(value)\n return parsed !== null && typeof parsed === 'object' ? parsed : undefined\n } catch {\n return undefined\n }\n}\n\nconst redactJson = (value: string): string => {\n const parsed = parseToolDefinitionJson(value)\n if (parsed === undefined) {\n return value\n }\n const redacted = JSON.stringify(\n Array.isArray(parsed) ? redactMcpToolCredentials(parsed) : redactMcpToolDefinition(parsed)\n )\n return redacted === JSON.stringify(parsed) ? value : redacted\n}\n\n/** Replaces MCP credentials in a tool definition attribute; values that are not JSON are kept as is. */\nexport function redactToolDefinitionCredentials(value: AttributeValue): AttributeValue {\n if (typeof value === 'string') {\n return redactJson(value)\n }\n if (Array.isArray(value) && value.every((item) => typeof item === 'string' || item == null)) {\n const redacted = value.map((item) => (typeof item === 'string' ? redactJson(item) : item))\n return redacted.some((item, index) => item !== value[index]) ? redacted : value\n }\n return value\n}\n\n/** Drops the parts of a tool definition attribute that are not JSON, since their credentials cannot be found. */\nexport function withoutUnparseableToolDefinitions(value: AttributeValue): AttributeValue | undefined {\n if (typeof value === 'string') {\n return parseToolDefinitionJson(value) === undefined ? undefined : value\n }\n if (Array.isArray(value)) {\n return value.filter(\n (item): item is string => typeof item === 'string' && parseToolDefinitionJson(item) !== undefined\n )\n }\n return undefined\n}\n","import type { Attributes, AttributeValue } from '@opentelemetry/api'\nimport type { ReadableSpan, TimedEvent } from './types'\n\nimport { BinaryContentRedactor } from '../sanitization/binary_content_redactor'\nimport { withAttributes } from './spans'\nimport { isToolDefinitionAttribute, redactToolDefinitionCredentials } from './toolDefinitions'\n\n// Deliberately always redacts here — the OTLP export path has no per-client passthrough gate.\nconst redactor = new BinaryContentRedactor()\n\nexport function redactSpan(span: ReadableSpan): ReadableSpan {\n const attributes = span.attributes ? redactAttributes(span.attributes) : span.attributes\n const events = span.events ? redactEvents(span.events) : span.events\n if (attributes === span.attributes && events === span.events) {\n return span\n }\n return withAttributes(span, attributes, events)\n}\n\nfunction redactAttributes(attributes: Attributes): Attributes {\n let changed = false\n const out: Attributes = {}\n for (const key of Object.keys(attributes)) {\n const original = attributes[key]\n const value =\n original !== undefined && isToolDefinitionAttribute(key) ? redactToolDefinitionCredentials(original) : original\n const redacted = value === undefined ? value : redactAttributeValue(value)\n if (redacted !== original) {\n changed = true\n }\n out[key] = redacted\n }\n return changed ? out : attributes\n}\n\nfunction redactEvents(events: TimedEvent[]): TimedEvent[] {\n let changed = false\n const out = events.map((event) => {\n if (!event.attributes) {\n return event\n }\n const attributes = redactAttributes(event.attributes)\n if (attributes === event.attributes) {\n return event\n }\n changed = true\n return { ...event, attributes }\n })\n return changed ? out : events\n}\n\nfunction redactAttributeValue(value: AttributeValue): AttributeValue {\n if (typeof value === 'string') {\n return redactString(value)\n }\n if (isStringArray(value)) {\n let changed = false\n const out = value.map((item) => {\n if (typeof item !== 'string') {\n return item\n }\n const redacted = redactString(item)\n if (redacted !== item) {\n changed = true\n }\n return redacted\n })\n return changed ? out : value\n }\n return value\n}\n\nfunction isStringArray(value: AttributeValue): value is Array<string | null | undefined> {\n return Array.isArray(value) && value.every((item) => typeof item !== 'number' && typeof item !== 'boolean')\n}\n\nfunction redactString(value: string): string {\n const trimmed = value.trimStart()\n if (trimmed.startsWith('{') || trimmed.startsWith('[')) {\n const redacted = redactJson(value)\n if (redacted !== undefined) {\n return redacted\n }\n }\n return redactor.redact(value)\n}\n\nfunction redactJson(value: string): string | undefined {\n let parsed: unknown\n try {\n parsed = JSON.parse(value)\n } catch {\n return undefined\n }\n if (parsed === null || typeof parsed !== 'object') {\n return undefined\n }\n const redactedStr = JSON.stringify(redactor.redact(parsed))\n // Preserve the original string (and its formatting) when nothing was redacted.\n return redactedStr === JSON.stringify(parsed) ? value : redactedStr\n}\n","import type { Attributes } from '@opentelemetry/api'\nimport type { ReadableSpan, TimedEvent } from './types'\n\nimport { withAttributes } from './spans'\nimport { isToolDefinitionAttribute, withoutUnparseableToolDefinitions } from './toolDefinitions'\n\n// Every attribute PostHog ingestion turns into prompt, output, tool call or error text. Ingestion\n// keeps unmapped attributes as event properties, so this also covers attributes it does not map.\nconst CONTENT_ATTRIBUTES = new Set([\n // Vercel AI SDK\n 'ai.prompt',\n 'ai.prompt.messages',\n 'ai.response.text',\n 'ai.response.object',\n 'ai.response.toolCalls',\n 'ai.response.reasoning',\n 'ai.response.reasoningDetails',\n 'ai.response.files',\n 'ai.toolCall.args',\n 'ai.toolCall.result',\n 'ai.value',\n 'ai.values',\n 'ai.embedding',\n 'ai.embeddings',\n 'ai.documents',\n 'ai.request.text',\n 'ai.decision.state',\n 'ai.decision.questions',\n 'ai.decision.answers',\n // OpenTelemetry GenAI semantic conventions\n 'gen_ai.input.messages',\n 'gen_ai.output.messages',\n 'gen_ai.system_instructions',\n 'gen_ai.prompt',\n 'gen_ai.completion',\n 'gen_ai.tool.call.arguments',\n 'gen_ai.tool.call.result',\n 'gen_ai.retrieval.documents',\n 'gen_ai.retrieval.query.text',\n 'gen_ai.memory.query.text',\n 'gen_ai.memory.records',\n 'gen_ai.evaluation.explanation',\n // Traceloop / OpenLLMetry\n 'traceloop.entity.input',\n 'traceloop.entity.output',\n 'traceloop.prompt.template',\n 'gen_ai.task.input',\n 'gen_ai.task.output',\n 'gen_ai.guardrail.input',\n 'gen_ai.guardrail.output',\n 'gen_ai.guardrail.error.message',\n 'gen_ai.response.revised_prompt',\n 'mcp.response.value',\n 'db.marqo.search.query',\n // Anthropic\n 'anthropic.tool_result.content',\n // Pydantic AI / Logfire\n 'pydantic_ai.all_messages',\n 'final_result',\n 'tool_arguments',\n 'tool_response',\n 'events',\n 'model_request_parameters',\n 'inputs',\n 'prompt',\n // OpenInference\n 'input.value',\n 'output.value',\n 'llm.function_call',\n 'llm.prompt_template.template',\n 'llm.prompt_template.variables',\n // Holds request parameters such as Responses `instructions`.\n 'llm.invocation_parameters',\n 'reranker.query',\n // Langfuse\n 'langfuse.trace.input',\n 'langfuse.trace.output',\n 'langfuse.observation.input',\n 'langfuse.observation.output',\n 'langfuse.observation.status_message',\n 'langfuse.experiment.item.expected_output',\n // Errors\n 'exception.message',\n 'exception.stacktrace',\n 'error.message',\n])\n\nconst CONTENT_ATTRIBUTE_PREFIXES = [\n 'gen_ai.prompt.',\n 'gen_ai.completion.',\n 'llm.prompts.',\n 'llm.completions.',\n 'llm.input_messages.',\n 'llm.output_messages.',\n 'llm.choices.',\n 'traceloop.prompt.template_variables.',\n]\n\nconst CONTENT_ATTRIBUTE_PATTERNS = [\n /^db\\.chroma\\.(query|get|delete)\\.where_document$/,\n /^embedding\\.embeddings\\.\\d+\\.embedding\\.(text|vector)$/,\n /^retrieval\\.documents\\.\\d+\\.document\\.(content|metadata)$/,\n /^reranker\\.(input|output)_documents\\.\\d+\\.document\\.content$/,\n /^(input|output)\\.images\\.\\d+\\.image\\.url$/,\n /^mastra\\.[a-z_]+\\.(input|output)$/,\n]\n\n// Prompt management metadata that shares the `gen_ai.prompt.` prefix with prompt content.\nconst NON_CONTENT_ATTRIBUTES = new Set(['gen_ai.prompt.name', 'gen_ai.prompt.version'])\n\n// Ingestion only reads exception events. Every other event (GenAI semconv messages, vector\n// database results, framework logs) can carry content.\nconst EXCEPTION_EVENT_NAME = 'exception'\n\nconst PROVIDER_METADATA_ATTRIBUTE = 'ai.response.providerMetadata'\n\nconst isContentAttribute = (key: string): boolean =>\n !NON_CONTENT_ATTRIBUTES.has(key) &&\n (CONTENT_ATTRIBUTES.has(key) ||\n CONTENT_ATTRIBUTE_PREFIXES.some((prefix) => key.startsWith(prefix) || prefix === `${key}.`) ||\n CONTENT_ATTRIBUTE_PATTERNS.some((pattern) => pattern.test(key)))\n\n// Provider metadata can carry content, such as Google grounding search queries. Ingestion only\n// reads the Vercel AI Gateway cost from it.\nfunction gatewayCostOnly(value: unknown): string | undefined {\n if (typeof value !== 'string') {\n return undefined\n }\n try {\n const cost: unknown = JSON.parse(value)?.gateway?.cost\n return typeof cost === 'number' || typeof cost === 'string' ? JSON.stringify({ gateway: { cost } }) : undefined\n } catch {\n return undefined\n }\n}\n\nfunction stripAttributes(attributes: Attributes): Attributes {\n const out: Attributes = {}\n for (const [key, value] of Object.entries(attributes)) {\n if (isContentAttribute(key)) {\n continue\n }\n if (isToolDefinitionAttribute(key)) {\n const definitions = value === undefined ? undefined : withoutUnparseableToolDefinitions(value)\n if (definitions !== undefined) {\n out[key] = definitions\n }\n continue\n }\n if (key === PROVIDER_METADATA_ATTRIBUTE) {\n const metadata = gatewayCostOnly(value)\n if (metadata !== undefined) {\n out[key] = metadata\n }\n continue\n }\n out[key] = value\n }\n return out\n}\n\nfunction stripEvents(events: TimedEvent[]): TimedEvent[] {\n return events\n .filter((event) => event.name === EXCEPTION_EVENT_NAME)\n .map((event) => (event.attributes ? { ...event, attributes: stripAttributes(event.attributes) } : event))\n}\n\n/** Returns a copy of the span without the attributes, events and status message that carry content. */\nexport function stripContent(span: ReadableSpan): ReadableSpan {\n const stripped = withAttributes(\n span,\n span.attributes ? stripAttributes(span.attributes) : span.attributes,\n span.events ? stripEvents(span.events) : span.events\n )\n if (span.status?.message) {\n Object.defineProperty(stripped, 'status', {\n value: { code: span.status.code },\n enumerable: true,\n configurable: true,\n })\n }\n return stripped\n}\n","// Warn when a wrapper's base_url points at the PostHog AI Gateway: the gateway\n// emits its own $ai_generation, so each call would be captured (and, for billable\n// products, billed) twice. We only warn — the wrapper's event carries data the\n// gateway never sees (groups, custom properties, trace hierarchy).\n\n// Keep in sync with the gateway's deployed hosts (see services/llm-gateway in the\n// main repo). gateway.us.posthog.com is live today; the rest are listed ahead of\n// any traffic moving to them.\nexport const POSTHOG_AI_GATEWAY_HOSTS: readonly string[] = [\n 'gateway.posthog.com',\n 'gateway.us.posthog.com',\n 'gateway.eu.posthog.com',\n 'ai-gateway.us.posthog.com',\n 'ai-gateway.eu.posthog.com',\n]\n\n// Swap for the dedicated AI Gateway page once it ships.\nconst GATEWAY_DOCS_URL = 'https://posthog.com/docs/ai-observability'\n\nconst extractHost = (baseURL: string): string | undefined => {\n try {\n // Tolerate bare hosts that omit a scheme, e.g. \"gateway.us.posthog.com/v1\".\n const hasScheme = /^[a-z][a-z0-9+.-]*:\\/\\//i.test(baseURL)\n return new URL(hasScheme ? baseURL : `https://${baseURL}`).hostname.toLowerCase()\n } catch {\n return undefined\n }\n}\n\nexport const isPostHogAiGatewayUrl = (baseURL: string | undefined | null): boolean => {\n if (!baseURL) {\n return false\n }\n const host = extractHost(baseURL)\n return host !== undefined && POSTHOG_AI_GATEWAY_HOSTS.includes(host)\n}\n\n// Warns on every gateway call by design: the misconfiguration is impossible to\n// miss that way, and a doubled bill is worse than noisy logs.\nexport const warnIfPostHogAiGateway = (baseURL: string | undefined | null): void => {\n if (!isPostHogAiGatewayUrl(baseURL)) {\n return\n }\n console.warn(\n '[PostHog] The PostHog AI wrapper is pointed at the PostHog AI Gateway. ' +\n 'Both capture $ai_generation, so every call is double-counted and double-billed. ' +\n `Use one or the other — see ${GATEWAY_DOCS_URL}.`\n )\n}\n\n// OTel spans don't pass through captureAiGeneration, so detect the gateway from\n// the span's host/URL attributes instead. These follow the GenAI / HTTP semantic\n// conventions: `server.address` is a bare host, `url.full` a full URL, both of\n// which isPostHogAiGatewayUrl accepts.\nconst OTEL_GATEWAY_URL_ATTRIBUTES = ['server.address', 'url.full'] as const\n\nexport const warnIfPostHogAiGatewayOtelAttributes = (attributes: Record<string, unknown> | undefined): void => {\n if (!attributes) {\n return\n }\n for (const key of OTEL_GATEWAY_URL_ATTRIBUTES) {\n const value = attributes[key]\n if (typeof value === 'string' && isPostHogAiGatewayUrl(value)) {\n warnIfPostHogAiGateway(value)\n return\n }\n }\n}\n","import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'\nimport type { ReadableSpan } from './types'\n\nimport { redactSpan } from './redact'\nimport { stripContent } from './privacy'\nimport { isAISpan } from './spans'\nimport { warnIfPostHogAiGatewayOtelAttributes } from '../gatewayWarning'\n\nconst DEFAULT_OTEL_HOST = 'https://us.i.posthog.com'\n// OpenTelemetry's ExportResultCode.SUCCESS is 0. Keep this local so loading the\n// published subpath does not require the exporter package's transitive dependencies.\nconst EXPORT_SUCCESS = 0\n\nfunction normalizeToken(value?: unknown): string {\n return typeof value === 'string' ? value.trim() : ''\n}\n\nfunction normalizeHost(value?: unknown): string {\n const normalizedValue = typeof value === 'string' ? value.trim() : ''\n return normalizedValue || DEFAULT_OTEL_HOST\n}\n\n/**\n * Options for the PostHogTraceExporter. `projectToken` is required; a blank token disables the\n * exporter as a defensive no-op. You can also optionally override the `host` URL. `host` defaults to `https://us.i.posthog.com`.\n *\n * @example\n * ```ts\n * import { PostHogTraceExporter } from '@posthog/ai/otel'\n *\n * new PostHogTraceExporter({ projectToken: 'phc_...' })\n * ```\n *\n * @example\n * ```ts\n * import { PostHogTraceExporter } from '@posthog/ai/otel'\n *\n * new PostHogTraceExporter({ projectToken: 'phc_...', host: 'https://eu.i.posthog.com' })\n * ```\n */\nexport type PostHogTraceExporterOptions = {\n projectToken: string\n host?: string\n /** Drop prompts, outputs, tool arguments and results, and error messages from exported spans. Defaults to false. */\n privacyMode?: boolean\n}\n\n/**\n * An OpenTelemetry `TraceExporter` that sends AI traces to PostHog's OTLP\n * ingestion endpoint. PostHog converts `gen_ai.*` spans into\n * `$ai_generation` events server-side.\n *\n * Only AI-related spans (those whose name or attribute keys start with\n * `gen_ai.`, `llm.`, `ai.`, or `traceloop.`) are exported; all other\n * spans are silently dropped.\n *\n * Use this when the API you're integrating with only accepts a\n * `TraceExporter` (e.g. Vercel's `registerOTel`) or when you need to\n * plug PostHog into an existing processor chain. Otherwise prefer\n * {@link PostHogSpanProcessor}, which is self-contained.\n *\n * `projectToken` is required; a blank token disables the exporter as a defensive no-op.\n * You can also optionally override the `host` URL.\n *\n * Exporters only see finished spans, so they can't add per-request PostHog context;\n * use {@link PostHogSpanProcessor} with `client` for that.\n *\n * @example\n * ```ts\n * import { PostHogTraceExporter } from '@posthog/ai/otel'\n * import { registerOTel } from '@vercel/otel'\n *\n * registerOTel({\n * serviceName: 'my-app',\n * traceExporter: new PostHogTraceExporter({ projectToken: 'phc_...' }),\n * })\n * ```\n */\nexport class PostHogTraceExporter extends OTLPTraceExporter {\n private readonly disabled: boolean\n private readonly privacyMode: boolean\n\n constructor(options: PostHogTraceExporterOptions) {\n const token = normalizeToken(options.projectToken)\n const disabled = !token\n const host = token ? new URL(normalizeHost(options.host)).origin : DEFAULT_OTEL_HOST\n super({\n url: `${host}/i/v0/ai/otel`,\n headers: token\n ? {\n Authorization: `Bearer ${token}`,\n }\n : {},\n })\n\n this.disabled = disabled\n this.privacyMode = options.privacyMode === true\n if (this.disabled) {\n console.warn('[PostHogTraceExporter] projectToken is missing or blank; the exporter will be disabled.')\n }\n }\n\n override export(spans: ReadableSpan[], resultCallback: (result: { code: number; error?: Error }) => void): void {\n if (this.disabled) {\n // Intentionally report success: missing or blank tokens disable exporting as a compatibility no-op.\n // Reporting failure would make OpenTelemetry treat every span as an export error.\n resultCallback({ code: EXPORT_SUCCESS })\n return\n }\n\n const aiSpans = spans.filter(isAISpan)\n if (aiSpans.length === 0) {\n resultCallback({ code: EXPORT_SUCCESS })\n return\n }\n for (const span of aiSpans) {\n warnIfPostHogAiGatewayOtelAttributes(span.attributes)\n }\n const shareable = this.privacyMode ? aiSpans.map(stripContent) : aiSpans\n super.export(shareable.map(redactSpan), resultCallback)\n }\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createContextKey } from '@opentelemetry/api';\nconst SUPPRESS_TRACING_KEY = createContextKey('OpenTelemetry SDK Context Key SUPPRESS_TRACING');\nexport function suppressTracing(context) {\n return context.setValue(SUPPRESS_TRACING_KEY, true);\n}\nexport function unsuppressTracing(context) {\n return context.deleteValue(SUPPRESS_TRACING_KEY);\n}\nexport function isTracingSuppressed(context) {\n return context.getValue(SUPPRESS_TRACING_KEY) === true;\n}\n//# sourceMappingURL=suppress-tracing.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { diag } from '@opentelemetry/api';\n/**\n * Returns a function that logs an error using the provided logger, or a\n * console logger if one was not provided.\n */\nexport function loggingErrorHandler() {\n return (ex) => {\n diag.error(stringifyException(ex));\n };\n}\n/**\n * Converts an exception into a string representation\n * @param {Exception} ex\n */\nfunction stringifyException(ex) {\n if (typeof ex === 'string') {\n return ex;\n }\n else {\n return JSON.stringify(flattenException(ex));\n }\n}\n/**\n * Flattens an exception into key-value pairs by traversing the prototype chain\n * and coercing values to strings. Duplicate properties will not be overwritten;\n * the first insert wins.\n */\nfunction flattenException(ex) {\n const result = {};\n let current = ex;\n while (current !== null) {\n Object.getOwnPropertyNames(current).forEach(propertyName => {\n if (result[propertyName])\n return;\n const value = current[propertyName];\n if (value) {\n result[propertyName] = String(value);\n }\n });\n current = Object.getPrototypeOf(current);\n }\n return result;\n}\n//# sourceMappingURL=logging-error-handler.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { loggingErrorHandler } from './logging-error-handler';\n/** The global error handler delegate */\nlet delegateHandler = loggingErrorHandler();\n/**\n * Set the global error handler\n * @param {ErrorHandler} handler\n */\nexport function setGlobalErrorHandler(handler) {\n delegateHandler = handler;\n}\n/**\n * Return the global error handler\n * @param {Exception} ex\n */\nexport function globalErrorHandler(ex) {\n try {\n delegateHandler(ex);\n }\n catch { } // eslint-disable-line no-empty\n}\n//# sourceMappingURL=global-error-handler.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { diag } from '@opentelemetry/api';\nimport { inspect } from 'util';\n/**\n * Retrieves a number from an environment variable.\n * - Returns `undefined` if the environment variable is empty, unset, contains only whitespace, or is not a number.\n * - Returns a number in all other cases.\n *\n * @param {string} key - The name of the environment variable to retrieve.\n * @returns {number | undefined} - The number value or `undefined`.\n */\nexport function getNumberFromEnv(key) {\n const raw = process.env[key];\n if (raw == null || raw.trim() === '') {\n return undefined;\n }\n const value = Number(raw);\n if (isNaN(value)) {\n diag.warn(`Unknown value ${inspect(raw)} for ${key}, expected a number, using defaults`);\n return undefined;\n }\n return value;\n}\n/**\n * Retrieves a string from an environment variable.\n * - Returns `undefined` if the environment variable is empty, unset, or contains only whitespace.\n *\n * @param {string} key - The name of the environment variable to retrieve.\n * @returns {string | undefined} - The string value or `undefined`.\n */\nexport function getStringFromEnv(key) {\n const raw = process.env[key];\n if (raw == null || raw.trim() === '') {\n return undefined;\n }\n return raw;\n}\n/**\n * Retrieves a boolean value from an environment variable.\n * - Trims leading and trailing whitespace and ignores casing.\n * - Returns `false` if the environment variable is empty, unset, or contains only whitespace.\n * - Returns `false` for strings that cannot be mapped to a boolean.\n *\n * @param {string} key - The name of the environment variable to retrieve.\n * @returns {boolean} - The boolean value or `false` if the environment variable is unset empty, unset, or contains only whitespace.\n */\nexport function getBooleanFromEnv(key) {\n const raw = process.env[key]?.trim().toLowerCase();\n if (raw == null || raw === '') {\n // NOTE: falling back to `false` instead of `undefined` as required by the specification.\n // If you have a use-case that requires `undefined`, consider using `getStringFromEnv()` and applying the necessary\n // normalizations in the consuming code.\n return false;\n }\n if (raw === 'true') {\n return true;\n }\n else if (raw === 'false') {\n return false;\n }\n else {\n diag.warn(`Unknown value ${inspect(raw)} for ${key}, expected 'true' or 'false', falling back to 'false' (default)`);\n return false;\n }\n}\n/**\n * Retrieves a list of strings from an environment variable.\n * - Uses ',' as the delimiter.\n * - Trims leading and trailing whitespace from each entry.\n * - Excludes empty entries.\n * - Returns `undefined` if the environment variable is empty or contains only whitespace.\n * - Returns an empty array if all entries are empty or whitespace.\n *\n * @param {string} key - The name of the environment variable to retrieve.\n * @returns {string[] | undefined} - The list of strings or `undefined`.\n */\nexport function getStringListFromEnv(key) {\n return getStringFromEnv(key)\n ?.split(',')\n .map(v => v.trim())\n .filter(s => s !== '');\n}\n//# sourceMappingURL=environment.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport var ExportResultCode;\n(function (ExportResultCode) {\n ExportResultCode[ExportResultCode[\"SUCCESS\"] = 0] = \"SUCCESS\";\n ExportResultCode[ExportResultCode[\"FAILED\"] = 1] = \"FAILED\";\n})(ExportResultCode || (ExportResultCode = {}));\n//# sourceMappingURL=ExportResult.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport class Deferred {\n _promise;\n _resolve;\n _reject;\n constructor() {\n this._promise = new Promise((resolve, reject) => {\n this._resolve = resolve;\n this._reject = reject;\n });\n }\n get promise() {\n return this._promise;\n }\n resolve(val) {\n this._resolve(val);\n }\n reject(err) {\n this._reject(err);\n }\n}\n//# sourceMappingURL=promise.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Deferred } from './promise';\n/**\n * Bind the callback and only invoke the callback once regardless how many times `BindOnceFuture.call` is invoked.\n */\nexport class BindOnceFuture {\n _callback;\n _that;\n _isCalled = false;\n _deferred = new Deferred();\n constructor(_callback, _that) {\n this._callback = _callback;\n this._that = _that;\n }\n get isCalled() {\n return this._isCalled;\n }\n get promise() {\n return this._deferred.promise;\n }\n call(...args) {\n if (!this._isCalled) {\n this._isCalled = true;\n try {\n Promise.resolve(this._callback.call(this._that, ...args)).then(val => this._deferred.resolve(val), err => this._deferred.reject(err));\n }\n catch (err) {\n this._deferred.reject(err);\n }\n }\n return this._deferred.promise;\n }\n}\n//# sourceMappingURL=callback.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { context, diag, TraceFlags } from '@opentelemetry/api';\nimport { BindOnceFuture, ExportResultCode, getNumberFromEnv, globalErrorHandler, suppressTracing, } from '@opentelemetry/core';\n/**\n * Implementation of the {@link SpanProcessor} that batches spans exported by\n * the SDK then pushes them to the exporter pipeline.\n */\nexport class BatchSpanProcessorBase {\n _exporter;\n _maxExportBatchSize;\n _maxQueueSize;\n _scheduledDelayMillis;\n _exportTimeoutMillis;\n _isExporting = false;\n _finishedSpans = [];\n _timer;\n _shutdownOnce;\n _droppedSpansCount = 0;\n constructor(_exporter, config) {\n this._exporter = _exporter;\n this._maxExportBatchSize =\n typeof config?.maxExportBatchSize === 'number'\n ? config.maxExportBatchSize\n : (getNumberFromEnv('OTEL_BSP_MAX_EXPORT_BATCH_SIZE') ?? 512);\n this._maxQueueSize =\n typeof config?.maxQueueSize === 'number'\n ? config.maxQueueSize\n : (getNumberFromEnv('OTEL_BSP_MAX_QUEUE_SIZE') ?? 2048);\n this._scheduledDelayMillis =\n typeof config?.scheduledDelayMillis === 'number'\n ? config.scheduledDelayMillis\n : (getNumberFromEnv('OTEL_BSP_SCHEDULE_DELAY') ?? 5000);\n this._exportTimeoutMillis =\n typeof config?.exportTimeoutMillis === 'number'\n ? config.exportTimeoutMillis\n : (getNumberFromEnv('OTEL_BSP_EXPORT_TIMEOUT') ?? 30000);\n this._shutdownOnce = new BindOnceFuture(this._shutdown, this);\n if (this._maxExportBatchSize > this._maxQueueSize) {\n diag.warn('BatchSpanProcessor: maxExportBatchSize must be smaller or equal to maxQueueSize, setting maxExportBatchSize to match maxQueueSize');\n this._maxExportBatchSize = this._maxQueueSize;\n }\n }\n forceFlush() {\n if (this._shutdownOnce.isCalled) {\n return this._shutdownOnce.promise;\n }\n return this._flushAll();\n }\n // does nothing.\n onStart(_span, _parentContext) { }\n onEnd(span) {\n if (this._shutdownOnce.isCalled) {\n return;\n }\n if ((span.spanContext().traceFlags & TraceFlags.SAMPLED) === 0) {\n return;\n }\n this._addToBuffer(span);\n }\n shutdown() {\n return this._shutdownOnce.call();\n }\n _shutdown() {\n return Promise.resolve()\n .then(() => {\n return this.onShutdown();\n })\n .then(() => {\n return this._flushAll();\n })\n .then(() => {\n return this._exporter.shutdown();\n });\n }\n /** Add a span in the buffer. */\n _addToBuffer(span) {\n if (this._finishedSpans.length >= this._maxQueueSize) {\n // limit reached, drop span\n if (this._droppedSpansCount === 0) {\n diag.debug('maxQueueSize reached, dropping spans');\n }\n this._droppedSpansCount++;\n return;\n }\n if (this._droppedSpansCount > 0) {\n // some spans were dropped, log once with count of spans dropped\n diag.warn(`Dropped ${this._droppedSpansCount} spans because maxQueueSize reached`);\n this._droppedSpansCount = 0;\n }\n this._finishedSpans.push(span);\n this._maybeStartTimer();\n }\n /**\n * Send all spans to the exporter respecting the batch size limit\n * This function is used only on forceFlush or shutdown,\n * for all other cases _flush should be used\n * */\n _flushAll() {\n return new Promise((resolve, reject) => {\n const promises = [];\n // calculate number of batches\n const count = Math.ceil(this._finishedSpans.length / this._maxExportBatchSize);\n for (let i = 0, j = count; i < j; i++) {\n promises.push(this._flushOneBatch());\n }\n Promise.all(promises)\n .then(() => {\n resolve();\n })\n .catch(reject);\n });\n }\n _flushOneBatch() {\n this._clearTimer();\n if (this._finishedSpans.length === 0) {\n return Promise.resolve();\n }\n return new Promise((resolve, reject) => {\n const timer = setTimeout(() => {\n // don't wait anymore for export, this way the next batch can start\n reject(new Error('Timeout'));\n }, this._exportTimeoutMillis);\n // prevent downstream exporter calls from generating spans\n context.with(suppressTracing(context.active()), () => {\n // Reset the finished spans buffer here because the next invocations of the _flush method\n // could pass the same finished spans to the exporter if the buffer is cleared\n // outside the execution of this callback.\n let spans;\n if (this._finishedSpans.length <= this._maxExportBatchSize) {\n spans = this._finishedSpans;\n this._finishedSpans = [];\n }\n else {\n spans = this._finishedSpans.splice(0, this._maxExportBatchSize);\n }\n const doExport = () => this._exporter.export(spans, result => {\n clearTimeout(timer);\n if (result.code === ExportResultCode.SUCCESS) {\n resolve();\n }\n else {\n reject(result.error ??\n new Error('BatchSpanProcessor: span export failed'));\n }\n });\n let pendingResources = null;\n for (let i = 0, len = spans.length; i < len; i++) {\n const span = spans[i];\n if (span.resource.asyncAttributesPending &&\n span.resource.waitForAsyncAttributes) {\n pendingResources ??= [];\n pendingResources.push(span.resource.waitForAsyncAttributes());\n }\n }\n // Avoid scheduling a promise to make the behavior more predictable and easier to test\n if (pendingResources === null) {\n doExport();\n }\n else {\n Promise.all(pendingResources).then(doExport, err => {\n globalErrorHandler(err);\n reject(err);\n });\n }\n });\n });\n }\n _maybeStartTimer() {\n if (this._isExporting)\n return;\n const flush = () => {\n this._isExporting = true;\n this._flushOneBatch()\n .finally(() => {\n this._isExporting = false;\n if (this._finishedSpans.length > 0) {\n this._clearTimer();\n this._maybeStartTimer();\n }\n })\n .catch(e => {\n this._isExporting = false;\n globalErrorHandler(e);\n });\n };\n // we only wait if the queue doesn't have enough elements yet\n if (this._finishedSpans.length >= this._maxExportBatchSize) {\n return flush();\n }\n if (this._timer !== undefined)\n return;\n this._timer = setTimeout(() => flush(), this._scheduledDelayMillis);\n // depending on runtime, this may be a 'number' or NodeJS.Timeout\n if (typeof this._timer !== 'number') {\n this._timer.unref();\n }\n }\n _clearTimer() {\n if (this._timer !== undefined) {\n clearTimeout(this._timer);\n this._timer = undefined;\n }\n }\n}\n//# sourceMappingURL=BatchSpanProcessorBase.js.map","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { BatchSpanProcessorBase } from '../../../export/BatchSpanProcessorBase';\nexport class BatchSpanProcessor extends BatchSpanProcessorBase {\n onShutdown() { }\n}\n//# sourceMappingURL=BatchSpanProcessor.js.map","/** @internal */\nexport type PrivacyModeGate = {\n readonly privacyMode?: boolean\n /** Legacy spelling, still honored for callers that set it directly. */\n readonly privacy_mode?: boolean\n /** Read for posthog-node versions that predate the `privacyMode` accessor. */\n readonly options?: { readonly privacyMode?: boolean }\n}\n\n/** Per-call settings can turn redaction on but never off. */\nexport const isPrivacyModeEnabled = (client: PrivacyModeGate | undefined, privacyMode = false): boolean =>\n privacyMode === true ||\n client?.privacyMode === true ||\n client?.privacy_mode === true ||\n client?.options?.privacyMode === true\n","import type { AttributeValue, Attributes } from '@opentelemetry/api'\nimport type { ReadableSpan } from './types'\n\nimport { withAttributes } from './spans'\n\nexport type CapturedContext = {\n distinctId?: string\n sessionId?: string\n properties?: Record<string, unknown>\n}\n\n// Structural so declarations type-check against posthog-node versions that have no getContext.\nexport type PostHogContextSource = {\n getContext?(): CapturedContext | undefined\n}\n\nconst DISTINCT_ID_ATTRIBUTE = 'posthog.distinct_id'\nconst SESSION_ID_ATTRIBUTE = '$session_id'\n\n// Ingestion prefers posthog.distinct_id, so adding it would override the user a span already names.\nconst IDENTITY_ATTRIBUTES = [\n DISTINCT_ID_ATTRIBUTE,\n 'user.id',\n 'ai.telemetry.metadata.posthog_distinct_id',\n 'ai.settings.context.posthog_distinct_id',\n]\n\ntype Primitive = string | number | boolean\n\nfunction isPrimitive(value: unknown): value is Primitive {\n return (\n typeof value === 'string' || typeof value === 'boolean' || (typeof value === 'number' && Number.isFinite(value))\n )\n}\n\nfunction isHomogeneousPrimitiveArray(value: unknown): value is string[] | number[] | boolean[] {\n return Array.isArray(value) && value.every((item) => isPrimitive(item) && typeof item === typeof value[0])\n}\n\nfunction rejectNonFinite(_key: string, value: unknown): unknown {\n if (typeof value === 'number' && !Number.isFinite(value)) {\n throw new TypeError('non-finite number')\n }\n return value\n}\n\nfunction toAttributeValue(value: unknown): AttributeValue | undefined {\n if (value === undefined || value === null || value === '') {\n return undefined\n }\n if (isPrimitive(value) || isHomogeneousPrimitiveArray(value)) {\n return value\n }\n try {\n const json = JSON.stringify(value, rejectNonFinite)\n if (json === undefined || json === 'null') {\n return undefined\n }\n return json.startsWith('\"') ? String(JSON.parse(json)) || undefined : json\n } catch {\n return undefined\n }\n}\n\nfunction hasValues(context: CapturedContext): boolean {\n return Boolean(context.distinctId || context.sessionId || Object.keys(context.properties ?? {}).length > 0)\n}\n\nexport function captureContext(client: PostHogContextSource): CapturedContext | undefined {\n try {\n // posthog-node versions before getContext existed are still within the peer range.\n if (typeof client.getContext !== 'function') {\n return undefined\n }\n const context = client.getContext()\n return context && hasValues(context) ? context : undefined\n } catch {\n // Capturing is best effort and must never break the instrumented call.\n return undefined\n }\n}\n\nfunction toAttributes(context: CapturedContext, spanAttributes: Attributes): Attributes {\n const hasIdentity = IDENTITY_ATTRIBUTES.some((key) => spanAttributes[key] !== undefined)\n const values: Record<string, unknown> = {\n ...(context.distinctId && !hasIdentity ? { [DISTINCT_ID_ATTRIBUTE]: context.distinctId } : {}),\n ...(context.sessionId ? { [SESSION_ID_ATTRIBUTE]: context.sessionId } : {}),\n ...context.properties,\n }\n const attributes: Attributes = {}\n for (const [key, value] of Object.entries(values)) {\n if (hasIdentity && key === DISTINCT_ID_ATTRIBUTE) {\n continue\n }\n const attribute = toAttributeValue(value)\n if (attribute !== undefined) {\n attributes[key] = attribute\n }\n }\n return attributes\n}\n\nexport function withRequestContext(span: ReadableSpan, context: CapturedContext): ReadableSpan {\n try {\n const attributes = toAttributes(context, span.attributes)\n if (Object.keys(attributes).length === 0) {\n return span\n }\n return withAttributes(span, { ...attributes, ...span.attributes })\n } catch {\n // Conversion runs inside span.end() and must never break the instrumented call.\n return span\n }\n}\n","import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'\nimport type { Context } from '@opentelemetry/api'\nimport type { SpanProcessor, ReadableSpan, Span } from './types'\nimport { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base'\n\nimport { redactSpan } from './redact'\nimport { stripContent } from './privacy'\nimport { isPrivacyModeEnabled, type PrivacyModeGate } from '../privacyMode'\nimport { captureContext, withRequestContext, type CapturedContext, type PostHogContextSource } from './requestContext'\nimport { isAISpan } from './spans'\nimport { warnIfPostHogAiGatewayOtelAttributes } from '../gatewayWarning'\n\nconst DEFAULT_OTEL_HOST = 'https://us.i.posthog.com'\n\nfunction normalizeToken(value?: unknown): string {\n return typeof value === 'string' ? value.trim() : ''\n}\n\nfunction normalizeHost(value?: unknown): string {\n const normalizedValue = typeof value === 'string' ? value.trim() : ''\n return normalizedValue || DEFAULT_OTEL_HOST\n}\n\nexport interface PostHogSpanProcessorOptions {\n /**\n * Your PostHog project token (the `phc_...` key). Required; a blank token disables the\n * processor as a defensive no-op.\n */\n projectToken: string\n\n /**\n * PostHog host URL. Defaults to `https://us.i.posthog.com`.\n */\n host?: string\n\n /**\n * Your posthog-node client. When set, each AI span this processor exports gets the distinct ID,\n * session ID (as `$session_id`) and properties from the context entered with `client.withContext()`.\n * Other processors on the provider don't see them.\n * Attributes already on the span win over properties, which win over the context's IDs.\n * The context is captured when a span starts, but its properties are read when the span ends,\n * so mutating a context object while a span is open shows up in the export.\n * Must be the same posthog-node instance you call `withContext` on.\n */\n client?: PostHogContextSource & PrivacyModeGate\n\n /**\n * Drop prompts, outputs, tool arguments and results, and error messages from exported spans.\n * Also on when the `client` was created with `privacyMode: true`. Defaults to false.\n */\n privacyMode?: boolean\n\n /**\n * @internal Injected processor for testing — bypasses exporter creation.\n */\n _spanProcessor?: SpanProcessor\n}\n\nclass NoopSpanProcessor implements SpanProcessor {\n onStart(_span: Span, _parentContext: Context): void {\n return\n }\n onEnd(_span: ReadableSpan): void {\n return\n }\n shutdown(): Promise<void> {\n return Promise.resolve()\n }\n forceFlush(): Promise<void> {\n return Promise.resolve()\n }\n}\n\n/**\n * An OpenTelemetry `SpanProcessor` that sends AI traces to PostHog.\n *\n * `projectToken` is required; a blank token disables the processor as a defensive no-op.\n *\n * Internally batches spans and exports them to PostHog's OTLP ingestion\n * endpoint. Only AI-related spans (those whose name or attribute keys\n * start with `gen_ai.`, `llm.`, `ai.`, or `traceloop.`) are exported;\n * all other spans are silently dropped.\n *\n * Request-scoped and serverless runtimes should keep a reference to this\n * processor and await {@link PostHogSpanProcessor.forceFlush} before the request\n * lifecycle ends. This waits for queued exports without sending one request per span.\n *\n * This is the recommended integration point when your setup accepts a\n * `SpanProcessor`. If you need a `TraceExporter` instead (e.g. for\n * Vercel's `registerOTel`), use {@link PostHogTraceExporter}.\n *\n * @example\n * ```ts\n * import { PostHogSpanProcessor } from '@posthog/ai/otel'\n * import { NodeSDK } from '@opentelemetry/sdk-node'\n *\n * const processor = new PostHogSpanProcessor({ projectToken: 'phc_...' })\n * const sdk = new NodeSDK({ spanProcessors: [processor] })\n * sdk.start()\n *\n * // In request-scoped runtimes, wait for queued exports before returning.\n * await processor.forceFlush()\n * ```\n *\n * @example\n * ```ts\n * // Per request: pass your posthog-node client, then wrap the work in a context.\n * const processor = new PostHogSpanProcessor({ projectToken: 'phc_...', client: posthog })\n * await posthog.withContext({ distinctId: user.id, properties: { plan: 'pro' } }, () => handleRequest())\n * ```\n */\nexport class PostHogSpanProcessor implements SpanProcessor {\n private readonly inner: SpanProcessor\n private readonly client?: PostHogContextSource & PrivacyModeGate\n private readonly privacyMode: boolean = false\n private readonly capturedContexts = new WeakMap<ReadableSpan, CapturedContext>()\n\n constructor(options: PostHogSpanProcessorOptions) {\n const token = normalizeToken(options.projectToken)\n if (!token) {\n console.warn('[PostHogSpanProcessor] projectToken is missing or blank; the processor will be disabled.')\n this.inner = new NoopSpanProcessor()\n return\n }\n this.client = options.client\n this.privacyMode = options.privacyMode === true\n\n if (options._spanProcessor) {\n this.inner = options._spanProcessor\n } else {\n const host = new URL(normalizeHost(options.host)).origin\n const exporter = new OTLPTraceExporter({\n url: `${host}/i/v0/ai/otel`,\n headers: {\n Authorization: `Bearer ${token}`,\n },\n })\n this.inner = new BatchSpanProcessor(exporter)\n }\n }\n\n onStart(span: Span, parentContext: Context): void {\n const captured = this.client && captureContext(this.client)\n if (captured) {\n this.capturedContexts.set(span, captured)\n }\n // Forwarded unconditionally — filtering happens in onEnd. We can't filter\n // here because the span hasn't finished yet and may not have AI attributes\n // set. BatchSpanProcessor.onStart is a no-op so this is safe.\n this.inner.onStart(span, parentContext)\n }\n\n onEnd(span: ReadableSpan): void {\n const captured = this.capturedContexts.get(span)\n this.capturedContexts.delete(span)\n if (isAISpan(span)) {\n warnIfPostHogAiGatewayOtelAttributes(span.attributes)\n const contextual = captured ? withRequestContext(span, captured) : span\n const shareable = isPrivacyModeEnabled(this.client, this.privacyMode) ? stripContent(contextual) : contextual\n this.inner.onEnd(redactSpan(shareable))\n }\n }\n\n shutdown(): Promise<void> {\n return this.inner.shutdown()\n }\n\n forceFlush(): Promise<void> {\n return this.inner.forceFlush()\n }\n}\n"],"x_google_ignoreList":[11,12,13,14,15,16,17,18,19],"mappings":";;;;;AAAA,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAI3B,IAAa,mBAAb,MAA8B;CAC5B,UAAU,OAAe,WAAsC;EAC7D,MAAM,UAAU,mBAAmB,KAAK,KAAK;EAC7C,IAAI,SAAS,OAAO;GAAE,MAAM;GAAY,WAAW,QAAQ;EAAG;EAE9D,IAAI,MAAM,SAAS,WAAW,OAAO,EAAE,MAAM,OAAO;EAEpD,MAAM,mBAAmB,MAAM,MAAM,GAAG,SAAS;EACjD,IAAI,mBAAmB,KAAK,gBAAgB,GAC1C,OAAO,EAAE,MAAM,MAAM;OAErB,OAAO,EAAE,MAAM,OAAO;CAE1B;AACF;;;ACnBA,MAA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QAAQ,gBACV,KAAK,QAAQ,QAAQ;OAChB;GACL,MAAM,OAAO,IAAI,IAAI,cAAc,QAAQ,IAAI,CAAC,CAAC,CAAC;GAClD,MAAM,WAAW,IAAI,kBAAkB;IACrC,KAAK,GAAG,KAAK;IACb,SAAS,EACP,eAAe,UAAU,QAC3B;GACF,CAAC;GACD,KAAK,QAAQ,IAAI,mBAAmB,QAAQ;EAC9C;CACF;CAEA,QAAQ,MAAY,eAA8B;EAChD,MAAM,WAAW,KAAK,UAAU,eAAe,KAAK,MAAM;EAC1D,IAAI,UACF,KAAK,iBAAiB,IAAI,MAAM,QAAQ;EAK1C,KAAK,MAAM,QAAQ,MAAM,aAAa;CACxC;CAEA,MAAM,MAA0B;EAC9B,MAAM,WAAW,KAAK,iBAAiB,IAAI,IAAI;EAC/C,KAAK,iBAAiB,OAAO,IAAI;EACjC,IAAI,SAAS,IAAI,GAAG;GAClB,qCAAqC,KAAK,UAAU;GACpD,MAAM,aAAa,WAAW,mBAAmB,MAAM,QAAQ,IAAI;GACnE,MAAM,YAAY,qBAAqB,KAAK,QAAQ,KAAK,WAAW,IAAI,aAAa,UAAU,IAAI;GACnG,KAAK,MAAM,MAAM,WAAW,SAAS,CAAC;EACxC;CACF;CAEA,WAA0B;EACxB,OAAO,KAAK,MAAM,SAAS;CAC7B;CAEA,aAA4B;EAC1B,OAAO,KAAK,MAAM,WAAW;CAC/B;AACF"}
|
package/dist/vercel/index.cjs
CHANGED
|
@@ -14,9 +14,77 @@ const isObject = (value) => {
|
|
|
14
14
|
function isFullAiCaptureEnabled(client) {
|
|
15
15
|
return client?.enableFullAiCapture === true;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* The caller's distinct id as a string, or undefined when it is missing, empty or only whitespace.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
function userDistinctId(value) {
|
|
23
|
+
if (!value) return;
|
|
24
|
+
const id = String(value);
|
|
25
|
+
return id.trim() === "" ? void 0 : id;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The caller's per-event options when they are an object. A missing or `null` value means no
|
|
29
|
+
* options. An array or any other value is reported and ignored, so it is never spread.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
function readAiEventOptions(value) {
|
|
34
|
+
if (value === void 0 || value === null) return;
|
|
35
|
+
if (typeof value === "object" && !Array.isArray(value)) return value;
|
|
36
|
+
console.warn(`[PostHog AI] options must be an object, got ${Array.isArray(value) ? "array" : typeof value}; ignoring them`);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The `properties` and `options` for an AI event. `personless` (no user distinct id) turns person
|
|
40
|
+
* processing off and beats the caller's `process_person_profile`.
|
|
41
|
+
*
|
|
42
|
+
* posthog-node 6 takes the options as they are, so no option is written as a property.
|
|
43
|
+
* posthog-node 5 has no per-event options: each known option is sent as the property that version
|
|
44
|
+
* reads, and an unknown key is dropped.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
function eventOptionFields(client, properties, options, personless) {
|
|
49
|
+
const userOptions = readAiEventOptions(options);
|
|
50
|
+
if (isPostHogNode6(client)) {
|
|
51
|
+
const eventOptions = {
|
|
52
|
+
...userOptions,
|
|
53
|
+
...personless ? { process_person_profile: false } : {}
|
|
54
|
+
};
|
|
55
|
+
return Object.keys(eventOptions).length > 0 ? {
|
|
56
|
+
properties,
|
|
57
|
+
options: eventOptions
|
|
58
|
+
} : { properties };
|
|
59
|
+
}
|
|
60
|
+
const withOptionProperties = {
|
|
61
|
+
...properties,
|
|
62
|
+
...(0, _posthog_core.eventOptionsAsLegacyProperties)(userOptions)
|
|
63
|
+
};
|
|
64
|
+
if (personless) withOptionProperties.$process_person_profile = false;
|
|
65
|
+
return { properties: withOptionProperties };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Whether the client is posthog-node 6 or later, the first major with per-event options.
|
|
69
|
+
*
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
function isPostHogNode6(client) {
|
|
73
|
+
return (0, _posthog_core.acceptsEventOptions)(client);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* posthog-node 6 sends every AI event on its capture v1 AI lane; `enableFullAiCapture` then only
|
|
77
|
+
* controls truncation and media redaction. posthog-node 5 keeps the opt-in, so an `@posthog/ai`
|
|
78
|
+
* upgrade never changes how a 5.x client sends.
|
|
79
|
+
*
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
function usesAiLane(client) {
|
|
83
|
+
return isPostHogNode6(client) || isFullAiCaptureEnabled(client);
|
|
84
|
+
}
|
|
17
85
|
/** @internal */
|
|
18
86
|
function captureAiEvent(client, event) {
|
|
19
|
-
if (
|
|
87
|
+
if (usesAiLane(client) && typeof client.captureAi === "function") {
|
|
20
88
|
client.captureAi(event);
|
|
21
89
|
return;
|
|
22
90
|
}
|
|
@@ -24,7 +92,7 @@ function captureAiEvent(client, event) {
|
|
|
24
92
|
}
|
|
25
93
|
/** @internal */
|
|
26
94
|
async function captureAiEventImmediate(client, event) {
|
|
27
|
-
if (
|
|
95
|
+
if (usesAiLane(client) && typeof client.captureAiImmediate === "function") {
|
|
28
96
|
await client.captureAiImmediate(event);
|
|
29
97
|
return;
|
|
30
98
|
}
|
|
@@ -424,7 +492,7 @@ function sanitizeValues(obj) {
|
|
|
424
492
|
}
|
|
425
493
|
//#endregion
|
|
426
494
|
//#region package.json
|
|
427
|
-
var version = "8.
|
|
495
|
+
var version = "8.21.1";
|
|
428
496
|
//#endregion
|
|
429
497
|
//#region src/serializeError.ts
|
|
430
498
|
const DEFAULT_MAX_DEPTH = 3;
|
|
@@ -619,6 +687,20 @@ const warnIfPostHogAiGateway = (baseURL) => {
|
|
|
619
687
|
//#endregion
|
|
620
688
|
//#region src/captureAiGeneration.ts
|
|
621
689
|
/**
|
|
690
|
+
* posthog-node 6 takes an options object; 5.x, which has no `registerOptions`, takes positional
|
|
691
|
+
* arguments. The 6.x positional fallback works too, but logs a deprecation error in the app.
|
|
692
|
+
*/
|
|
693
|
+
const captureAiException = (client, error, properties, uuid$1) => {
|
|
694
|
+
if (isPostHogNode6(client)) {
|
|
695
|
+
client.captureException(error, {
|
|
696
|
+
properties,
|
|
697
|
+
uuid: uuid$1
|
|
698
|
+
});
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
client.captureException.call(client, error, void 0, properties, uuid$1);
|
|
702
|
+
};
|
|
703
|
+
/**
|
|
622
704
|
* Capture an `$ai_generation` (or `$ai_embedding`) event to PostHog.
|
|
623
705
|
*
|
|
624
706
|
* This is the canonical primitive that every `@posthog/ai` wrapper
|
|
@@ -654,7 +736,7 @@ const captureAiGeneration = async (client, options) => {
|
|
|
654
736
|
if (client.options?.enableExceptionAutocapture) {
|
|
655
737
|
if (!shouldRedact) {
|
|
656
738
|
exceptionId = (0, _posthog_core.uuidv7)();
|
|
657
|
-
client
|
|
739
|
+
captureAiException(client, options.error, { $ai_trace_id: traceId }, exceptionId);
|
|
658
740
|
}
|
|
659
741
|
if (typeof options.error === "object") options.error.__posthog_previously_captured_error = true;
|
|
660
742
|
}
|
|
@@ -680,6 +762,7 @@ const captureAiGeneration = async (client, options) => {
|
|
|
680
762
|
...usage.webSearchCount ? { $ai_web_search_count: usage.webSearchCount } : {},
|
|
681
763
|
...usage.rawUsage ? { $ai_usage: usage.rawUsage } : {}
|
|
682
764
|
};
|
|
765
|
+
const distinctId = userDistinctId(options.distinctId);
|
|
683
766
|
const properties = {
|
|
684
767
|
$ai_lib: "posthog-ai",
|
|
685
768
|
$ai_lib_version: version,
|
|
@@ -699,7 +782,6 @@ const captureAiGeneration = async (client, options) => {
|
|
|
699
782
|
...options.baseURL === null ? {} : { $ai_base_url: options.baseURL ?? "" },
|
|
700
783
|
...options.properties,
|
|
701
784
|
$ai_tokens_source: getTokensSource(options.properties),
|
|
702
|
-
...options.distinctId ? {} : { $process_person_profile: false },
|
|
703
785
|
...options.stopReason ? { $ai_stop_reason: options.stopReason } : {},
|
|
704
786
|
...options.tools ? { $ai_tools: redactMcpToolCredentials(options.tools) } : {},
|
|
705
787
|
...options.completionId ? { $ai_completion_id: options.completionId } : {},
|
|
@@ -708,9 +790,9 @@ const captureAiGeneration = async (client, options) => {
|
|
|
708
790
|
...costOverrideData
|
|
709
791
|
};
|
|
710
792
|
const event = {
|
|
711
|
-
distinctId:
|
|
793
|
+
distinctId: distinctId ?? traceId,
|
|
712
794
|
event: eventType,
|
|
713
|
-
properties,
|
|
795
|
+
...eventOptionFields(client, properties, options.options, !distinctId),
|
|
714
796
|
groups: options.groups
|
|
715
797
|
};
|
|
716
798
|
if (options.captureImmediate) await captureAiEventImmediate(client, event);
|
|
@@ -991,6 +1073,7 @@ const wrapVercelLanguageModel = (model, phClient, options) => {
|
|
|
991
1073
|
traceId,
|
|
992
1074
|
properties: mergedOptions.posthogProperties,
|
|
993
1075
|
groups: mergedOptions.posthogGroups,
|
|
1076
|
+
options: mergedOptions.posthogOptions,
|
|
994
1077
|
privacyMode,
|
|
995
1078
|
modelOverride: mergedOptions.posthogModelOverride,
|
|
996
1079
|
providerOverride: mergedOptions.posthogProviderOverride,
|