opik 1.7.13 → 1.7.14

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-B_2JOueU.cjs';
3
+ import { O as OpikClient, S as Span, T as Trace } from '../Client-DH-gNmmg.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-B_2JOueU.js';
3
+ import { O as OpikClient, S as Span, T as Trace } from '../Client-DH-gNmmg.js';
4
4
  import 'stream';
5
5
 
6
6
  type SpanExporter = NodeSDKConfiguration["traceExporter"];
@@ -1 +1 @@
1
- import {f,a}from'../chunk-BFXGGAXO.js';import'../chunk-WOT6VMZA.js';var k=new f,m=class{constructor({client:e=k}={}){this.traces=new Map;this.spans=new Map;this.getSpanInput=e=>{let t={},{attributes:n}=e;return Object.keys(n).forEach(a=>{if(a==="ai.prompt"||a==="gen_ai.request"){let r=w(n[a]);r&&(t={...t,...r});}if(a.startsWith("ai.prompt.")){let r=a.replace("ai.prompt.","");t[r]=l(n[a]);}if(a.startsWith("gen_ai.request.")){let r=a.replace("gen_ai.request.","");t[r]=l(n[a]);}}),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:l(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(c(e.startTime)),endTime:new Date(c(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(r=>r.instrumentationLibrary.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 a$1=E(n);a.debug("Exporting spans",n),Object.entries(a$1).forEach(([r,p])=>{var f,S;let[s,...R]=p,g=this.client.trace({startTime:new Date(c(s.startTime)),endTime:new Date(c(s.endTime)),name:(S=(f=s.attributes["ai.telemetry.metadata.traceName"])==null?void 0:f.toString())!=null?S:s.name,input:this.getSpanInput(s),output:this.getSpanOutput(s),metadata:this.getSpanMetadata(s),usage:this.getSpanUsage(s)});this.traces.set(r,g),R.forEach(d=>{var h;let y=this.spans.get((h=d.parentSpanId)!=null?h:""),I=this.processSpan({parentSpan:y,otelSpan:d,trace:g});this.spans.set(d.spanContext().spanId,I);});});try{await this.client.flush(),t({code:0});}catch(r){a.error("Error exporting spans",r),t({code:1,error:r instanceof Error?r:new Error("Unknown error")});}};this.client=e;}static getSettings(e){var n,i,a;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:(a=e.recordOutputs)!=null?a:true,functionId:e.functionId,metadata:t}}};function E(o){let e={};return o.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]=x(n);}),e}function c(o){return o[0]*1e3+o[1]/1e6}function l(o){try{return JSON.parse(o)}catch{return o}}function w(o){if(typeof o=="string")try{let e=JSON.parse(o);if(e!==null&&typeof e=="object"&&!Array.isArray(e))return e}catch{return}}function x(o){let e=new Map,t=new Map;for(let r of o){let{spanId:p}=r.spanContext();e.set(p,r),r.parentSpanId&&(t.has(r.parentSpanId)||t.set(r.parentSpanId,[]),t.get(r.parentSpanId).push(r));}let n=o.filter(r=>!r.parentSpanId||!e.has(r.parentSpanId)),i=[],a=[...n];for(;a.length>0;){let r=a.shift();i.push(r);let p=r.spanContext().spanId,s=t.get(p)||[];a.push(...s);}return i}export{m as OpikExporter};
1
+ import {f,a}from'../chunk-X47BOIBU.js';import'../chunk-WOT6VMZA.js';var k=new f,m=class{constructor({client:e=k}={}){this.traces=new Map;this.spans=new Map;this.getSpanInput=e=>{let t={},{attributes:n}=e;return Object.keys(n).forEach(a=>{if(a==="ai.prompt"||a==="gen_ai.request"){let r=w(n[a]);r&&(t={...t,...r});}if(a.startsWith("ai.prompt.")){let r=a.replace("ai.prompt.","");t[r]=l(n[a]);}if(a.startsWith("gen_ai.request.")){let r=a.replace("gen_ai.request.","");t[r]=l(n[a]);}}),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:l(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(c(e.startTime)),endTime:new Date(c(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(r=>r.instrumentationLibrary.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 a$1=E(n);a.debug("Exporting spans",n),Object.entries(a$1).forEach(([r,p])=>{var f,S;let[s,...R]=p,g=this.client.trace({startTime:new Date(c(s.startTime)),endTime:new Date(c(s.endTime)),name:(S=(f=s.attributes["ai.telemetry.metadata.traceName"])==null?void 0:f.toString())!=null?S:s.name,input:this.getSpanInput(s),output:this.getSpanOutput(s),metadata:this.getSpanMetadata(s),usage:this.getSpanUsage(s)});this.traces.set(r,g),R.forEach(d=>{var h;let y=this.spans.get((h=d.parentSpanId)!=null?h:""),I=this.processSpan({parentSpan:y,otelSpan:d,trace:g});this.spans.set(d.spanContext().spanId,I);});});try{await this.client.flush(),t({code:0});}catch(r){a.error("Error exporting spans",r),t({code:1,error:r instanceof Error?r:new Error("Unknown error")});}};this.client=e;}static getSettings(e){var n,i,a;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:(a=e.recordOutputs)!=null?a:true,functionId:e.functionId,metadata:t}}};function E(o){let e={};return o.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]=x(n);}),e}function c(o){return o[0]*1e3+o[1]/1e6}function l(o){try{return JSON.parse(o)}catch{return o}}function w(o){if(typeof o=="string")try{let e=JSON.parse(o);if(e!==null&&typeof e=="object"&&!Array.isArray(e))return e}catch{return}}function x(o){let e=new Map,t=new Map;for(let r of o){let{spanId:p}=r.spanContext();e.set(p,r),r.parentSpanId&&(t.has(r.parentSpanId)||t.set(r.parentSpanId,[]),t.get(r.parentSpanId).push(r));}let n=o.filter(r=>!r.parentSpanId||!e.has(r.parentSpanId)),i=[],a=[...n];for(;a.length>0;){let r=a.shift();i.push(r);let p=r.spanContext().spanId,s=t.get(p)||[];a.push(...s);}return i}export{m 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.7.13",
4
+ "version": "1.7.14",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/comet-ml/opik.git",