@latitude-data/telemetry 0.0.3 → 0.0.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/exporters/latitudeExporter.ts","../src/processors/vercel/conventions.ts","../src/processors/vercel/index.ts","../src/telemetry/index.ts"],"sourcesContent":["import { ExportResultCode, hrTimeToNanoseconds } from '@opentelemetry/core'\nimport {\n OTLPExporterBase,\n OTLPExporterConfigBase,\n} from '@opentelemetry/otlp-exporter-base'\nimport { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'\n\nconst DOMAIN =\n process.env.NODE_ENV === 'production'\n ? 'gateway.latitude.so/api/v2/otlp'\n : 'localhost:8787/api/v2/otlp'\nconst PROTOCOL = process.env.NODE_ENV === 'production' ? 'https' : 'http'\n\ninterface OTLPHttpExporterConfig extends OTLPExporterConfigBase {\n apiKey: string\n endpoint?: string\n}\n\nexport class LatitudeExporter\n extends OTLPExporterBase<any, any, any>\n implements SpanExporter\n{\n url: string\n private headers: Record<string, string>\n\n constructor(config: OTLPHttpExporterConfig) {\n super(config)\n\n this.url = config.endpoint || this.__defaultUrl\n this.headers = {\n Authorization: `Bearer ${config.apiKey}`,\n }\n }\n\n async export(\n spans: ReadableSpan[],\n resultCallback: (result: any) => void,\n ): Promise<void> {\n await this.send(\n spans,\n () => resultCallback({ code: ExportResultCode.SUCCESS }),\n (error) => {\n resultCallback({ code: ExportResultCode.FAILED, error })\n },\n )\n }\n\n async shutdown(): Promise<void> {\n // No-op\n }\n\n async onShutdown(): Promise<void> {\n // No-op\n }\n\n async onInit(): Promise<void> {\n // No-op\n }\n\n async send(\n spans: ReadableSpan[],\n onSuccess: () => void,\n onError: (error: Error) => void,\n ): Promise<void> {\n if (spans.length === 0) {\n onSuccess()\n return\n }\n\n const serviceRequest = this.convert(spans)\n const body = JSON.stringify(serviceRequest)\n\n try {\n const response = await fetch(this.url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.headers,\n },\n body,\n })\n\n if (!response.ok || response.status >= 400) {\n throw new Error(`${response.status} ${response.statusText}`)\n }\n\n onSuccess()\n } catch (error) {\n onError(error as Error)\n }\n }\n\n convert(spans: ReadableSpan[]) {\n return {\n resourceSpans: [\n {\n resource: {\n attributes: this.convertAttributes(\n spans[0]?.resource?.attributes || {},\n ),\n },\n scopeSpans: [\n {\n spans: spans.map((span) => ({\n traceId: span.spanContext().traceId,\n spanId: span.spanContext().spanId,\n parentSpanId: span.parentSpanId,\n name: span.name,\n kind: span.kind,\n startTimeUnixNano: hrTimeToNanoseconds(\n span.startTime,\n ).toString(),\n endTimeUnixNano: span.endTime\n ? hrTimeToNanoseconds(span.endTime).toString()\n : undefined,\n attributes: this.convertAttributes(span.attributes),\n status: span.status && {\n code: span.status.code,\n message: span.status.message,\n },\n events: span.events?.map((event) => ({\n timeUnixNano: hrTimeToNanoseconds(event.time).toString(),\n name: event.name,\n attributes: this.convertAttributes(event.attributes),\n })),\n links: span.links?.map((link) => ({\n traceId: link.context.traceId,\n spanId: link.context.spanId,\n attributes: this.convertAttributes(link.attributes),\n })),\n })),\n },\n ],\n },\n ],\n }\n }\n\n getDefaultUrl(config: any): string {\n return config.endpoint || this.__defaultUrl\n }\n\n private get __defaultUrl(): string {\n return `${PROTOCOL}://${DOMAIN}/v1/traces`\n }\n\n private convertAttributes(attributes: Record<string, unknown> = {}): Array<{\n key: string\n value: { stringValue?: string; intValue?: number; boolValue?: boolean }\n }> {\n return Object.entries(attributes).map(([key, value]) => ({\n key,\n value: this.convertAttributeValue(value),\n }))\n }\n\n private convertAttributeValue(value: unknown): {\n stringValue?: string\n intValue?: number\n boolValue?: boolean\n } {\n if (typeof value === 'string') return { stringValue: value }\n if (typeof value === 'number') return { intValue: value }\n if (typeof value === 'boolean') return { boolValue: value }\n return { stringValue: String(value) }\n }\n}\n","/**\n * Below are the semantic conventions for the Vercel AI SDK.\n * @see https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#collected-data\n */\nconst AI_PREFIX = 'ai' as const\n\nconst AIPrefixes = {\n settings: 'settings',\n model: 'model',\n usage: 'usage',\n telemetry: 'telemetry',\n prompt: 'prompt',\n toolCall: 'toolCall',\n response: 'response',\n} as const\n\nconst AIUsagePostfixes = {\n completionTokens: 'completionTokens',\n promptTokens: 'promptTokens',\n} as const\n\nconst AIResultPostfixes = {\n text: 'text',\n toolCalls: 'toolCalls',\n object: 'object',\n} as const\n\nconst AIPromptPostfixes = {\n messages: 'messages',\n} as const\n\nconst AIToolCallPostfixes = {\n id: 'id',\n name: 'name',\n args: 'args',\n result: 'result',\n} as const\n\nconst SETTINGS = `${AI_PREFIX}.${AIPrefixes.settings}` as const\n\nconst MODEL_ID = `${AI_PREFIX}.${AIPrefixes.model}.id` as const\n\nconst METADATA = `${AI_PREFIX}.${AIPrefixes.telemetry}.metadata` as const\n\nconst TOKEN_COUNT_COMPLETION =\n `${AI_PREFIX}.${AIPrefixes.usage}.${AIUsagePostfixes.completionTokens}` as const\n\nconst TOKEN_COUNT_PROMPT =\n `${AI_PREFIX}.${AIPrefixes.usage}.${AIUsagePostfixes.promptTokens}` as const\n\nconst RESPONSE_TEXT =\n `${AI_PREFIX}.${AIPrefixes.response}.${AIResultPostfixes.text}` as const\n\nconst RESPONSE_TOOL_CALLS =\n `${AI_PREFIX}.${AIPrefixes.response}.${AIResultPostfixes.toolCalls}` as const\n\nconst RESULT_OBJECT =\n `${AI_PREFIX}.${AIPrefixes.response}.${AIResultPostfixes.object}` as const\n\nconst PROMPT = `${AI_PREFIX}.${AIPrefixes.prompt}` as const\n\nconst PROMPT_MESSAGES = `${PROMPT}.${AIPromptPostfixes.messages}` as const\n\nconst EMBEDDING_TEXT = `${AI_PREFIX}.value` as const\nconst EMBEDDING_VECTOR = `${AI_PREFIX}.embedding` as const\n\nconst EMBEDDING_TEXTS = `${AI_PREFIX}.values` as const\nconst EMBEDDING_VECTORS = `${AI_PREFIX}.embeddings` as const\n\nconst TOOL_CALL_ID =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.id}` as const\nconst TOOL_CALL_NAME =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.name}` as const\nconst TOOL_CALL_ARGS =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.args}` as const\nconst TOOL_CALL_RESULT =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.result}` as const\n\n/**\n * The semantic conventions used by the Vercel AI SDK.\n * @see https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#collected-data\n */\nexport const AISemanticConventions = {\n MODEL_ID,\n METADATA,\n SETTINGS,\n TOKEN_COUNT_COMPLETION,\n TOKEN_COUNT_PROMPT,\n RESPONSE_TEXT,\n RESPONSE_TOOL_CALLS,\n RESULT_OBJECT,\n PROMPT,\n PROMPT_MESSAGES,\n EMBEDDING_TEXT,\n EMBEDDING_VECTOR,\n EMBEDDING_TEXTS,\n EMBEDDING_VECTORS,\n TOOL_CALL_ID,\n TOOL_CALL_NAME,\n TOOL_CALL_ARGS,\n TOOL_CALL_RESULT,\n} as const\n\nexport const AISemanticConventionsList = Object.freeze(\n Object.values(AISemanticConventions),\n)\n\nexport type AISemanticConvention =\n (typeof AISemanticConventions)[keyof typeof AISemanticConventions]\n","import {\n ReadableSpan,\n SimpleSpanProcessor,\n SpanProcessor,\n BatchSpanProcessor,\n} from '@opentelemetry/sdk-trace-base'\nimport type { ToolCallPart } from 'ai'\n\nimport { AISemanticConventions } from './conventions'\n\nexport class VercelSpanProcessor\n extends SimpleSpanProcessor\n implements SpanProcessor\n{\n onEnd(span: ReadableSpan): void {\n if (!shouldProcess(span)) return\n if (shouldConvertToLatitudeFormat(span)) convertToLatitudeFormat(span)\n\n super.onEnd(span)\n }\n}\n\nexport class VercelBatchSpanProcessor\n extends BatchSpanProcessor\n implements SpanProcessor\n{\n onEnd(span: ReadableSpan): void {\n if (!shouldProcess(span)) return\n if (shouldConvertToLatitudeFormat(span)) convertToLatitudeFormat(span)\n\n super.onEnd(span)\n }\n}\n\nfunction shouldProcess(span: ReadableSpan): boolean {\n return (\n Object.keys(span.attributes).some((k) => k.startsWith('latitude.')) ||\n Object.keys(span.attributes).some((k) => k.startsWith('ai.'))\n )\n}\n\nfunction shouldConvertToLatitudeFormat(span: ReadableSpan): boolean {\n return Object.keys(span.attributes).some((k) => k.startsWith('ai.'))\n}\n\nfunction convertToLatitudeFormat(span: ReadableSpan): void {\n try {\n const computedAttrs = computeOpenLLMAttributes(span)\n if (computedAttrs) {\n ;(span as any).attributes = {\n ...span.attributes,\n ...computedAttrs,\n }\n }\n } catch (e) {\n console.log('Latitude telemetry Error: ', e)\n // do nothing\n }\n}\n\nfunction computeOpenLLMAttributes(span: ReadableSpan) {\n const attrs = span.attributes || {}\n const result: Record<string, string | number | boolean> = {}\n\n // Extract model information\n if (attrs[AISemanticConventions.MODEL_ID]) {\n result['gen_ai.request.model'] = String(\n attrs[AISemanticConventions.MODEL_ID],\n )\n result['gen_ai.response.model'] = String(\n attrs[AISemanticConventions.MODEL_ID],\n )\n }\n\n // Extract settings\n try {\n const settings = attrs[AISemanticConventions.SETTINGS]\n ? JSON.parse(String(attrs[AISemanticConventions.SETTINGS]))\n : {}\n\n if (settings) {\n // Add max tokens if present\n if (settings.maxTokens) {\n result['gen_ai.request.max_tokens'] = settings.maxTokens\n }\n\n if (!attrs['gen_ai.system'] && settings.provider) {\n result['gen_ai.system'] = String(settings.provider)\n }\n }\n } catch (e) {\n console.error('Error parsing settings', e)\n }\n\n // Set request type to chat as that's what Vercel AI SDK uses\n result['llm.request.type'] = 'chat'\n\n // Extract messages\n try {\n const messages = attrs['ai.prompt.messages']\n ? JSON.parse(String(attrs['ai.prompt.messages']))\n : []\n\n // Process prompt messages\n messages.forEach((msg: any, index: number) => {\n result[`gen_ai.prompt.${index}.role`] = msg.role\n result[`gen_ai.prompt.${index}.content`] =\n typeof msg.content === 'string'\n ? msg.content\n : JSON.stringify(msg.content)\n })\n } catch (e) {\n console.error('Error parsing messages', e)\n return undefined\n }\n\n // Extract completion/response\n const responseText = attrs['ai.response.text']\n const responseObject = attrs['ai.response.object']\n const responseToolCalls = attrs['ai.response.toolCalls']\n if (responseText) {\n result[`gen_ai.completion.0.role`] = 'assistant'\n result[`gen_ai.completion.0.content`] = String(responseText)\n } else if (responseToolCalls) {\n try {\n const toolCalls = JSON.parse(String(responseToolCalls))\n if (toolCalls.length > 0) {\n result['gen_ai.completion.0.finish_reason'] = 'tool_calls'\n result[`gen_ai.completion.0.role`] = 'assistant'\n\n toolCalls.forEach((toolCall: ToolCallPart, toolCallIndex: number) => {\n result[`gen_ai.completion.0.tool_calls.${toolCallIndex}.id`] =\n toolCall.toolCallId\n result[`gen_ai.completion.0.tool_calls.${toolCallIndex}.name`] =\n toolCall.toolName\n result[`gen_ai.completion.0.tool_calls.${toolCallIndex}.arguments`] =\n toolCall.args as string\n })\n }\n } catch (e) {\n console.error('Error parsing tool calls', e)\n }\n } else if (responseObject) {\n result['gen_ai.completion.0.role'] = 'assistant'\n result['gen_ai.completion.0.content'] = String(responseObject)\n }\n\n // Extract token usage\n const completionTokens = attrs['ai.usage.completionTokens']\n const promptTokens = attrs['ai.usage.promptTokens']\n\n if (typeof completionTokens === 'number') {\n result['gen_ai.usage.completion_tokens'] = completionTokens\n }\n if (typeof promptTokens === 'number') {\n result['gen_ai.usage.prompt_tokens'] = promptTokens\n }\n if (\n typeof completionTokens === 'number' &&\n typeof promptTokens === 'number'\n ) {\n result['llm.usage.total_tokens'] = completionTokens + promptTokens\n }\n\n return result\n}\n","import { NodeSDK } from '@opentelemetry/sdk-node'\nimport {\n SimpleSpanProcessor,\n BatchSpanProcessor,\n SpanExporter,\n} from '@opentelemetry/sdk-trace-node'\n\nimport { AnthropicInstrumentation } from '@traceloop/instrumentation-anthropic'\nimport { OpenAIInstrumentation } from '@traceloop/instrumentation-openai'\nimport { AzureOpenAIInstrumentation } from '@traceloop/instrumentation-azure'\nimport {\n AIPlatformInstrumentation,\n VertexAIInstrumentation,\n} from '@traceloop/instrumentation-vertexai'\nimport { BedrockInstrumentation } from '@traceloop/instrumentation-bedrock'\nimport { CohereInstrumentation } from '@traceloop/instrumentation-cohere'\n\nimport type * as openai from 'openai'\nimport type * as anthropic from '@anthropic-ai/sdk'\nimport type * as azure from '@azure/openai'\nimport type * as cohere from 'cohere-ai'\nimport type * as bedrock from '@aws-sdk/client-bedrock-runtime'\nimport type * as aiplatform from '@google-cloud/aiplatform'\nimport type * as vertexAI from '@google-cloud/vertexai'\nimport type * as pinecone from '@pinecone-database/pinecone'\nimport type * as ChainsModule from 'langchain/chains'\nimport type * as AgentsModule from 'langchain/agents'\nimport type * as ToolsModule from 'langchain/tools'\nimport type * as RunnableModule from '@langchain/core/runnables'\nimport type * as VectorStoreModule from '@langchain/core/vectorstores'\nimport type * as llamaindex from 'llamaindex'\nimport type * as chromadb from 'chromadb'\nimport type * as qdrant from '@qdrant/js-client-rest'\nimport { Resource } from '@opentelemetry/resources'\nimport { context, trace } from '@opentelemetry/api'\n\ntype IModules = {\n openAI?: typeof openai\n anthropic?: typeof anthropic\n azureOpenAI?: typeof azure\n cohere?: typeof cohere\n bedrock?: typeof bedrock\n google_vertexai?: typeof vertexAI\n google_aiplatform?: typeof aiplatform\n pinecone?: typeof pinecone\n langchain?: {\n chainsModule?: typeof ChainsModule\n agentsModule?: typeof AgentsModule\n toolsModule?: typeof ToolsModule\n runnablesModule?: typeof RunnableModule\n vectorStoreModule?: typeof VectorStoreModule\n }\n llamaIndex?: typeof llamaindex\n chromadb?: typeof chromadb\n qdrant?: typeof qdrant\n}\n\ntype SpanAttributes = {\n name?: string\n metadata?: Record<string, unknown>\n prompt?: {\n uuid: string\n versionUuid?: string\n parameters?: Record<string, unknown>\n }\n distinctId?: string\n}\n\nexport type LatitudeTelemetrySDKConfig = {\n exporter: SpanExporter\n modules?: IModules\n disableBatch?: boolean\n processors?: (typeof SimpleSpanProcessor)[] | (typeof BatchSpanProcessor)[]\n}\n\nexport class LatitudeTelemetrySDK {\n private exporter: SpanExporter\n\n constructor({\n exporter,\n modules = {},\n disableBatch = false,\n processors = [],\n }: LatitudeTelemetrySDKConfig) {\n this.exporter = exporter\n\n this._init(modules, { disableBatch, processors })\n }\n\n private _init(\n modules: IModules,\n options?: {\n disableBatch?: boolean\n processors?:\n | (typeof SimpleSpanProcessor)[]\n | (typeof BatchSpanProcessor)[]\n },\n ) {\n const instrumentations = []\n\n if (modules?.openAI) {\n const openAIInstrumentation = new OpenAIInstrumentation({\n enrichTokens: true,\n })\n // @ts-ignore\n openAIInstrumentation.manuallyInstrument(modules.openAI!)\n instrumentations.push(openAIInstrumentation)\n }\n\n if (modules?.anthropic) {\n const anthropicInstrumentation = new AnthropicInstrumentation()\n anthropicInstrumentation.manuallyInstrument(modules.anthropic!)\n instrumentations.push(new AnthropicInstrumentation())\n }\n\n if (modules?.azureOpenAI) {\n const azureOpenAIInstrumentation = new AzureOpenAIInstrumentation()\n azureOpenAIInstrumentation.manuallyInstrument(modules.azureOpenAI!)\n instrumentations.push(azureOpenAIInstrumentation)\n }\n\n if (modules?.cohere) {\n const cohereInstrumentation = new CohereInstrumentation()\n cohereInstrumentation.manuallyInstrument(modules.cohere!)\n instrumentations.push(cohereInstrumentation)\n }\n\n if (modules?.google_vertexai) {\n const vertexAIInstrumentation = new VertexAIInstrumentation()\n vertexAIInstrumentation.manuallyInstrument(modules.google_vertexai!)\n instrumentations.push(vertexAIInstrumentation)\n }\n\n if (modules?.google_aiplatform) {\n const aiplatformInstrumentation = new AIPlatformInstrumentation()\n aiplatformInstrumentation.manuallyInstrument(modules.google_aiplatform!)\n instrumentations.push(aiplatformInstrumentation)\n }\n\n if (modules?.bedrock) {\n const bedrockInstrumentation = new BedrockInstrumentation()\n bedrockInstrumentation.manuallyInstrument(modules.bedrock!)\n instrumentations.push(bedrockInstrumentation)\n }\n\n // TODO: Enable these once we have manually tested them\n //if (modules?.langchain) {\n // const langchainInstrumentation = new LangChainInstrumentation()\n // langchainInstrumentation.manuallyInstrument(modules.langchain!)\n // instrumentations.push(langchainInstrumentation)\n //}\n //\n //if (modules?.llamaIndex) {\n // const llamaindexInstrumentation = new LlamaIndexInstrumentation()\n // llamaindexInstrumentation.manuallyInstrument(modules.llamaIndex!)\n // instrumentations.push(llamaindexInstrumentation)\n //}\n\n //if (modules?.pinecone) {\n // const pineconeInstrumentation = new PineconeInstrumentation()\n // pineconeInstrumentation.manuallyInstrument(modules.pinecone!)\n // instrumentations.push(pineconeInstrumentation)\n //}\n\n //if (modules?.chromadb) {\n // const chromadbInstrumentation = new ChromaDBInstrumentation()\n // chromadbInstrumentation.manuallyInstrument(modules.chromadb!)\n // instrumentations.push(chromadbInstrumentation)\n //}\n\n //if (modules?.qdrant) {\n // const qdrantInstrumentation = new QdrantInstrumentation()\n // qdrantInstrumentation.manuallyInstrument(modules.qdrant!)\n // instrumentations.push(qdrantInstrumentation)\n //}\n\n if (!instrumentations.length && !options?.processors?.length) {\n console.warn('Latitude: No instrumentations or processors to initialize')\n return\n }\n\n const processors = options?.disableBatch\n ? [\n new SimpleSpanProcessor(this.exporter),\n ...(options?.processors?.map(\n (processor) => new processor(this.exporter),\n ) || []),\n ]\n : [\n new BatchSpanProcessor(this.exporter),\n ...(options?.processors?.map(\n (processor) => new processor(this.exporter),\n ) || []),\n ]\n\n const sdk = new NodeSDK({\n resource: new Resource({\n 'service.name': process.env.npm_package_name,\n }),\n instrumentations,\n traceExporter: this.exporter,\n // @ts-ignore\n spanProcessors: processors,\n })\n\n sdk.start()\n }\n\n span<T>(s: SpanAttributes, fn: (span: any) => T): Promise<T> {\n const c = context.active()\n return context.with(c, () =>\n trace\n .getTracer('latitude')\n .startActiveSpan(s.name ?? 'latitude.span', {}, c, async (span) => {\n try {\n if (s.prompt) {\n try {\n span.setAttribute('latitude.prompt', JSON.stringify(s.prompt))\n } catch (e) {\n console.error(\n 'Latitude: Could not serialize latitude.prompt attribute',\n e,\n )\n }\n }\n\n if (s.distinctId) {\n span.setAttribute('latitude.distinctId', s.distinctId)\n }\n\n if (s.metadata) {\n try {\n span.setAttribute(\n 'latitude.metadata',\n JSON.stringify(s.metadata),\n )\n } catch (e) {\n console.error(\n 'Latitude: Could not serialize latitude.metadata attribute',\n e,\n )\n }\n }\n } catch (error) {\n console.error(error)\n }\n\n const res = fn(span)\n if (res instanceof Promise) {\n return res.then((resolvedRes) => {\n span.end()\n\n return resolvedRes\n })\n }\n\n span.end()\n\n return res\n }),\n )\n }\n}\n"],"names":["OTLPExporterBase","ExportResultCode","hrTimeToNanoseconds","SimpleSpanProcessor","BatchSpanProcessor","OpenAIInstrumentation","AnthropicInstrumentation","AzureOpenAIInstrumentation","CohereInstrumentation","VertexAIInstrumentation","AIPlatformInstrumentation","BedrockInstrumentation","NodeSDK","Resource","context","trace"],"mappings":";;;;;;;;;;;;;;;;AAOA,MAAM,MAAM,GAEN;IAC4B;AAClC,MAAM,QAAQ,GAA2C,OAAO,CAAS;AAOnE,MAAO,gBACX,SAAQA,iCAA+B,CAAA;AAGvC,IAAA,GAAG;AACK,IAAA,OAAO;AAEf,IAAA,WAAA,CAAY,MAA8B,EAAA;QACxC,KAAK,CAAC,MAAM,CAAC;QAEb,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,YAAY;QAC/C,IAAI,CAAC,OAAO,GAAG;AACb,YAAA,aAAa,EAAE,CAAA,OAAA,EAAU,MAAM,CAAC,MAAM,CAAE,CAAA;SACzC;;AAGH,IAAA,MAAM,MAAM,CACV,KAAqB,EACrB,cAAqC,EAAA;QAErC,MAAM,IAAI,CAAC,IAAI,CACb,KAAK,EACL,MAAM,cAAc,CAAC,EAAE,IAAI,EAAEC,qBAAgB,CAAC,OAAO,EAAE,CAAC,EACxD,CAAC,KAAK,KAAI;YACR,cAAc,CAAC,EAAE,IAAI,EAAEA,qBAAgB,CAAC,MAAM,EAAE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AAC,EAAE;AACV,wBAAA,OAAO,CAAC,KAAK,CACX,2DAA2D,EAC3D,CAAC,CACF;;;;YAGL,OAAO,KAAK,EAAE;AACd,gBAAA,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;;AAGtB,YAAA,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;AACpB,YAAA,IAAI,GAAG,YAAY,OAAO,EAAE;AAC1B,gBAAA,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,KAAI;oBAC9B,IAAI,CAAC,GAAG,EAAE;AAEV,oBAAA,OAAO,WAAW;AACpB,iBAAC,CAAC;;YAGJ,IAAI,CAAC,GAAG,EAAE;AAEV,YAAA,OAAO,GAAG;SACX,CAAC,CACL;;AAEJ;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/exporters/latitudeExporter.ts","../src/processors/vercel/conventions.ts","../src/processors/vercel/index.ts","../src/telemetry/index.ts"],"sourcesContent":["import { ExportResultCode, hrTimeToNanoseconds } from '@opentelemetry/core'\nimport {\n OTLPExporterBase,\n OTLPExporterConfigBase,\n} from '@opentelemetry/otlp-exporter-base'\nimport { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'\n\nconst DOMAIN =\n process.env.NODE_ENV === 'production'\n ? 'gateway.latitude.so/api/v2/otlp'\n : 'localhost:8787/api/v2/otlp'\nconst PROTOCOL = process.env.NODE_ENV === 'production' ? 'https' : 'http'\n\ninterface OTLPHttpExporterConfig extends OTLPExporterConfigBase {\n apiKey: string\n endpoint?: string\n}\n\nexport class LatitudeExporter\n extends OTLPExporterBase<any, any, any>\n implements SpanExporter\n{\n url: string\n private headers: Record<string, string>\n\n constructor(config: OTLPHttpExporterConfig) {\n super(config)\n\n this.url = config.endpoint || this.__defaultUrl\n this.headers = {\n Authorization: `Bearer ${config.apiKey}`,\n }\n }\n\n async export(\n spans: ReadableSpan[],\n resultCallback: (result: any) => void,\n ): Promise<void> {\n await this.send(\n spans,\n () => resultCallback({ code: ExportResultCode.SUCCESS }),\n (error) => {\n resultCallback({ code: ExportResultCode.FAILED, error })\n },\n )\n }\n\n async shutdown(): Promise<void> {\n // No-op\n }\n\n async onShutdown(): Promise<void> {\n // No-op\n }\n\n async onInit(): Promise<void> {\n // No-op\n }\n\n async send(\n spans: ReadableSpan[],\n onSuccess: () => void,\n onError: (error: Error) => void,\n ): Promise<void> {\n if (spans.length === 0) {\n onSuccess()\n return\n }\n\n const serviceRequest = this.convert(spans)\n const body = JSON.stringify(serviceRequest)\n\n try {\n const response = await fetch(this.url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.headers,\n },\n body,\n })\n\n if (!response.ok || response.status >= 400) {\n throw new Error(`${response.status} ${response.statusText}`)\n }\n\n onSuccess()\n } catch (error) {\n onError(error as Error)\n }\n }\n\n convert(spans: ReadableSpan[]) {\n return {\n resourceSpans: [\n {\n resource: {\n attributes: this.convertAttributes(\n spans[0]?.resource?.attributes || {},\n ),\n },\n scopeSpans: [\n {\n spans: spans.map((span) => ({\n traceId: span.spanContext().traceId,\n spanId: span.spanContext().spanId,\n parentSpanId: span.parentSpanId,\n name: span.name,\n kind: span.kind,\n startTimeUnixNano: hrTimeToNanoseconds(\n span.startTime,\n ).toString(),\n endTimeUnixNano: span.endTime\n ? hrTimeToNanoseconds(span.endTime).toString()\n : undefined,\n attributes: this.convertAttributes(span.attributes),\n status: span.status && {\n code: span.status.code,\n message: span.status.message,\n },\n events: span.events?.map((event) => ({\n timeUnixNano: hrTimeToNanoseconds(event.time).toString(),\n name: event.name,\n attributes: this.convertAttributes(event.attributes),\n })),\n links: span.links?.map((link) => ({\n traceId: link.context.traceId,\n spanId: link.context.spanId,\n attributes: this.convertAttributes(link.attributes),\n })),\n })),\n },\n ],\n },\n ],\n }\n }\n\n getDefaultUrl(config: any): string {\n return config.endpoint || this.__defaultUrl\n }\n\n private get __defaultUrl(): string {\n return `${PROTOCOL}://${DOMAIN}/v1/traces`\n }\n\n private convertAttributes(attributes: Record<string, unknown> = {}): Array<{\n key: string\n value: { stringValue?: string; intValue?: number; boolValue?: boolean }\n }> {\n return Object.entries(attributes).map(([key, value]) => ({\n key,\n value: this.convertAttributeValue(value),\n }))\n }\n\n private convertAttributeValue(value: unknown): {\n stringValue?: string\n intValue?: number\n boolValue?: boolean\n } {\n if (typeof value === 'string') return { stringValue: value }\n if (typeof value === 'number') return { intValue: value }\n if (typeof value === 'boolean') return { boolValue: value }\n return { stringValue: String(value) }\n }\n}\n","/**\n * Below are the semantic conventions for the Vercel AI SDK.\n * @see https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#collected-data\n */\nconst AI_PREFIX = 'ai' as const\n\nconst AIPrefixes = {\n settings: 'settings',\n model: 'model',\n usage: 'usage',\n telemetry: 'telemetry',\n prompt: 'prompt',\n toolCall: 'toolCall',\n response: 'response',\n} as const\n\nconst AIUsagePostfixes = {\n completionTokens: 'completionTokens',\n promptTokens: 'promptTokens',\n} as const\n\nconst AIResultPostfixes = {\n text: 'text',\n toolCalls: 'toolCalls',\n object: 'object',\n} as const\n\nconst AIPromptPostfixes = {\n messages: 'messages',\n} as const\n\nconst AIToolCallPostfixes = {\n id: 'id',\n name: 'name',\n args: 'args',\n result: 'result',\n} as const\n\nconst SETTINGS = `${AI_PREFIX}.${AIPrefixes.settings}` as const\n\nconst MODEL_ID = `${AI_PREFIX}.${AIPrefixes.model}.id` as const\n\nconst METADATA = `${AI_PREFIX}.${AIPrefixes.telemetry}.metadata` as const\n\nconst TOKEN_COUNT_COMPLETION =\n `${AI_PREFIX}.${AIPrefixes.usage}.${AIUsagePostfixes.completionTokens}` as const\n\nconst TOKEN_COUNT_PROMPT =\n `${AI_PREFIX}.${AIPrefixes.usage}.${AIUsagePostfixes.promptTokens}` as const\n\nconst RESPONSE_TEXT =\n `${AI_PREFIX}.${AIPrefixes.response}.${AIResultPostfixes.text}` as const\n\nconst RESPONSE_TOOL_CALLS =\n `${AI_PREFIX}.${AIPrefixes.response}.${AIResultPostfixes.toolCalls}` as const\n\nconst RESULT_OBJECT =\n `${AI_PREFIX}.${AIPrefixes.response}.${AIResultPostfixes.object}` as const\n\nconst PROMPT = `${AI_PREFIX}.${AIPrefixes.prompt}` as const\n\nconst PROMPT_MESSAGES = `${PROMPT}.${AIPromptPostfixes.messages}` as const\n\nconst EMBEDDING_TEXT = `${AI_PREFIX}.value` as const\nconst EMBEDDING_VECTOR = `${AI_PREFIX}.embedding` as const\n\nconst EMBEDDING_TEXTS = `${AI_PREFIX}.values` as const\nconst EMBEDDING_VECTORS = `${AI_PREFIX}.embeddings` as const\n\nconst TOOL_CALL_ID =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.id}` as const\nconst TOOL_CALL_NAME =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.name}` as const\nconst TOOL_CALL_ARGS =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.args}` as const\nconst TOOL_CALL_RESULT =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.result}` as const\n\n/**\n * The semantic conventions used by the Vercel AI SDK.\n * @see https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#collected-data\n */\nexport const AISemanticConventions = {\n MODEL_ID,\n METADATA,\n SETTINGS,\n TOKEN_COUNT_COMPLETION,\n TOKEN_COUNT_PROMPT,\n RESPONSE_TEXT,\n RESPONSE_TOOL_CALLS,\n RESULT_OBJECT,\n PROMPT,\n PROMPT_MESSAGES,\n EMBEDDING_TEXT,\n EMBEDDING_VECTOR,\n EMBEDDING_TEXTS,\n EMBEDDING_VECTORS,\n TOOL_CALL_ID,\n TOOL_CALL_NAME,\n TOOL_CALL_ARGS,\n TOOL_CALL_RESULT,\n} as const\n\nexport const AISemanticConventionsList = Object.freeze(\n Object.values(AISemanticConventions),\n)\n\nexport type AISemanticConvention =\n (typeof AISemanticConventions)[keyof typeof AISemanticConventions]\n","import {\n ReadableSpan,\n SimpleSpanProcessor,\n SpanProcessor,\n BatchSpanProcessor,\n} from '@opentelemetry/sdk-trace-base'\nimport type { ToolCallPart } from 'ai'\n\nimport { AISemanticConventions } from './conventions'\n\nexport class VercelSpanProcessor\n extends SimpleSpanProcessor\n implements SpanProcessor\n{\n onEnd(span: ReadableSpan): void {\n if (!shouldProcess(span)) return\n if (shouldConvertToLatitudeFormat(span)) convertToLatitudeFormat(span)\n\n super.onEnd(span)\n }\n}\n\nexport class VercelBatchSpanProcessor\n extends BatchSpanProcessor\n implements SpanProcessor\n{\n onEnd(span: ReadableSpan): void {\n if (!shouldProcess(span)) return\n if (shouldConvertToLatitudeFormat(span)) convertToLatitudeFormat(span)\n\n super.onEnd(span)\n }\n}\n\nfunction shouldProcess(span: ReadableSpan): boolean {\n return (\n Object.keys(span.attributes).some((k) => k.startsWith('latitude.')) ||\n Object.keys(span.attributes).some((k) => k.startsWith('ai.'))\n )\n}\n\nfunction shouldConvertToLatitudeFormat(span: ReadableSpan): boolean {\n return Object.keys(span.attributes).some((k) => k.startsWith('ai.'))\n}\n\nfunction convertToLatitudeFormat(span: ReadableSpan): void {\n try {\n const computedAttrs = computeOpenLLMAttributes(span)\n if (computedAttrs) {\n ;(span as any).attributes = {\n ...span.attributes,\n ...computedAttrs,\n }\n }\n } catch (e) {\n console.log('Latitude telemetry Error: ', e)\n // do nothing\n }\n}\n\nfunction computeOpenLLMAttributes(span: ReadableSpan) {\n const attrs = span.attributes || {}\n const result: Record<string, string | number | boolean> = {}\n\n // Extract model information\n if (attrs[AISemanticConventions.MODEL_ID]) {\n result['gen_ai.request.model'] = String(\n attrs[AISemanticConventions.MODEL_ID],\n )\n result['gen_ai.response.model'] = String(\n attrs[AISemanticConventions.MODEL_ID],\n )\n }\n\n // Extract settings\n try {\n const settings = attrs[AISemanticConventions.SETTINGS]\n ? JSON.parse(String(attrs[AISemanticConventions.SETTINGS]))\n : {}\n\n if (settings) {\n // Add max tokens if present\n if (settings.maxTokens) {\n result['gen_ai.request.max_tokens'] = settings.maxTokens\n }\n\n if (!attrs['gen_ai.system'] && settings.provider) {\n result['gen_ai.system'] = String(settings.provider)\n }\n }\n } catch (e) {\n console.error('Error parsing settings', e)\n }\n\n // Set request type to chat as that's what Vercel AI SDK uses\n result['llm.request.type'] = 'chat'\n\n // Extract messages\n try {\n const messages = attrs['ai.prompt.messages']\n ? JSON.parse(String(attrs['ai.prompt.messages']))\n : []\n\n // Process prompt messages\n messages.forEach((msg: any, index: number) => {\n result[`gen_ai.prompt.${index}.role`] = msg.role\n result[`gen_ai.prompt.${index}.content`] =\n typeof msg.content === 'string'\n ? msg.content\n : JSON.stringify(msg.content)\n })\n } catch (e) {\n console.error('Error parsing messages', e)\n\n return undefined\n }\n\n // Extract completion/response\n const responseText = attrs['ai.response.text']\n const responseObject = attrs['ai.response.object']\n const responseToolCalls = attrs['ai.response.toolCalls']\n if (responseText) {\n result[`gen_ai.completion.0.role`] = 'assistant'\n result[`gen_ai.completion.0.content`] = String(responseText)\n } else if (responseToolCalls) {\n try {\n const toolCalls = JSON.parse(String(responseToolCalls))\n if (toolCalls.length > 0) {\n result['gen_ai.completion.0.finish_reason'] = 'tool_calls'\n result[`gen_ai.completion.0.role`] = 'assistant'\n\n toolCalls.forEach((toolCall: ToolCallPart, toolCallIndex: number) => {\n result[`gen_ai.completion.0.tool_calls.${toolCallIndex}.id`] =\n toolCall.toolCallId\n result[`gen_ai.completion.0.tool_calls.${toolCallIndex}.name`] =\n toolCall.toolName\n result[`gen_ai.completion.0.tool_calls.${toolCallIndex}.arguments`] =\n toolCall.args as string\n })\n }\n } catch (e) {\n console.error('Error parsing tool calls', e)\n }\n } else if (responseObject) {\n result['gen_ai.completion.0.role'] = 'assistant'\n result['gen_ai.completion.0.content'] = String(responseObject)\n }\n\n // Extract token usage\n const completionTokens = attrs['ai.usage.completionTokens']\n const promptTokens = attrs['ai.usage.promptTokens']\n\n if (typeof completionTokens === 'number') {\n result['gen_ai.usage.completion_tokens'] = completionTokens\n }\n if (typeof promptTokens === 'number') {\n result['gen_ai.usage.prompt_tokens'] = promptTokens\n }\n if (\n typeof completionTokens === 'number' &&\n typeof promptTokens === 'number'\n ) {\n result['llm.usage.total_tokens'] = completionTokens + promptTokens\n }\n\n return result\n}\n","import { NodeSDK } from '@opentelemetry/sdk-node'\nimport {\n SimpleSpanProcessor,\n BatchSpanProcessor,\n SpanExporter,\n} from '@opentelemetry/sdk-trace-node'\n\nimport { AnthropicInstrumentation } from '@traceloop/instrumentation-anthropic'\nimport { OpenAIInstrumentation } from '@traceloop/instrumentation-openai'\nimport { AzureOpenAIInstrumentation } from '@traceloop/instrumentation-azure'\nimport {\n AIPlatformInstrumentation,\n VertexAIInstrumentation,\n} from '@traceloop/instrumentation-vertexai'\nimport { BedrockInstrumentation } from '@traceloop/instrumentation-bedrock'\nimport { CohereInstrumentation } from '@traceloop/instrumentation-cohere'\n\nimport type * as openai from 'openai'\nimport type * as anthropic from '@anthropic-ai/sdk'\nimport type * as azure from '@azure/openai'\nimport type * as cohere from 'cohere-ai'\nimport type * as bedrock from '@aws-sdk/client-bedrock-runtime'\nimport type * as aiplatform from '@google-cloud/aiplatform'\nimport type * as vertexAI from '@google-cloud/vertexai'\nimport type * as pinecone from '@pinecone-database/pinecone'\nimport type * as ChainsModule from 'langchain/chains'\nimport type * as AgentsModule from 'langchain/agents'\nimport type * as ToolsModule from 'langchain/tools'\nimport type * as RunnableModule from '@langchain/core/runnables'\nimport type * as VectorStoreModule from '@langchain/core/vectorstores'\nimport type * as llamaindex from 'llamaindex'\nimport type * as chromadb from 'chromadb'\nimport type * as qdrant from '@qdrant/js-client-rest'\nimport { Resource } from '@opentelemetry/resources'\nimport { context, trace } from '@opentelemetry/api'\n\ntype IModules = {\n openAI?: typeof openai.OpenAI\n anthropic?: typeof anthropic\n azureOpenAI?: typeof azure\n cohere?: typeof cohere\n bedrock?: typeof bedrock\n google_vertexai?: typeof vertexAI\n google_aiplatform?: typeof aiplatform\n pinecone?: typeof pinecone\n langchain?: {\n chainsModule?: typeof ChainsModule\n agentsModule?: typeof AgentsModule\n toolsModule?: typeof ToolsModule\n runnablesModule?: typeof RunnableModule\n vectorStoreModule?: typeof VectorStoreModule\n }\n llamaIndex?: typeof llamaindex\n chromadb?: typeof chromadb\n qdrant?: typeof qdrant\n}\n\ntype SpanAttributes = {\n name?: string\n metadata?: Record<string, unknown>\n prompt?: {\n uuid: string\n versionUuid?: string\n parameters?: Record<string, unknown>\n }\n distinctId?: string\n}\n\nexport type LatitudeTelemetrySDKConfig = {\n exporter: SpanExporter\n modules?: IModules\n disableBatch?: boolean\n processors?: (typeof SimpleSpanProcessor)[] | (typeof BatchSpanProcessor)[]\n}\n\nexport class LatitudeTelemetrySDK {\n private exporter: SpanExporter\n\n constructor({\n exporter,\n modules = {},\n disableBatch = false,\n processors = [],\n }: LatitudeTelemetrySDKConfig) {\n this.exporter = exporter\n\n this._init(modules, { disableBatch, processors })\n }\n\n private _init(\n modules: IModules,\n options?: {\n disableBatch?: boolean\n processors?:\n | (typeof SimpleSpanProcessor)[]\n | (typeof BatchSpanProcessor)[]\n },\n ) {\n const instrumentations = []\n\n if (modules?.openAI) {\n const openAIInstrumentation = new OpenAIInstrumentation({\n enrichTokens: true,\n })\n // @ts-ignore\n openAIInstrumentation.manuallyInstrument(modules.openAI!)\n instrumentations.push(openAIInstrumentation)\n }\n\n if (modules?.anthropic) {\n const anthropicInstrumentation = new AnthropicInstrumentation()\n anthropicInstrumentation.manuallyInstrument(modules.anthropic!)\n instrumentations.push(new AnthropicInstrumentation())\n }\n\n if (modules?.azureOpenAI) {\n const azureOpenAIInstrumentation = new AzureOpenAIInstrumentation()\n azureOpenAIInstrumentation.manuallyInstrument(modules.azureOpenAI!)\n instrumentations.push(azureOpenAIInstrumentation)\n }\n\n if (modules?.cohere) {\n const cohereInstrumentation = new CohereInstrumentation()\n cohereInstrumentation.manuallyInstrument(modules.cohere!)\n instrumentations.push(cohereInstrumentation)\n }\n\n if (modules?.google_vertexai) {\n const vertexAIInstrumentation = new VertexAIInstrumentation()\n vertexAIInstrumentation.manuallyInstrument(modules.google_vertexai!)\n instrumentations.push(vertexAIInstrumentation)\n }\n\n if (modules?.google_aiplatform) {\n const aiplatformInstrumentation = new AIPlatformInstrumentation()\n aiplatformInstrumentation.manuallyInstrument(modules.google_aiplatform!)\n instrumentations.push(aiplatformInstrumentation)\n }\n\n if (modules?.bedrock) {\n const bedrockInstrumentation = new BedrockInstrumentation()\n bedrockInstrumentation.manuallyInstrument(modules.bedrock!)\n instrumentations.push(bedrockInstrumentation)\n }\n\n // TODO: Enable these once we have manually tested them\n //if (modules?.langchain) {\n // const langchainInstrumentation = new LangChainInstrumentation()\n // langchainInstrumentation.manuallyInstrument(modules.langchain!)\n // instrumentations.push(langchainInstrumentation)\n //}\n //\n //if (modules?.llamaIndex) {\n // const llamaindexInstrumentation = new LlamaIndexInstrumentation()\n // llamaindexInstrumentation.manuallyInstrument(modules.llamaIndex!)\n // instrumentations.push(llamaindexInstrumentation)\n //}\n\n //if (modules?.pinecone) {\n // const pineconeInstrumentation = new PineconeInstrumentation()\n // pineconeInstrumentation.manuallyInstrument(modules.pinecone!)\n // instrumentations.push(pineconeInstrumentation)\n //}\n\n //if (modules?.chromadb) {\n // const chromadbInstrumentation = new ChromaDBInstrumentation()\n // chromadbInstrumentation.manuallyInstrument(modules.chromadb!)\n // instrumentations.push(chromadbInstrumentation)\n //}\n\n //if (modules?.qdrant) {\n // const qdrantInstrumentation = new QdrantInstrumentation()\n // qdrantInstrumentation.manuallyInstrument(modules.qdrant!)\n // instrumentations.push(qdrantInstrumentation)\n //}\n\n if (!instrumentations.length && !options?.processors?.length) {\n console.warn('Latitude: No instrumentations or processors to initialize')\n return\n }\n\n const processors = options?.disableBatch\n ? [\n new SimpleSpanProcessor(this.exporter),\n ...(options?.processors?.map(\n (processor) => new processor(this.exporter),\n ) || []),\n ]\n : [\n new BatchSpanProcessor(this.exporter),\n ...(options?.processors?.map(\n (processor) => new processor(this.exporter),\n ) || []),\n ]\n\n const sdk = new NodeSDK({\n resource: new Resource({\n 'service.name': process.env.npm_package_name,\n }),\n instrumentations,\n traceExporter: this.exporter,\n // @ts-ignore\n spanProcessors: processors,\n })\n\n sdk.start()\n }\n\n span<T>(s: SpanAttributes, fn: (span: any) => T): Promise<T> {\n const c = context.active()\n return context.with(c, () =>\n trace\n .getTracer('latitude')\n .startActiveSpan(s.name ?? 'latitude.span', {}, c, async (span) => {\n try {\n if (s.prompt) {\n try {\n span.setAttribute('latitude.prompt', JSON.stringify(s.prompt))\n } catch (e) {\n console.error(\n 'Latitude: Could not serialize latitude.prompt attribute',\n e,\n )\n }\n }\n\n if (s.distinctId) {\n span.setAttribute('latitude.distinctId', s.distinctId)\n }\n\n if (s.metadata) {\n try {\n span.setAttribute(\n 'latitude.metadata',\n JSON.stringify(s.metadata),\n )\n } catch (e) {\n console.error(\n 'Latitude: Could not serialize latitude.metadata attribute',\n e,\n )\n }\n }\n } catch (error) {\n console.error(error)\n }\n\n const res = fn(span)\n if (res instanceof Promise) {\n return res.then((resolvedRes) => {\n span.end()\n\n return resolvedRes\n })\n }\n\n span.end()\n\n return res\n }),\n )\n }\n}\n"],"names":["OTLPExporterBase","ExportResultCode","hrTimeToNanoseconds","SimpleSpanProcessor","BatchSpanProcessor","OpenAIInstrumentation","AnthropicInstrumentation","AzureOpenAIInstrumentation","CohereInstrumentation","VertexAIInstrumentation","AIPlatformInstrumentation","BedrockInstrumentation","NodeSDK","Resource","context","trace"],"mappings":";;;;;;;;;;;;;;;;AAOA,MAAM,MAAM,GAEN;IAC4B;AAClC,MAAM,QAAQ,GAA2C,OAAO,CAAS;AAOnE,MAAO,gBACX,SAAQA,iCAA+B,CAAA;AAGvC,IAAA,GAAG;AACK,IAAA,OAAO;AAEf,IAAA,WAAA,CAAY,MAA8B,EAAA;QACxC,KAAK,CAAC,MAAM,CAAC;QAEb,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,YAAY;QAC/C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ACV,wBAAA,OAAO,CAAC,KAAK,CACX,yDAAyD,EACzD,CAAC,CACF;;;AAIL,gBAAA,IAAI,CAAC,CAAC,UAAU,EAAE;oBAChB,IAAI,CAAC,YAAY,CAAC,qBAAqB,EAAE,CAAC,CAAC,UAAU,CAAC;;AAGxD,gBAAA,IAAI,CAAC,CAAC,QAAQ,EAAE;AACd,oBAAA,IAAI;AACF,wBAAA,IAAI,CAAC,YAAY,CACf,mBAAmB,EACnB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAC3B;;oBACD,OAAO,CAAC,EAAE;AACV,wBAAA,OAAO,CAAC,KAAK,CACX,2DAA2D,EAC3D,CAAC,CACF;;;;YAGL,OAAO,KAAK,EAAE;AACd,gBAAA,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;;AAGtB,YAAA,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;AACpB,YAAA,IAAI,GAAG,YAAY,OAAO,EAAE;AAC1B,gBAAA,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,KAAI;oBAC9B,IAAI,CAAC,GAAG,EAAE;AAEV,oBAAA,OAAO,WAAW;AACpB,iBAAC,CAAC;;YAGJ,IAAI,CAAC,GAAG,EAAE;AAEV,YAAA,OAAO,GAAG;SACX,CAAC,CACL;;AAEJ;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -107,7 +107,7 @@ declare class VercelBatchSpanProcessor extends BatchSpanProcessor implements Spa
107
107
  }
108
108
 
109
109
  type IModules = {
110
- openAI?: typeof openai;
110
+ openAI?: typeof openai.OpenAI;
111
111
  anthropic?: typeof anthropic;
112
112
  azureOpenAI?: typeof azure;
113
113
  cohere?: typeof cohere;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/exporters/latitudeExporter.ts","../src/processors/vercel/conventions.ts","../src/processors/vercel/index.ts","../src/telemetry/index.ts"],"sourcesContent":["import { ExportResultCode, hrTimeToNanoseconds } from '@opentelemetry/core'\nimport {\n OTLPExporterBase,\n OTLPExporterConfigBase,\n} from '@opentelemetry/otlp-exporter-base'\nimport { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'\n\nconst DOMAIN =\n process.env.NODE_ENV === 'production'\n ? 'gateway.latitude.so/api/v2/otlp'\n : 'localhost:8787/api/v2/otlp'\nconst PROTOCOL = process.env.NODE_ENV === 'production' ? 'https' : 'http'\n\ninterface OTLPHttpExporterConfig extends OTLPExporterConfigBase {\n apiKey: string\n endpoint?: string\n}\n\nexport class LatitudeExporter\n extends OTLPExporterBase<any, any, any>\n implements SpanExporter\n{\n url: string\n private headers: Record<string, string>\n\n constructor(config: OTLPHttpExporterConfig) {\n super(config)\n\n this.url = config.endpoint || this.__defaultUrl\n this.headers = {\n Authorization: `Bearer ${config.apiKey}`,\n }\n }\n\n async export(\n spans: ReadableSpan[],\n resultCallback: (result: any) => void,\n ): Promise<void> {\n await this.send(\n spans,\n () => resultCallback({ code: ExportResultCode.SUCCESS }),\n (error) => {\n resultCallback({ code: ExportResultCode.FAILED, error })\n },\n )\n }\n\n async shutdown(): Promise<void> {\n // No-op\n }\n\n async onShutdown(): Promise<void> {\n // No-op\n }\n\n async onInit(): Promise<void> {\n // No-op\n }\n\n async send(\n spans: ReadableSpan[],\n onSuccess: () => void,\n onError: (error: Error) => void,\n ): Promise<void> {\n if (spans.length === 0) {\n onSuccess()\n return\n }\n\n const serviceRequest = this.convert(spans)\n const body = JSON.stringify(serviceRequest)\n\n try {\n const response = await fetch(this.url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.headers,\n },\n body,\n })\n\n if (!response.ok || response.status >= 400) {\n throw new Error(`${response.status} ${response.statusText}`)\n }\n\n onSuccess()\n } catch (error) {\n onError(error as Error)\n }\n }\n\n convert(spans: ReadableSpan[]) {\n return {\n resourceSpans: [\n {\n resource: {\n attributes: this.convertAttributes(\n spans[0]?.resource?.attributes || {},\n ),\n },\n scopeSpans: [\n {\n spans: spans.map((span) => ({\n traceId: span.spanContext().traceId,\n spanId: span.spanContext().spanId,\n parentSpanId: span.parentSpanId,\n name: span.name,\n kind: span.kind,\n startTimeUnixNano: hrTimeToNanoseconds(\n span.startTime,\n ).toString(),\n endTimeUnixNano: span.endTime\n ? hrTimeToNanoseconds(span.endTime).toString()\n : undefined,\n attributes: this.convertAttributes(span.attributes),\n status: span.status && {\n code: span.status.code,\n message: span.status.message,\n },\n events: span.events?.map((event) => ({\n timeUnixNano: hrTimeToNanoseconds(event.time).toString(),\n name: event.name,\n attributes: this.convertAttributes(event.attributes),\n })),\n links: span.links?.map((link) => ({\n traceId: link.context.traceId,\n spanId: link.context.spanId,\n attributes: this.convertAttributes(link.attributes),\n })),\n })),\n },\n ],\n },\n ],\n }\n }\n\n getDefaultUrl(config: any): string {\n return config.endpoint || this.__defaultUrl\n }\n\n private get __defaultUrl(): string {\n return `${PROTOCOL}://${DOMAIN}/v1/traces`\n }\n\n private convertAttributes(attributes: Record<string, unknown> = {}): Array<{\n key: string\n value: { stringValue?: string; intValue?: number; boolValue?: boolean }\n }> {\n return Object.entries(attributes).map(([key, value]) => ({\n key,\n value: this.convertAttributeValue(value),\n }))\n }\n\n private convertAttributeValue(value: unknown): {\n stringValue?: string\n intValue?: number\n boolValue?: boolean\n } {\n if (typeof value === 'string') return { stringValue: value }\n if (typeof value === 'number') return { intValue: value }\n if (typeof value === 'boolean') return { boolValue: value }\n return { stringValue: String(value) }\n }\n}\n","/**\n * Below are the semantic conventions for the Vercel AI SDK.\n * @see https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#collected-data\n */\nconst AI_PREFIX = 'ai' as const\n\nconst AIPrefixes = {\n settings: 'settings',\n model: 'model',\n usage: 'usage',\n telemetry: 'telemetry',\n prompt: 'prompt',\n toolCall: 'toolCall',\n response: 'response',\n} as const\n\nconst AIUsagePostfixes = {\n completionTokens: 'completionTokens',\n promptTokens: 'promptTokens',\n} as const\n\nconst AIResultPostfixes = {\n text: 'text',\n toolCalls: 'toolCalls',\n object: 'object',\n} as const\n\nconst AIPromptPostfixes = {\n messages: 'messages',\n} as const\n\nconst AIToolCallPostfixes = {\n id: 'id',\n name: 'name',\n args: 'args',\n result: 'result',\n} as const\n\nconst SETTINGS = `${AI_PREFIX}.${AIPrefixes.settings}` as const\n\nconst MODEL_ID = `${AI_PREFIX}.${AIPrefixes.model}.id` as const\n\nconst METADATA = `${AI_PREFIX}.${AIPrefixes.telemetry}.metadata` as const\n\nconst TOKEN_COUNT_COMPLETION =\n `${AI_PREFIX}.${AIPrefixes.usage}.${AIUsagePostfixes.completionTokens}` as const\n\nconst TOKEN_COUNT_PROMPT =\n `${AI_PREFIX}.${AIPrefixes.usage}.${AIUsagePostfixes.promptTokens}` as const\n\nconst RESPONSE_TEXT =\n `${AI_PREFIX}.${AIPrefixes.response}.${AIResultPostfixes.text}` as const\n\nconst RESPONSE_TOOL_CALLS =\n `${AI_PREFIX}.${AIPrefixes.response}.${AIResultPostfixes.toolCalls}` as const\n\nconst RESULT_OBJECT =\n `${AI_PREFIX}.${AIPrefixes.response}.${AIResultPostfixes.object}` as const\n\nconst PROMPT = `${AI_PREFIX}.${AIPrefixes.prompt}` as const\n\nconst PROMPT_MESSAGES = `${PROMPT}.${AIPromptPostfixes.messages}` as const\n\nconst EMBEDDING_TEXT = `${AI_PREFIX}.value` as const\nconst EMBEDDING_VECTOR = `${AI_PREFIX}.embedding` as const\n\nconst EMBEDDING_TEXTS = `${AI_PREFIX}.values` as const\nconst EMBEDDING_VECTORS = `${AI_PREFIX}.embeddings` as const\n\nconst TOOL_CALL_ID =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.id}` as const\nconst TOOL_CALL_NAME =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.name}` as const\nconst TOOL_CALL_ARGS =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.args}` as const\nconst TOOL_CALL_RESULT =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.result}` as const\n\n/**\n * The semantic conventions used by the Vercel AI SDK.\n * @see https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#collected-data\n */\nexport const AISemanticConventions = {\n MODEL_ID,\n METADATA,\n SETTINGS,\n TOKEN_COUNT_COMPLETION,\n TOKEN_COUNT_PROMPT,\n RESPONSE_TEXT,\n RESPONSE_TOOL_CALLS,\n RESULT_OBJECT,\n PROMPT,\n PROMPT_MESSAGES,\n EMBEDDING_TEXT,\n EMBEDDING_VECTOR,\n EMBEDDING_TEXTS,\n EMBEDDING_VECTORS,\n TOOL_CALL_ID,\n TOOL_CALL_NAME,\n TOOL_CALL_ARGS,\n TOOL_CALL_RESULT,\n} as const\n\nexport const AISemanticConventionsList = Object.freeze(\n Object.values(AISemanticConventions),\n)\n\nexport type AISemanticConvention =\n (typeof AISemanticConventions)[keyof typeof AISemanticConventions]\n","import {\n ReadableSpan,\n SimpleSpanProcessor,\n SpanProcessor,\n BatchSpanProcessor,\n} from '@opentelemetry/sdk-trace-base'\nimport type { ToolCallPart } from 'ai'\n\nimport { AISemanticConventions } from './conventions'\n\nexport class VercelSpanProcessor\n extends SimpleSpanProcessor\n implements SpanProcessor\n{\n onEnd(span: ReadableSpan): void {\n if (!shouldProcess(span)) return\n if (shouldConvertToLatitudeFormat(span)) convertToLatitudeFormat(span)\n\n super.onEnd(span)\n }\n}\n\nexport class VercelBatchSpanProcessor\n extends BatchSpanProcessor\n implements SpanProcessor\n{\n onEnd(span: ReadableSpan): void {\n if (!shouldProcess(span)) return\n if (shouldConvertToLatitudeFormat(span)) convertToLatitudeFormat(span)\n\n super.onEnd(span)\n }\n}\n\nfunction shouldProcess(span: ReadableSpan): boolean {\n return (\n Object.keys(span.attributes).some((k) => k.startsWith('latitude.')) ||\n Object.keys(span.attributes).some((k) => k.startsWith('ai.'))\n )\n}\n\nfunction shouldConvertToLatitudeFormat(span: ReadableSpan): boolean {\n return Object.keys(span.attributes).some((k) => k.startsWith('ai.'))\n}\n\nfunction convertToLatitudeFormat(span: ReadableSpan): void {\n try {\n const computedAttrs = computeOpenLLMAttributes(span)\n if (computedAttrs) {\n ;(span as any).attributes = {\n ...span.attributes,\n ...computedAttrs,\n }\n }\n } catch (e) {\n console.log('Latitude telemetry Error: ', e)\n // do nothing\n }\n}\n\nfunction computeOpenLLMAttributes(span: ReadableSpan) {\n const attrs = span.attributes || {}\n const result: Record<string, string | number | boolean> = {}\n\n // Extract model information\n if (attrs[AISemanticConventions.MODEL_ID]) {\n result['gen_ai.request.model'] = String(\n attrs[AISemanticConventions.MODEL_ID],\n )\n result['gen_ai.response.model'] = String(\n attrs[AISemanticConventions.MODEL_ID],\n )\n }\n\n // Extract settings\n try {\n const settings = attrs[AISemanticConventions.SETTINGS]\n ? JSON.parse(String(attrs[AISemanticConventions.SETTINGS]))\n : {}\n\n if (settings) {\n // Add max tokens if present\n if (settings.maxTokens) {\n result['gen_ai.request.max_tokens'] = settings.maxTokens\n }\n\n if (!attrs['gen_ai.system'] && settings.provider) {\n result['gen_ai.system'] = String(settings.provider)\n }\n }\n } catch (e) {\n console.error('Error parsing settings', e)\n }\n\n // Set request type to chat as that's what Vercel AI SDK uses\n result['llm.request.type'] = 'chat'\n\n // Extract messages\n try {\n const messages = attrs['ai.prompt.messages']\n ? JSON.parse(String(attrs['ai.prompt.messages']))\n : []\n\n // Process prompt messages\n messages.forEach((msg: any, index: number) => {\n result[`gen_ai.prompt.${index}.role`] = msg.role\n result[`gen_ai.prompt.${index}.content`] =\n typeof msg.content === 'string'\n ? msg.content\n : JSON.stringify(msg.content)\n })\n } catch (e) {\n console.error('Error parsing messages', e)\n return undefined\n }\n\n // Extract completion/response\n const responseText = attrs['ai.response.text']\n const responseObject = attrs['ai.response.object']\n const responseToolCalls = attrs['ai.response.toolCalls']\n if (responseText) {\n result[`gen_ai.completion.0.role`] = 'assistant'\n result[`gen_ai.completion.0.content`] = String(responseText)\n } else if (responseToolCalls) {\n try {\n const toolCalls = JSON.parse(String(responseToolCalls))\n if (toolCalls.length > 0) {\n result['gen_ai.completion.0.finish_reason'] = 'tool_calls'\n result[`gen_ai.completion.0.role`] = 'assistant'\n\n toolCalls.forEach((toolCall: ToolCallPart, toolCallIndex: number) => {\n result[`gen_ai.completion.0.tool_calls.${toolCallIndex}.id`] =\n toolCall.toolCallId\n result[`gen_ai.completion.0.tool_calls.${toolCallIndex}.name`] =\n toolCall.toolName\n result[`gen_ai.completion.0.tool_calls.${toolCallIndex}.arguments`] =\n toolCall.args as string\n })\n }\n } catch (e) {\n console.error('Error parsing tool calls', e)\n }\n } else if (responseObject) {\n result['gen_ai.completion.0.role'] = 'assistant'\n result['gen_ai.completion.0.content'] = String(responseObject)\n }\n\n // Extract token usage\n const completionTokens = attrs['ai.usage.completionTokens']\n const promptTokens = attrs['ai.usage.promptTokens']\n\n if (typeof completionTokens === 'number') {\n result['gen_ai.usage.completion_tokens'] = completionTokens\n }\n if (typeof promptTokens === 'number') {\n result['gen_ai.usage.prompt_tokens'] = promptTokens\n }\n if (\n typeof completionTokens === 'number' &&\n typeof promptTokens === 'number'\n ) {\n result['llm.usage.total_tokens'] = completionTokens + promptTokens\n }\n\n return result\n}\n","import { NodeSDK } from '@opentelemetry/sdk-node'\nimport {\n SimpleSpanProcessor,\n BatchSpanProcessor,\n SpanExporter,\n} from '@opentelemetry/sdk-trace-node'\n\nimport { AnthropicInstrumentation } from '@traceloop/instrumentation-anthropic'\nimport { OpenAIInstrumentation } from '@traceloop/instrumentation-openai'\nimport { AzureOpenAIInstrumentation } from '@traceloop/instrumentation-azure'\nimport {\n AIPlatformInstrumentation,\n VertexAIInstrumentation,\n} from '@traceloop/instrumentation-vertexai'\nimport { BedrockInstrumentation } from '@traceloop/instrumentation-bedrock'\nimport { CohereInstrumentation } from '@traceloop/instrumentation-cohere'\n\nimport type * as openai from 'openai'\nimport type * as anthropic from '@anthropic-ai/sdk'\nimport type * as azure from '@azure/openai'\nimport type * as cohere from 'cohere-ai'\nimport type * as bedrock from '@aws-sdk/client-bedrock-runtime'\nimport type * as aiplatform from '@google-cloud/aiplatform'\nimport type * as vertexAI from '@google-cloud/vertexai'\nimport type * as pinecone from '@pinecone-database/pinecone'\nimport type * as ChainsModule from 'langchain/chains'\nimport type * as AgentsModule from 'langchain/agents'\nimport type * as ToolsModule from 'langchain/tools'\nimport type * as RunnableModule from '@langchain/core/runnables'\nimport type * as VectorStoreModule from '@langchain/core/vectorstores'\nimport type * as llamaindex from 'llamaindex'\nimport type * as chromadb from 'chromadb'\nimport type * as qdrant from '@qdrant/js-client-rest'\nimport { Resource } from '@opentelemetry/resources'\nimport { context, trace } from '@opentelemetry/api'\n\ntype IModules = {\n openAI?: typeof openai\n anthropic?: typeof anthropic\n azureOpenAI?: typeof azure\n cohere?: typeof cohere\n bedrock?: typeof bedrock\n google_vertexai?: typeof vertexAI\n google_aiplatform?: typeof aiplatform\n pinecone?: typeof pinecone\n langchain?: {\n chainsModule?: typeof ChainsModule\n agentsModule?: typeof AgentsModule\n toolsModule?: typeof ToolsModule\n runnablesModule?: typeof RunnableModule\n vectorStoreModule?: typeof VectorStoreModule\n }\n llamaIndex?: typeof llamaindex\n chromadb?: typeof chromadb\n qdrant?: typeof qdrant\n}\n\ntype SpanAttributes = {\n name?: string\n metadata?: Record<string, unknown>\n prompt?: {\n uuid: string\n versionUuid?: string\n parameters?: Record<string, unknown>\n }\n distinctId?: string\n}\n\nexport type LatitudeTelemetrySDKConfig = {\n exporter: SpanExporter\n modules?: IModules\n disableBatch?: boolean\n processors?: (typeof SimpleSpanProcessor)[] | (typeof BatchSpanProcessor)[]\n}\n\nexport class LatitudeTelemetrySDK {\n private exporter: SpanExporter\n\n constructor({\n exporter,\n modules = {},\n disableBatch = false,\n processors = [],\n }: LatitudeTelemetrySDKConfig) {\n this.exporter = exporter\n\n this._init(modules, { disableBatch, processors })\n }\n\n private _init(\n modules: IModules,\n options?: {\n disableBatch?: boolean\n processors?:\n | (typeof SimpleSpanProcessor)[]\n | (typeof BatchSpanProcessor)[]\n },\n ) {\n const instrumentations = []\n\n if (modules?.openAI) {\n const openAIInstrumentation = new OpenAIInstrumentation({\n enrichTokens: true,\n })\n // @ts-ignore\n openAIInstrumentation.manuallyInstrument(modules.openAI!)\n instrumentations.push(openAIInstrumentation)\n }\n\n if (modules?.anthropic) {\n const anthropicInstrumentation = new AnthropicInstrumentation()\n anthropicInstrumentation.manuallyInstrument(modules.anthropic!)\n instrumentations.push(new AnthropicInstrumentation())\n }\n\n if (modules?.azureOpenAI) {\n const azureOpenAIInstrumentation = new AzureOpenAIInstrumentation()\n azureOpenAIInstrumentation.manuallyInstrument(modules.azureOpenAI!)\n instrumentations.push(azureOpenAIInstrumentation)\n }\n\n if (modules?.cohere) {\n const cohereInstrumentation = new CohereInstrumentation()\n cohereInstrumentation.manuallyInstrument(modules.cohere!)\n instrumentations.push(cohereInstrumentation)\n }\n\n if (modules?.google_vertexai) {\n const vertexAIInstrumentation = new VertexAIInstrumentation()\n vertexAIInstrumentation.manuallyInstrument(modules.google_vertexai!)\n instrumentations.push(vertexAIInstrumentation)\n }\n\n if (modules?.google_aiplatform) {\n const aiplatformInstrumentation = new AIPlatformInstrumentation()\n aiplatformInstrumentation.manuallyInstrument(modules.google_aiplatform!)\n instrumentations.push(aiplatformInstrumentation)\n }\n\n if (modules?.bedrock) {\n const bedrockInstrumentation = new BedrockInstrumentation()\n bedrockInstrumentation.manuallyInstrument(modules.bedrock!)\n instrumentations.push(bedrockInstrumentation)\n }\n\n // TODO: Enable these once we have manually tested them\n //if (modules?.langchain) {\n // const langchainInstrumentation = new LangChainInstrumentation()\n // langchainInstrumentation.manuallyInstrument(modules.langchain!)\n // instrumentations.push(langchainInstrumentation)\n //}\n //\n //if (modules?.llamaIndex) {\n // const llamaindexInstrumentation = new LlamaIndexInstrumentation()\n // llamaindexInstrumentation.manuallyInstrument(modules.llamaIndex!)\n // instrumentations.push(llamaindexInstrumentation)\n //}\n\n //if (modules?.pinecone) {\n // const pineconeInstrumentation = new PineconeInstrumentation()\n // pineconeInstrumentation.manuallyInstrument(modules.pinecone!)\n // instrumentations.push(pineconeInstrumentation)\n //}\n\n //if (modules?.chromadb) {\n // const chromadbInstrumentation = new ChromaDBInstrumentation()\n // chromadbInstrumentation.manuallyInstrument(modules.chromadb!)\n // instrumentations.push(chromadbInstrumentation)\n //}\n\n //if (modules?.qdrant) {\n // const qdrantInstrumentation = new QdrantInstrumentation()\n // qdrantInstrumentation.manuallyInstrument(modules.qdrant!)\n // instrumentations.push(qdrantInstrumentation)\n //}\n\n if (!instrumentations.length && !options?.processors?.length) {\n console.warn('Latitude: No instrumentations or processors to initialize')\n return\n }\n\n const processors = options?.disableBatch\n ? [\n new SimpleSpanProcessor(this.exporter),\n ...(options?.processors?.map(\n (processor) => new processor(this.exporter),\n ) || []),\n ]\n : [\n new BatchSpanProcessor(this.exporter),\n ...(options?.processors?.map(\n (processor) => new processor(this.exporter),\n ) || []),\n ]\n\n const sdk = new NodeSDK({\n resource: new Resource({\n 'service.name': process.env.npm_package_name,\n }),\n instrumentations,\n traceExporter: this.exporter,\n // @ts-ignore\n spanProcessors: processors,\n })\n\n sdk.start()\n }\n\n span<T>(s: SpanAttributes, fn: (span: any) => T): Promise<T> {\n const c = context.active()\n return context.with(c, () =>\n trace\n .getTracer('latitude')\n .startActiveSpan(s.name ?? 'latitude.span', {}, c, async (span) => {\n try {\n if (s.prompt) {\n try {\n span.setAttribute('latitude.prompt', JSON.stringify(s.prompt))\n } catch (e) {\n console.error(\n 'Latitude: Could not serialize latitude.prompt attribute',\n e,\n )\n }\n }\n\n if (s.distinctId) {\n span.setAttribute('latitude.distinctId', s.distinctId)\n }\n\n if (s.metadata) {\n try {\n span.setAttribute(\n 'latitude.metadata',\n JSON.stringify(s.metadata),\n )\n } catch (e) {\n console.error(\n 'Latitude: Could not serialize latitude.metadata attribute',\n e,\n )\n }\n }\n } catch (error) {\n console.error(error)\n }\n\n const res = fn(span)\n if (res instanceof Promise) {\n return res.then((resolvedRes) => {\n span.end()\n\n return resolvedRes\n })\n }\n\n span.end()\n\n return res\n }),\n )\n }\n}\n"],"names":["SimpleSpanProcessor","BatchSpanProcessor"],"mappings":";;;;;;;;;;;;;;AAOA,MAAM,MAAM,GAEN;IAC4B;AAClC,MAAM,QAAQ,GAA2C,OAAO,CAAS;AAOnE,MAAO,gBACX,SAAQ,gBAA+B,CAAA;AAGvC,IAAA,GAAG;AACK,IAAA,OAAO;AAEf,IAAA,WAAA,CAAY,MAA8B,EAAA;QACxC,KAAK,CAAC,MAAM,CAAC;QAEb,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,YAAY;QAC/C,IAAI,CAAC,OAAO,GAAG;AACb,YAAA,aAAa,EAAE,CAAA,OAAA,EAAU,MAAM,CAAC,MAAM,CAAE,CAAA;SACzC;;AAGH,IAAA,MAAM,MAAM,CACV,KAAqB,EACrB,cAAqC,EAAA;QAErC,MAAM,IAAI,CAAC,IAAI,CACb,KAAK,EACL,MAAM,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,CAAC,EACxD,CAAC,KAAK,KAAI;YACR,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;AAC1D,SAAC,CACF;;AAGH,IAAA,MAAM,QAAQ,GAAA;;;AAId,IAAA,MAAM,UAAU,GAAA;;;AAIhB,IAAA,MAAM,MAAM,GAAA;;;AAIZ,IAAA,MAAM,IAAI,CACR,KAAqB,EACrB,SAAqB,EACrB,OAA+B,EAAA;AAE/B,QAAA,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;AACtB,YAAA,SAAS,EAAE;YACX;;QAGF,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;AAE3C,QAAA,IA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C,CACL;;AAEJ;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/exporters/latitudeExporter.ts","../src/processors/vercel/conventions.ts","../src/processors/vercel/index.ts","../src/telemetry/index.ts"],"sourcesContent":["import { ExportResultCode, hrTimeToNanoseconds } from '@opentelemetry/core'\nimport {\n OTLPExporterBase,\n OTLPExporterConfigBase,\n} from '@opentelemetry/otlp-exporter-base'\nimport { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'\n\nconst DOMAIN =\n process.env.NODE_ENV === 'production'\n ? 'gateway.latitude.so/api/v2/otlp'\n : 'localhost:8787/api/v2/otlp'\nconst PROTOCOL = process.env.NODE_ENV === 'production' ? 'https' : 'http'\n\ninterface OTLPHttpExporterConfig extends OTLPExporterConfigBase {\n apiKey: string\n endpoint?: string\n}\n\nexport class LatitudeExporter\n extends OTLPExporterBase<any, any, any>\n implements SpanExporter\n{\n url: string\n private headers: Record<string, string>\n\n constructor(config: OTLPHttpExporterConfig) {\n super(config)\n\n this.url = config.endpoint || this.__defaultUrl\n this.headers = {\n Authorization: `Bearer ${config.apiKey}`,\n }\n }\n\n async export(\n spans: ReadableSpan[],\n resultCallback: (result: any) => void,\n ): Promise<void> {\n await this.send(\n spans,\n () => resultCallback({ code: ExportResultCode.SUCCESS }),\n (error) => {\n resultCallback({ code: ExportResultCode.FAILED, error })\n },\n )\n }\n\n async shutdown(): Promise<void> {\n // No-op\n }\n\n async onShutdown(): Promise<void> {\n // No-op\n }\n\n async onInit(): Promise<void> {\n // No-op\n }\n\n async send(\n spans: ReadableSpan[],\n onSuccess: () => void,\n onError: (error: Error) => void,\n ): Promise<void> {\n if (spans.length === 0) {\n onSuccess()\n return\n }\n\n const serviceRequest = this.convert(spans)\n const body = JSON.stringify(serviceRequest)\n\n try {\n const response = await fetch(this.url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.headers,\n },\n body,\n })\n\n if (!response.ok || response.status >= 400) {\n throw new Error(`${response.status} ${response.statusText}`)\n }\n\n onSuccess()\n } catch (error) {\n onError(error as Error)\n }\n }\n\n convert(spans: ReadableSpan[]) {\n return {\n resourceSpans: [\n {\n resource: {\n attributes: this.convertAttributes(\n spans[0]?.resource?.attributes || {},\n ),\n },\n scopeSpans: [\n {\n spans: spans.map((span) => ({\n traceId: span.spanContext().traceId,\n spanId: span.spanContext().spanId,\n parentSpanId: span.parentSpanId,\n name: span.name,\n kind: span.kind,\n startTimeUnixNano: hrTimeToNanoseconds(\n span.startTime,\n ).toString(),\n endTimeUnixNano: span.endTime\n ? hrTimeToNanoseconds(span.endTime).toString()\n : undefined,\n attributes: this.convertAttributes(span.attributes),\n status: span.status && {\n code: span.status.code,\n message: span.status.message,\n },\n events: span.events?.map((event) => ({\n timeUnixNano: hrTimeToNanoseconds(event.time).toString(),\n name: event.name,\n attributes: this.convertAttributes(event.attributes),\n })),\n links: span.links?.map((link) => ({\n traceId: link.context.traceId,\n spanId: link.context.spanId,\n attributes: this.convertAttributes(link.attributes),\n })),\n })),\n },\n ],\n },\n ],\n }\n }\n\n getDefaultUrl(config: any): string {\n return config.endpoint || this.__defaultUrl\n }\n\n private get __defaultUrl(): string {\n return `${PROTOCOL}://${DOMAIN}/v1/traces`\n }\n\n private convertAttributes(attributes: Record<string, unknown> = {}): Array<{\n key: string\n value: { stringValue?: string; intValue?: number; boolValue?: boolean }\n }> {\n return Object.entries(attributes).map(([key, value]) => ({\n key,\n value: this.convertAttributeValue(value),\n }))\n }\n\n private convertAttributeValue(value: unknown): {\n stringValue?: string\n intValue?: number\n boolValue?: boolean\n } {\n if (typeof value === 'string') return { stringValue: value }\n if (typeof value === 'number') return { intValue: value }\n if (typeof value === 'boolean') return { boolValue: value }\n return { stringValue: String(value) }\n }\n}\n","/**\n * Below are the semantic conventions for the Vercel AI SDK.\n * @see https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#collected-data\n */\nconst AI_PREFIX = 'ai' as const\n\nconst AIPrefixes = {\n settings: 'settings',\n model: 'model',\n usage: 'usage',\n telemetry: 'telemetry',\n prompt: 'prompt',\n toolCall: 'toolCall',\n response: 'response',\n} as const\n\nconst AIUsagePostfixes = {\n completionTokens: 'completionTokens',\n promptTokens: 'promptTokens',\n} as const\n\nconst AIResultPostfixes = {\n text: 'text',\n toolCalls: 'toolCalls',\n object: 'object',\n} as const\n\nconst AIPromptPostfixes = {\n messages: 'messages',\n} as const\n\nconst AIToolCallPostfixes = {\n id: 'id',\n name: 'name',\n args: 'args',\n result: 'result',\n} as const\n\nconst SETTINGS = `${AI_PREFIX}.${AIPrefixes.settings}` as const\n\nconst MODEL_ID = `${AI_PREFIX}.${AIPrefixes.model}.id` as const\n\nconst METADATA = `${AI_PREFIX}.${AIPrefixes.telemetry}.metadata` as const\n\nconst TOKEN_COUNT_COMPLETION =\n `${AI_PREFIX}.${AIPrefixes.usage}.${AIUsagePostfixes.completionTokens}` as const\n\nconst TOKEN_COUNT_PROMPT =\n `${AI_PREFIX}.${AIPrefixes.usage}.${AIUsagePostfixes.promptTokens}` as const\n\nconst RESPONSE_TEXT =\n `${AI_PREFIX}.${AIPrefixes.response}.${AIResultPostfixes.text}` as const\n\nconst RESPONSE_TOOL_CALLS =\n `${AI_PREFIX}.${AIPrefixes.response}.${AIResultPostfixes.toolCalls}` as const\n\nconst RESULT_OBJECT =\n `${AI_PREFIX}.${AIPrefixes.response}.${AIResultPostfixes.object}` as const\n\nconst PROMPT = `${AI_PREFIX}.${AIPrefixes.prompt}` as const\n\nconst PROMPT_MESSAGES = `${PROMPT}.${AIPromptPostfixes.messages}` as const\n\nconst EMBEDDING_TEXT = `${AI_PREFIX}.value` as const\nconst EMBEDDING_VECTOR = `${AI_PREFIX}.embedding` as const\n\nconst EMBEDDING_TEXTS = `${AI_PREFIX}.values` as const\nconst EMBEDDING_VECTORS = `${AI_PREFIX}.embeddings` as const\n\nconst TOOL_CALL_ID =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.id}` as const\nconst TOOL_CALL_NAME =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.name}` as const\nconst TOOL_CALL_ARGS =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.args}` as const\nconst TOOL_CALL_RESULT =\n `${AI_PREFIX}.${AIPrefixes.toolCall}.${AIToolCallPostfixes.result}` as const\n\n/**\n * The semantic conventions used by the Vercel AI SDK.\n * @see https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#collected-data\n */\nexport const AISemanticConventions = {\n MODEL_ID,\n METADATA,\n SETTINGS,\n TOKEN_COUNT_COMPLETION,\n TOKEN_COUNT_PROMPT,\n RESPONSE_TEXT,\n RESPONSE_TOOL_CALLS,\n RESULT_OBJECT,\n PROMPT,\n PROMPT_MESSAGES,\n EMBEDDING_TEXT,\n EMBEDDING_VECTOR,\n EMBEDDING_TEXTS,\n EMBEDDING_VECTORS,\n TOOL_CALL_ID,\n TOOL_CALL_NAME,\n TOOL_CALL_ARGS,\n TOOL_CALL_RESULT,\n} as const\n\nexport const AISemanticConventionsList = Object.freeze(\n Object.values(AISemanticConventions),\n)\n\nexport type AISemanticConvention =\n (typeof AISemanticConventions)[keyof typeof AISemanticConventions]\n","import {\n ReadableSpan,\n SimpleSpanProcessor,\n SpanProcessor,\n BatchSpanProcessor,\n} from '@opentelemetry/sdk-trace-base'\nimport type { ToolCallPart } from 'ai'\n\nimport { AISemanticConventions } from './conventions'\n\nexport class VercelSpanProcessor\n extends SimpleSpanProcessor\n implements SpanProcessor\n{\n onEnd(span: ReadableSpan): void {\n if (!shouldProcess(span)) return\n if (shouldConvertToLatitudeFormat(span)) convertToLatitudeFormat(span)\n\n super.onEnd(span)\n }\n}\n\nexport class VercelBatchSpanProcessor\n extends BatchSpanProcessor\n implements SpanProcessor\n{\n onEnd(span: ReadableSpan): void {\n if (!shouldProcess(span)) return\n if (shouldConvertToLatitudeFormat(span)) convertToLatitudeFormat(span)\n\n super.onEnd(span)\n }\n}\n\nfunction shouldProcess(span: ReadableSpan): boolean {\n return (\n Object.keys(span.attributes).some((k) => k.startsWith('latitude.')) ||\n Object.keys(span.attributes).some((k) => k.startsWith('ai.'))\n )\n}\n\nfunction shouldConvertToLatitudeFormat(span: ReadableSpan): boolean {\n return Object.keys(span.attributes).some((k) => k.startsWith('ai.'))\n}\n\nfunction convertToLatitudeFormat(span: ReadableSpan): void {\n try {\n const computedAttrs = computeOpenLLMAttributes(span)\n if (computedAttrs) {\n ;(span as any).attributes = {\n ...span.attributes,\n ...computedAttrs,\n }\n }\n } catch (e) {\n console.log('Latitude telemetry Error: ', e)\n // do nothing\n }\n}\n\nfunction computeOpenLLMAttributes(span: ReadableSpan) {\n const attrs = span.attributes || {}\n const result: Record<string, string | number | boolean> = {}\n\n // Extract model information\n if (attrs[AISemanticConventions.MODEL_ID]) {\n result['gen_ai.request.model'] = String(\n attrs[AISemanticConventions.MODEL_ID],\n )\n result['gen_ai.response.model'] = String(\n attrs[AISemanticConventions.MODEL_ID],\n )\n }\n\n // Extract settings\n try {\n const settings = attrs[AISemanticConventions.SETTINGS]\n ? JSON.parse(String(attrs[AISemanticConventions.SETTINGS]))\n : {}\n\n if (settings) {\n // Add max tokens if present\n if (settings.maxTokens) {\n result['gen_ai.request.max_tokens'] = settings.maxTokens\n }\n\n if (!attrs['gen_ai.system'] && settings.provider) {\n result['gen_ai.system'] = String(settings.provider)\n }\n }\n } catch (e) {\n console.error('Error parsing settings', e)\n }\n\n // Set request type to chat as that's what Vercel AI SDK uses\n result['llm.request.type'] = 'chat'\n\n // Extract messages\n try {\n const messages = attrs['ai.prompt.messages']\n ? JSON.parse(String(attrs['ai.prompt.messages']))\n : []\n\n // Process prompt messages\n messages.forEach((msg: any, index: number) => {\n result[`gen_ai.prompt.${index}.role`] = msg.role\n result[`gen_ai.prompt.${index}.content`] =\n typeof msg.content === 'string'\n ? msg.content\n : JSON.stringify(msg.content)\n })\n } catch (e) {\n console.error('Error parsing messages', e)\n\n return undefined\n }\n\n // Extract completion/response\n const responseText = attrs['ai.response.text']\n const responseObject = attrs['ai.response.object']\n const responseToolCalls = attrs['ai.response.toolCalls']\n if (responseText) {\n result[`gen_ai.completion.0.role`] = 'assistant'\n result[`gen_ai.completion.0.content`] = String(responseText)\n } else if (responseToolCalls) {\n try {\n const toolCalls = JSON.parse(String(responseToolCalls))\n if (toolCalls.length > 0) {\n result['gen_ai.completion.0.finish_reason'] = 'tool_calls'\n result[`gen_ai.completion.0.role`] = 'assistant'\n\n toolCalls.forEach((toolCall: ToolCallPart, toolCallIndex: number) => {\n result[`gen_ai.completion.0.tool_calls.${toolCallIndex}.id`] =\n toolCall.toolCallId\n result[`gen_ai.completion.0.tool_calls.${toolCallIndex}.name`] =\n toolCall.toolName\n result[`gen_ai.completion.0.tool_calls.${toolCallIndex}.arguments`] =\n toolCall.args as string\n })\n }\n } catch (e) {\n console.error('Error parsing tool calls', e)\n }\n } else if (responseObject) {\n result['gen_ai.completion.0.role'] = 'assistant'\n result['gen_ai.completion.0.content'] = String(responseObject)\n }\n\n // Extract token usage\n const completionTokens = attrs['ai.usage.completionTokens']\n const promptTokens = attrs['ai.usage.promptTokens']\n\n if (typeof completionTokens === 'number') {\n result['gen_ai.usage.completion_tokens'] = completionTokens\n }\n if (typeof promptTokens === 'number') {\n result['gen_ai.usage.prompt_tokens'] = promptTokens\n }\n if (\n typeof completionTokens === 'number' &&\n typeof promptTokens === 'number'\n ) {\n result['llm.usage.total_tokens'] = completionTokens + promptTokens\n }\n\n return result\n}\n","import { NodeSDK } from '@opentelemetry/sdk-node'\nimport {\n SimpleSpanProcessor,\n BatchSpanProcessor,\n SpanExporter,\n} from '@opentelemetry/sdk-trace-node'\n\nimport { AnthropicInstrumentation } from '@traceloop/instrumentation-anthropic'\nimport { OpenAIInstrumentation } from '@traceloop/instrumentation-openai'\nimport { AzureOpenAIInstrumentation } from '@traceloop/instrumentation-azure'\nimport {\n AIPlatformInstrumentation,\n VertexAIInstrumentation,\n} from '@traceloop/instrumentation-vertexai'\nimport { BedrockInstrumentation } from '@traceloop/instrumentation-bedrock'\nimport { CohereInstrumentation } from '@traceloop/instrumentation-cohere'\n\nimport type * as openai from 'openai'\nimport type * as anthropic from '@anthropic-ai/sdk'\nimport type * as azure from '@azure/openai'\nimport type * as cohere from 'cohere-ai'\nimport type * as bedrock from '@aws-sdk/client-bedrock-runtime'\nimport type * as aiplatform from '@google-cloud/aiplatform'\nimport type * as vertexAI from '@google-cloud/vertexai'\nimport type * as pinecone from '@pinecone-database/pinecone'\nimport type * as ChainsModule from 'langchain/chains'\nimport type * as AgentsModule from 'langchain/agents'\nimport type * as ToolsModule from 'langchain/tools'\nimport type * as RunnableModule from '@langchain/core/runnables'\nimport type * as VectorStoreModule from '@langchain/core/vectorstores'\nimport type * as llamaindex from 'llamaindex'\nimport type * as chromadb from 'chromadb'\nimport type * as qdrant from '@qdrant/js-client-rest'\nimport { Resource } from '@opentelemetry/resources'\nimport { context, trace } from '@opentelemetry/api'\n\ntype IModules = {\n openAI?: typeof openai.OpenAI\n anthropic?: typeof anthropic\n azureOpenAI?: typeof azure\n cohere?: typeof cohere\n bedrock?: typeof bedrock\n google_vertexai?: typeof vertexAI\n google_aiplatform?: typeof aiplatform\n pinecone?: typeof pinecone\n langchain?: {\n chainsModule?: typeof ChainsModule\n agentsModule?: typeof AgentsModule\n toolsModule?: typeof ToolsModule\n runnablesModule?: typeof RunnableModule\n vectorStoreModule?: typeof VectorStoreModule\n }\n llamaIndex?: typeof llamaindex\n chromadb?: typeof chromadb\n qdrant?: typeof qdrant\n}\n\ntype SpanAttributes = {\n name?: string\n metadata?: Record<string, unknown>\n prompt?: {\n uuid: string\n versionUuid?: string\n parameters?: Record<string, unknown>\n }\n distinctId?: string\n}\n\nexport type LatitudeTelemetrySDKConfig = {\n exporter: SpanExporter\n modules?: IModules\n disableBatch?: boolean\n processors?: (typeof SimpleSpanProcessor)[] | (typeof BatchSpanProcessor)[]\n}\n\nexport class LatitudeTelemetrySDK {\n private exporter: SpanExporter\n\n constructor({\n exporter,\n modules = {},\n disableBatch = false,\n processors = [],\n }: LatitudeTelemetrySDKConfig) {\n this.exporter = exporter\n\n this._init(modules, { disableBatch, processors })\n }\n\n private _init(\n modules: IModules,\n options?: {\n disableBatch?: boolean\n processors?:\n | (typeof SimpleSpanProcessor)[]\n | (typeof BatchSpanProcessor)[]\n },\n ) {\n const instrumentations = []\n\n if (modules?.openAI) {\n const openAIInstrumentation = new OpenAIInstrumentation({\n enrichTokens: true,\n })\n // @ts-ignore\n openAIInstrumentation.manuallyInstrument(modules.openAI!)\n instrumentations.push(openAIInstrumentation)\n }\n\n if (modules?.anthropic) {\n const anthropicInstrumentation = new AnthropicInstrumentation()\n anthropicInstrumentation.manuallyInstrument(modules.anthropic!)\n instrumentations.push(new AnthropicInstrumentation())\n }\n\n if (modules?.azureOpenAI) {\n const azureOpenAIInstrumentation = new AzureOpenAIInstrumentation()\n azureOpenAIInstrumentation.manuallyInstrument(modules.azureOpenAI!)\n instrumentations.push(azureOpenAIInstrumentation)\n }\n\n if (modules?.cohere) {\n const cohereInstrumentation = new CohereInstrumentation()\n cohereInstrumentation.manuallyInstrument(modules.cohere!)\n instrumentations.push(cohereInstrumentation)\n }\n\n if (modules?.google_vertexai) {\n const vertexAIInstrumentation = new VertexAIInstrumentation()\n vertexAIInstrumentation.manuallyInstrument(modules.google_vertexai!)\n instrumentations.push(vertexAIInstrumentation)\n }\n\n if (modules?.google_aiplatform) {\n const aiplatformInstrumentation = new AIPlatformInstrumentation()\n aiplatformInstrumentation.manuallyInstrument(modules.google_aiplatform!)\n instrumentations.push(aiplatformInstrumentation)\n }\n\n if (modules?.bedrock) {\n const bedrockInstrumentation = new BedrockInstrumentation()\n bedrockInstrumentation.manuallyInstrument(modules.bedrock!)\n instrumentations.push(bedrockInstrumentation)\n }\n\n // TODO: Enable these once we have manually tested them\n //if (modules?.langchain) {\n // const langchainInstrumentation = new LangChainInstrumentation()\n // langchainInstrumentation.manuallyInstrument(modules.langchain!)\n // instrumentations.push(langchainInstrumentation)\n //}\n //\n //if (modules?.llamaIndex) {\n // const llamaindexInstrumentation = new LlamaIndexInstrumentation()\n // llamaindexInstrumentation.manuallyInstrument(modules.llamaIndex!)\n // instrumentations.push(llamaindexInstrumentation)\n //}\n\n //if (modules?.pinecone) {\n // const pineconeInstrumentation = new PineconeInstrumentation()\n // pineconeInstrumentation.manuallyInstrument(modules.pinecone!)\n // instrumentations.push(pineconeInstrumentation)\n //}\n\n //if (modules?.chromadb) {\n // const chromadbInstrumentation = new ChromaDBInstrumentation()\n // chromadbInstrumentation.manuallyInstrument(modules.chromadb!)\n // instrumentations.push(chromadbInstrumentation)\n //}\n\n //if (modules?.qdrant) {\n // const qdrantInstrumentation = new QdrantInstrumentation()\n // qdrantInstrumentation.manuallyInstrument(modules.qdrant!)\n // instrumentations.push(qdrantInstrumentation)\n //}\n\n if (!instrumentations.length && !options?.processors?.length) {\n console.warn('Latitude: No instrumentations or processors to initialize')\n return\n }\n\n const processors = options?.disableBatch\n ? [\n new SimpleSpanProcessor(this.exporter),\n ...(options?.processors?.map(\n (processor) => new processor(this.exporter),\n ) || []),\n ]\n : [\n new BatchSpanProcessor(this.exporter),\n ...(options?.processors?.map(\n (processor) => new processor(this.exporter),\n ) || []),\n ]\n\n const sdk = new NodeSDK({\n resource: new Resource({\n 'service.name': process.env.npm_package_name,\n }),\n instrumentations,\n traceExporter: this.exporter,\n // @ts-ignore\n spanProcessors: processors,\n })\n\n sdk.start()\n }\n\n span<T>(s: SpanAttributes, fn: (span: any) => T): Promise<T> {\n const c = context.active()\n return context.with(c, () =>\n trace\n .getTracer('latitude')\n .startActiveSpan(s.name ?? 'latitude.span', {}, c, async (span) => {\n try {\n if (s.prompt) {\n try {\n span.setAttribute('latitude.prompt', JSON.stringify(s.prompt))\n } catch (e) {\n console.error(\n 'Latitude: Could not serialize latitude.prompt attribute',\n e,\n )\n }\n }\n\n if (s.distinctId) {\n span.setAttribute('latitude.distinctId', s.distinctId)\n }\n\n if (s.metadata) {\n try {\n span.setAttribute(\n 'latitude.metadata',\n JSON.stringify(s.metadata),\n )\n } catch (e) {\n console.error(\n 'Latitude: Could not serialize latitude.metadata attribute',\n e,\n )\n }\n }\n } catch (error) {\n console.error(error)\n }\n\n const res = fn(span)\n if (res instanceof Promise) {\n return res.then((resolvedRes) => {\n span.end()\n\n return resolvedRes\n })\n }\n\n span.end()\n\n return res\n }),\n )\n }\n}\n"],"names":["SimpleSpanProcessor","BatchSpanProcessor"],"mappings":";;;;;;;;;;;;;;AAOA,MAAM,MAAM,GAEN;IAC4B;AAClC,MAAM,QAAQ,GAA2C,OAAO,CAAS;AAOnE,MAAO,gBACX,SAAQ,gBAA+B,CAAA;AAGvC,IAAA,GAAG;AACK,IAAA,OAAO;AAEf,IAAA,WAAA,CAAY,MAA8B,EAAA;QACxC,KAAK,CAAC,MAAM,CAAC;QAEb,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,YAAY;QAC/C,IAAI,CAAC,OAAO,GAAG;AACb,YAAA,aAAa,EAAE,CAAA,OAAA,EAAU,MAAM,CAAC,MAAM,CAAE,CAAA;SACzC;;AAGH,IAAA,MAAM,MAAM,CACV,KAAqB,EACrB,cAAqC,EAAA;QAErC,MAAM,IAAI,CAAC,IAAI,CACb,KAAK,EACL,MAAM,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,CAAC,EACxD,CAAC,KAAK,KAAI;YACR,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;AAC1D,SAAC,CACF;;AAGH,IAAA,MAAM,QAAQ,GAAA;;;AAId,IAAA,MAAM,UAAU,GAAA;;;AAIhB,IAAA,MAAM,MAAM,GAAA;;;AAIZ,IAAA,MAAM,IAAI,CACR,KAAqB,EACrB,SAAqB,EACrB,OAA+B,EAAA;AAE/B,QAAA,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE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I,CAAC,CAAC,WAAW,KAAI;oBAC9B,IAAI,CAAC,GAAG,EAAE;AAEV,oBAAA,OAAO,WAAW;AACpB,iBAAC,CAAC;;YAGJ,IAAI,CAAC,GAAG,EAAE;AAEV,YAAA,OAAO,GAAG;SACX,CAAC,CACL;;AAEJ;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latitude-data/telemetry",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "OpenTelemetry exporters for Latitude",
5
5
  "author": "Latitude Data SL <hello@latitude.so>",
6
6
  "license": "LGPL-3.0",
@@ -70,7 +70,7 @@
70
70
  "openai": "^4.74.0",
71
71
  "rollup": "^4.21.1",
72
72
  "rollup-plugin-dts": "^6.1.1",
73
- "vitest": "^2.0.5",
73
+ "vitest": "^2.1.4",
74
74
  "@latitude-data/typescript-config": "^0.0.0",
75
75
  "@latitude-data/eslint-config": "^0.0.0"
76
76
  },
@@ -82,6 +82,8 @@
82
82
  "build": "NODE_ENV=production rollup -c ./rollup.config.mjs",
83
83
  "tc": "tsc --noEmit",
84
84
  "lint": "eslint src",
85
- "prettier": "prettier --write \"**/*.{ts,tsx,md}\""
85
+ "prettier": "prettier --write \"**/*.{ts,tsx,md}\"",
86
+ "test": "vitest run",
87
+ "test:watch": "vitest"
86
88
  }
87
89
  }