opik 1.8.85 → 1.8.86

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,6 +1,6 @@
1
1
  import { AttributeValue, Tracer } from '@opentelemetry/api';
2
2
  import { NodeSDKConfiguration } from '@opentelemetry/sdk-node';
3
- import { O as OpikClient, S as Span, T as Trace } from '../Client-CEIekgCZ.cjs';
3
+ import { O as OpikClient, S as Span, T as Trace } from '../Client-BMjFLeAt.cjs';
4
4
  import 'stream';
5
5
 
6
6
  type SpanExporter = NodeSDKConfiguration["traceExporter"];
@@ -1,6 +1,6 @@
1
1
  import { AttributeValue, Tracer } from '@opentelemetry/api';
2
2
  import { NodeSDKConfiguration } from '@opentelemetry/sdk-node';
3
- import { O as OpikClient, S as Span, T as Trace } from '../Client-CEIekgCZ.js';
3
+ import { O as OpikClient, S as Span, T as Trace } from '../Client-BMjFLeAt.js';
4
4
  import 'stream';
5
5
 
6
6
  type SpanExporter = NodeSDKConfiguration["traceExporter"];
@@ -1 +1 @@
1
- import {i,a}from'../chunk-54RLVONR.js';import'../chunk-VL2AKASE.js';var E=new i,f=class{constructor({client:e=E,tags:t=[],metadata:n={}}={}){this.traces=new Map;this.spans=new Map;this.getSpanInput=e=>{let t={},{attributes:n}=e;return Object.keys(n).forEach(o=>{if(o==="ai.prompt"||o==="gen_ai.request"){let a=C(n[o]);a&&(t={...t,...a});}if(o.startsWith("ai.prompt.")){let a=o.replace("ai.prompt.","");t[a]=m(n[o]);}if(o.startsWith("gen_ai.request.")){let a=o.replace("gen_ai.request.","");t[a]=m(n[o]);}}),Object.keys(t).length>0||("ai.toolCall.name"in n&&(t.toolName=n["ai.toolCall.name"]),"ai.toolCall.args"in n&&(t.args=n["ai.toolCall.args"])),t};this.getSpanOutput=e=>{let{attributes:t}=e;return t["ai.response.text"]?{text:t["ai.response.text"]}:t["ai.toolCall.result"]?{result:t["ai.toolCall.result"]}:t["ai.response.toolCalls"]?{toolCalls:m(t["ai.response.toolCalls"])}:{}};this.getSpanMetadata=e=>{let{attributes:t}=e,n={};return t["gen_ai.response.model"]&&(n.model=t["gen_ai.response.model"]),t["gen_ai.system"]&&(n.system=t["gen_ai.system"]),n};this.getSpanUsage=e=>{let{attributes:t}=e,n={};return "ai.usage.promptTokens"in t&&(n.prompt_tokens=t["ai.usage.promptTokens"]),"gen_ai.usage.input_tokens"in t&&(n.prompt_tokens=t["gen_ai.usage.input_tokens"]),"ai.usage.completionTokens"in t&&(n.completion_tokens=t["ai.usage.completionTokens"]),"gen_ai.usage.output_tokens"in t&&(n.completion_tokens=t["gen_ai.usage.output_tokens"]),("prompt_tokens"in n||"completion_tokens"in n)&&(n.total_tokens=(n.prompt_tokens||0)+(n.completion_tokens||0)),n};this.processSpan=({otelSpan:e,parentSpan:t,trace:n})=>n.span({name:e.name,startTime:new Date(l(e.startTime)),endTime:new Date(l(e.endTime)),parentSpanId:t==null?void 0:t.data.id,input:this.getSpanInput(e),output:this.getSpanOutput(e),metadata:this.getSpanMetadata(e),usage:this.getSpanUsage(e),type:"llm"});this.shutdown=async()=>{await this.client.flush();};this.forceFlush=async()=>{await this.client.flush();};this.export=async(e,t)=>{let n=e.filter(a=>a.instrumentationScope.name==="ai"),i=e.length-n.length;if(i>0&&a.debug(`Ignored ${i} non-AI SDK spans`),n.length===0){a.debug("No AI SDK spans found"),t({code:0});return}let o=w(n);a.debug("Exporting spans",n),Object.entries(o).forEach(([a,c])=>{var S,h;let[r,...u]=c,p=this.client.trace({startTime:new Date(l(r.startTime)),endTime:new Date(l(r.endTime)),name:(h=(S=r.attributes["ai.telemetry.metadata.traceName"])==null?void 0:S.toString())!=null?h:r.name,input:this.getSpanInput(r),output:this.getSpanOutput(r),metadata:{...this.getSpanMetadata(r),...this.metadata},tags:this.tags,usage:this.getSpanUsage(r)});this.traces.set(a,p),u.forEach(g=>{var b,y;let x=this.spans.get((y=(b=g.parentSpanContext)==null?void 0:b.spanId)!=null?y:""),k=this.processSpan({parentSpan:x,otelSpan:g,trace:p});this.spans.set(g.spanContext().spanId,k);});});try{await this.client.flush(),t({code:0});}catch(a$1){a.error("Error exporting spans",a$1),t({code:1,error:a$1 instanceof Error?a$1:new Error("Unknown error")});}};this.client=e,this.tags=[...t],this.metadata={...n};}static getSettings(e){var n,i,o;let t={...e.metadata};return e.name&&(t.traceName=e.name),{isEnabled:(n=e.isEnabled)!=null?n:true,recordInputs:(i=e.recordInputs)!=null?i:true,recordOutputs:(o=e.recordOutputs)!=null?o:true,functionId:e.functionId,metadata:t}}};function w(s){let e={};return s.forEach(t=>{let n=t.spanContext();e[n.traceId]||(e[n.traceId]=[]),e[n.traceId].push(t);}),Object.entries(e).forEach(([t,n])=>{e[t]=I(n);}),e}function l(s){return s[0]*1e3+s[1]/1e6}function m(s){try{return JSON.parse(s)}catch{return s}}function C(s){if(typeof s=="string")try{let e=JSON.parse(s);if(e!==null&&typeof e=="object"&&!Array.isArray(e))return e}catch{return}}function I(s){var a,c;let e=new Map,t=new Map;for(let r of s){let{spanId:u}=r.spanContext(),p=(c=(a=r.parentSpanContext)==null?void 0:a.spanId)!=null?c:"";e.set(u,r),p&&(t.has(p)||t.set(p,[]),t.get(p).push(r));}let n=s.filter(r=>{var u;return !((u=r.parentSpanContext)!=null&&u.spanId)||!e.has(r.parentSpanContext.spanId)}),i=[],o=[...n];for(;o.length>0;){let r=o.shift();i.push(r);let u=r.spanContext().spanId,p=t.get(u)||[];o.push(...p);}return i}export{f as OpikExporter};
1
+ import {i,a}from'../chunk-K5L6K4RC.js';import'../chunk-VL2AKASE.js';var E=new i,f=class{constructor({client:e=E,tags:t=[],metadata:n={}}={}){this.traces=new Map;this.spans=new Map;this.getSpanInput=e=>{let t={},{attributes:n}=e;return Object.keys(n).forEach(o=>{if(o==="ai.prompt"||o==="gen_ai.request"){let a=C(n[o]);a&&(t={...t,...a});}if(o.startsWith("ai.prompt.")){let a=o.replace("ai.prompt.","");t[a]=m(n[o]);}if(o.startsWith("gen_ai.request.")){let a=o.replace("gen_ai.request.","");t[a]=m(n[o]);}}),Object.keys(t).length>0||("ai.toolCall.name"in n&&(t.toolName=n["ai.toolCall.name"]),"ai.toolCall.args"in n&&(t.args=n["ai.toolCall.args"])),t};this.getSpanOutput=e=>{let{attributes:t}=e;return t["ai.response.text"]?{text:t["ai.response.text"]}:t["ai.toolCall.result"]?{result:t["ai.toolCall.result"]}:t["ai.response.toolCalls"]?{toolCalls:m(t["ai.response.toolCalls"])}:{}};this.getSpanMetadata=e=>{let{attributes:t}=e,n={};return t["gen_ai.response.model"]&&(n.model=t["gen_ai.response.model"]),t["gen_ai.system"]&&(n.system=t["gen_ai.system"]),n};this.getSpanUsage=e=>{let{attributes:t}=e,n={};return "ai.usage.promptTokens"in t&&(n.prompt_tokens=t["ai.usage.promptTokens"]),"gen_ai.usage.input_tokens"in t&&(n.prompt_tokens=t["gen_ai.usage.input_tokens"]),"ai.usage.completionTokens"in t&&(n.completion_tokens=t["ai.usage.completionTokens"]),"gen_ai.usage.output_tokens"in t&&(n.completion_tokens=t["gen_ai.usage.output_tokens"]),("prompt_tokens"in n||"completion_tokens"in n)&&(n.total_tokens=(n.prompt_tokens||0)+(n.completion_tokens||0)),n};this.processSpan=({otelSpan:e,parentSpan:t,trace:n})=>n.span({name:e.name,startTime:new Date(l(e.startTime)),endTime:new Date(l(e.endTime)),parentSpanId:t==null?void 0:t.data.id,input:this.getSpanInput(e),output:this.getSpanOutput(e),metadata:this.getSpanMetadata(e),usage:this.getSpanUsage(e),type:"llm"});this.shutdown=async()=>{await this.client.flush();};this.forceFlush=async()=>{await this.client.flush();};this.export=async(e,t)=>{let n=e.filter(a=>a.instrumentationScope.name==="ai"),i=e.length-n.length;if(i>0&&a.debug(`Ignored ${i} non-AI SDK spans`),n.length===0){a.debug("No AI SDK spans found"),t({code:0});return}let o=w(n);a.debug("Exporting spans",n),Object.entries(o).forEach(([a,c])=>{var S,h;let[r,...u]=c,p=this.client.trace({startTime:new Date(l(r.startTime)),endTime:new Date(l(r.endTime)),name:(h=(S=r.attributes["ai.telemetry.metadata.traceName"])==null?void 0:S.toString())!=null?h:r.name,input:this.getSpanInput(r),output:this.getSpanOutput(r),metadata:{...this.getSpanMetadata(r),...this.metadata},tags:this.tags,usage:this.getSpanUsage(r)});this.traces.set(a,p),u.forEach(g=>{var b,y;let x=this.spans.get((y=(b=g.parentSpanContext)==null?void 0:b.spanId)!=null?y:""),k=this.processSpan({parentSpan:x,otelSpan:g,trace:p});this.spans.set(g.spanContext().spanId,k);});});try{await this.client.flush(),t({code:0});}catch(a$1){a.error("Error exporting spans",a$1),t({code:1,error:a$1 instanceof Error?a$1:new Error("Unknown error")});}};this.client=e,this.tags=[...t],this.metadata={...n};}static getSettings(e){var n,i,o;let t={...e.metadata};return e.name&&(t.traceName=e.name),{isEnabled:(n=e.isEnabled)!=null?n:true,recordInputs:(i=e.recordInputs)!=null?i:true,recordOutputs:(o=e.recordOutputs)!=null?o:true,functionId:e.functionId,metadata:t}}};function w(s){let e={};return s.forEach(t=>{let n=t.spanContext();e[n.traceId]||(e[n.traceId]=[]),e[n.traceId].push(t);}),Object.entries(e).forEach(([t,n])=>{e[t]=I(n);}),e}function l(s){return s[0]*1e3+s[1]/1e6}function m(s){try{return JSON.parse(s)}catch{return s}}function C(s){if(typeof s=="string")try{let e=JSON.parse(s);if(e!==null&&typeof e=="object"&&!Array.isArray(e))return e}catch{return}}function I(s){var a,c;let e=new Map,t=new Map;for(let r of s){let{spanId:u}=r.spanContext(),p=(c=(a=r.parentSpanContext)==null?void 0:a.spanId)!=null?c:"";e.set(u,r),p&&(t.has(p)||t.set(p,[]),t.get(p).push(r));}let n=s.filter(r=>{var u;return !((u=r.parentSpanContext)!=null&&u.spanId)||!e.has(r.parentSpanContext.spanId)}),i=[],o=[...n];for(;o.length>0;){let r=o.shift();i.push(r);let u=r.spanContext().spanId,p=t.get(u)||[];o.push(...p);}return i}export{f as OpikExporter};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opik",
3
3
  "description": "Opik TypeScript and JavaScript SDK",
4
- "version": "1.8.85",
4
+ "version": "1.8.86",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/comet-ml/opik.git",