From 2671bd1590417db2f7ca90931574254ad739354e Mon Sep 17 00:00:00 2001 From: Nightingalelyy Date: Mon, 17 Aug 2026 00:27:18 +0800 Subject: [PATCH] fix(examples): repair OpenAI Agents, OpenInference, and OpenRouter tracing --- .../anthropic-openinference/_runtime.ts | 63 ++ .../anthropic-openinference/failure.ts | 27 + .../anthropic-openinference/hello_world.ts | 45 +- .../anthropic-openinference/package-lock.json | 747 ++++++++++++++++++ .../anthropic-openinference/package.json | 15 +- .../tracing/openai-agents-sdk/_runtime.ts | 4 +- .../tracing/openrouter/01_chat_completion.ts | 3 + .../tracing/openrouter/02_tool_calling.ts | 5 +- .../tracing/openrouter/04_embeddings.ts | 5 +- .../tracing/openrouter/package-lock.json | 39 +- typescript/tracing/openrouter/package.json | 7 +- 11 files changed, 918 insertions(+), 42 deletions(-) create mode 100644 typescript/tracing/anthropic-openinference/_runtime.ts create mode 100644 typescript/tracing/anthropic-openinference/failure.ts create mode 100644 typescript/tracing/anthropic-openinference/package-lock.json diff --git a/typescript/tracing/anthropic-openinference/_runtime.ts b/typescript/tracing/anthropic-openinference/_runtime.ts new file mode 100644 index 0000000..07d29ff --- /dev/null +++ b/typescript/tracing/anthropic-openinference/_runtime.ts @@ -0,0 +1,63 @@ +import dotenv from "dotenv"; +import Anthropic from "@anthropic-ai/sdk"; +import { AnthropicInstrumentation } from "@arizeai/openinference-instrumentation-anthropic"; +import { Respan } from "@respan/respan"; +import { OpenInferenceInstrumentor } from "@respan/instrumentation-openinference"; +import { fileURLToPath } from "node:url"; + +dotenv.config({ + path: fileURLToPath(new URL("../../../.env", import.meta.url)), + quiet: true, +}); + +export const RUN_ID = + process.env.RESPAN_EXAMPLE_RUN_ID || `openinference-anthropic-${Date.now()}`; + +function required(name: string): string { + const value = process.env[name]?.trim(); + if (!value) throw new Error(`Set ${name} in the repository-root .env file.`); + return value; +} + +export function createRuntime(): { respan: Respan } { + return { + respan: new Respan({ + apiKey: required("RESPAN_API_KEY"), + baseURL: process.env.RESPAN_BASE_URL, + instrumentations: [ + new OpenInferenceInstrumentor(AnthropicInstrumentation, Anthropic), + ], + silenceInitializationMessage: true, + }), + }; +} + +export function createAnthropicClient(): Anthropic { + const gatewayBase = ( + process.env.RESPAN_GATEWAY_BASE_URL?.trim() || required("RESPAN_BASE_URL") + ).replace(/\/$/, ""); + return new Anthropic({ + apiKey: process.env.RESPAN_GATEWAY_API_KEY?.trim() || required("RESPAN_API_KEY"), + baseURL: `${gatewayBase}/anthropic`, + }); +} + +export async function runWithOpenInferenceWorkflow( + respan: Respan, + workflowName: string, + fn: () => Promise, +): Promise { + await respan.initialize(); + return await respan.propagateAttributes( + { + custom_identifier: RUN_ID, + trace_group_identifier: workflowName, + metadata: { + example: "typescript-anthropic-openinference", + run_id: RUN_ID, + workflow_name: workflowName, + }, + }, + async () => await respan.withWorkflow({ name: workflowName }, fn), + ); +} diff --git a/typescript/tracing/anthropic-openinference/failure.ts b/typescript/tracing/anthropic-openinference/failure.ts new file mode 100644 index 0000000..82db56e --- /dev/null +++ b/typescript/tracing/anthropic-openinference/failure.ts @@ -0,0 +1,27 @@ +import { createAnthropicClient, createRuntime, runWithOpenInferenceWorkflow } from "./_runtime.js"; + +const workflowName = "openinference_anthropic_failure"; +const { respan } = createRuntime(); +let rejected = false; + +try { + await runWithOpenInferenceWorkflow(respan, workflowName, async () => { + await createAnthropicClient().messages.create({ + model: process.env.RESPAN_ANTHROPIC_INVALID_MODEL || "respan-intentional-invalid-model", + max_tokens: 20, + messages: [ + { role: "user", content: "Exercise the expected Anthropic failure path." }, + ], + }); + }); +} catch (error) { + rejected = true; + const message = error instanceof Error ? error.message : String(error); + console.log(JSON.stringify({ workflowName, expectedFailure: message }, null, 2)); +} finally { + await respan.shutdown(); +} + +if (!rejected) { + throw new Error("Expected the unsupported Anthropic model request to fail."); +} diff --git a/typescript/tracing/anthropic-openinference/hello_world.ts b/typescript/tracing/anthropic-openinference/hello_world.ts index 0c6bb5f..0a8113e 100644 --- a/typescript/tracing/anthropic-openinference/hello_world.ts +++ b/typescript/tracing/anthropic-openinference/hello_world.ts @@ -1,31 +1,26 @@ /** Anthropic SDK — Chat completion with Respan tracing via OpenInference. */ -import "dotenv/config"; -import Anthropic from "@anthropic-ai/sdk"; -import { AnthropicInstrumentation } from "@arizeai/openinference-instrumentation-anthropic"; -import { Respan } from "@respan/respan"; -import { OpenInferenceInstrumentor } from "@respan/instrumentation-openinference"; +import { createAnthropicClient, createRuntime, runWithOpenInferenceWorkflow } from "./_runtime.js"; -const respan = new Respan({ - apiKey: process.env.RESPAN_API_KEY, - baseURL: process.env.RESPAN_BASE_URL, - instrumentations: [ - new OpenInferenceInstrumentor(AnthropicInstrumentation, Anthropic), - ], -}); -await respan.initialize(); +const workflowName = "openinference_anthropic_supported"; +const { respan } = createRuntime(); -const client = new Anthropic(); +try { + const output = await runWithOpenInferenceWorkflow(respan, workflowName, async () => { + const message = await createAnthropicClient().messages.create({ + model: process.env.RESPAN_ANTHROPIC_MODEL || "claude-sonnet-4-5-20250929", + max_tokens: 100, + messages: [ + { role: "user", content: "Write a haiku about recursion in programming." }, + ], + }); -const message = await client.messages.create({ - model: "claude-sonnet-4-20250514", - max_tokens: 100, - messages: [ - { role: "user", content: "Write a haiku about recursion in programming." }, - ], -}); - -const text = message.content[0]; -if (text.type === "text") { - console.log(text.text); + return message.content + .map((block) => (block.type === "text" ? block.text : "")) + .filter(Boolean) + .join("\n"); + }); + console.log(JSON.stringify({ workflowName, output }, null, 2)); +} finally { + await respan.shutdown(); } diff --git a/typescript/tracing/anthropic-openinference/package-lock.json b/typescript/tracing/anthropic-openinference/package-lock.json new file mode 100644 index 0000000..9791fa0 --- /dev/null +++ b/typescript/tracing/anthropic-openinference/package-lock.json @@ -0,0 +1,747 @@ +{ + "name": "respan-anthropic-openinference-examples", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "respan-anthropic-openinference-examples", + "dependencies": { + "@anthropic-ai/sdk": "^0.80.0", + "@arizeai/openinference-instrumentation-anthropic": "^0.1.7", + "@opentelemetry/api": "^1.9.0", + "@opentelemetry/sdk-trace-base": "^2.10.0", + "@respan/instrumentation-openinference": "file:../../../../respan/javascript-sdks/instrumentations/respan-instrumentation-openinference", + "@respan/respan": "file:../../../../respan/javascript-sdks/respan", + "@respan/respan-sdk": "file:../../../../respan/javascript-sdks/respan-sdk", + "@respan/tracing": "file:../../../../respan/javascript-sdks/respan-tracing", + "dotenv": "^16.0.0" + }, + "devDependencies": { + "@types/node": "^22.0.0", + "tsx": "^4.0.0", + "typescript": "^5.7.0" + } + }, + "../../../../respan/javascript-sdks/instrumentations/respan-instrumentation-openinference": { + "name": "@respan/instrumentation-openinference", + "version": "1.1.3", + "license": "Apache-2.0", + "dependencies": { + "@arizeai/openinference-semantic-conventions": "^2.1.7", + "@opentelemetry/api": "^1.9.0", + "@opentelemetry/sdk-trace-base": "^2.10.0", + "@opentelemetry/semantic-conventions": "^1.43.0", + "@respan/respan-sdk": "^1.0.0" + }, + "devDependencies": { + "@types/node": "^22.15.29", + "typescript": "^5.7.3" + } + }, + "../../../../respan/javascript-sdks/respan": { + "name": "@respan/respan", + "version": "2.1.0", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/api": "^1.9.0", + "@respan/respan-sdk": "^1.0.0", + "@respan/tracing": "^1.0.0" + }, + "devDependencies": { + "@types/node": "^24.2.1", + "typescript": "^5.7.3" + }, + "optionalDependencies": { + "@respan/instrumentation-anthropic": "^1.0.0", + "@respan/instrumentation-aws-bedrock": "^1.0.0", + "@respan/instrumentation-azure-openai": "^1.0.0", + "@respan/instrumentation-cohere": "^0.1.0", + "@respan/instrumentation-openai": "^1.0.0", + "@respan/instrumentation-openrouter": "^0.1.0", + "@respan/instrumentation-together-ai": "^0.1.0", + "@respan/instrumentation-vertexai": "^0.1.0", + "@respan/instrumentation-writer": "^0.1.0" + } + }, + "../../../../respan/javascript-sdks/respan-sdk": { + "name": "@respan/respan-sdk", + "version": "1.3.2", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/api": "^1.9.0", + "@opentelemetry/core": "^2.10.0", + "@opentelemetry/sdk-trace-base": "^2.10.0", + "typescript": "^5.8.3", + "zod": "^4.1.12" + }, + "devDependencies": { + "@types/node": "^22.15.29" + } + }, + "../../../../respan/javascript-sdks/respan-sdk/node_modules/zod": { + "version": "4.3.6", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, + "../../../../respan/javascript-sdks/respan-tracing": { + "name": "@respan/tracing", + "version": "1.1.6", + "license": "Apache-2.0", + "os": [ + "darwin", + "linux", + "win32" + ], + "dependencies": { + "@opentelemetry/api": "^1.9.0", + "@opentelemetry/core": "^2.10.0", + "@opentelemetry/exporter-trace-otlp-http": "^0.221.0", + "@opentelemetry/resources": "^2.10.0", + "@opentelemetry/sdk-node": "^0.221.0", + "@opentelemetry/sdk-trace-base": "^2.10.0", + "@opentelemetry/sdk-trace-node": "^2.10.0", + "@opentelemetry/semantic-conventions": "^1.43.0", + "@respan/respan-sdk": "^1.0.0", + "@traceloop/ai-semantic-conventions": "^0.13.0" + }, + "devDependencies": { + "@ai-sdk/openai": "^4.0.30", + "@anthropic-ai/sdk": "0.41.0", + "@vercel/otel": "^2.1.3", + "ai": "^7.0.65", + "dotenv": "^16.4.7", + "openai": "^4.80.1", + "ts-node": "^10.9.2", + "tsx": "^4.19.2", + "typescript": "^5.7.3", + "zod": "^3.24.2" + }, + "optionalDependencies": { + "@traceloop/instrumentation-anthropic": "^0.22.2", + "@traceloop/instrumentation-azure": "^0.13.0", + "@traceloop/instrumentation-bedrock": "^0.13.0", + "@traceloop/instrumentation-chromadb": "^0.13.0", + "@traceloop/instrumentation-cohere": "^0.13.0", + "@traceloop/instrumentation-langchain": "^0.13.0", + "@traceloop/instrumentation-llamaindex": "^0.13.0", + "@traceloop/instrumentation-openai": "^0.14.4", + "@traceloop/instrumentation-pinecone": "^0.13.0", + "@traceloop/instrumentation-qdrant": "^0.13.0", + "@traceloop/instrumentation-together": "^0.13.0", + "@traceloop/instrumentation-vertexai": "^0.13.0" + } + }, + "../../../../respan/javascript-sdks/respan-tracing/node_modules/@ai-sdk/openai": { + "version": "1.3.24", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "1.1.3", + "@ai-sdk/provider-utils": "2.2.8" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "zod": "^3.0.0" + } + }, + "../../../../respan/javascript-sdks/respan-tracing/node_modules/@ai-sdk/provider-utils": { + "version": "2.2.8", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "1.1.3", + "nanoid": "^3.3.8", + "secure-json-parse": "^2.7.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "zod": "^3.23.8" + } + }, + "../../../../respan/javascript-sdks/respan-tracing/node_modules/@ai-sdk/react": { + "version": "1.2.12", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider-utils": "2.2.8", + "@ai-sdk/ui-utils": "1.2.11", + "swr": "^2.2.5", + "throttleit": "2.1.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "react": "^18 || ^19 || ^19.0.0-rc", + "zod": "^3.23.8" + }, + "peerDependenciesMeta": { + "zod": { + "optional": true + } + } + }, + "../../../../respan/javascript-sdks/respan-tracing/node_modules/@ai-sdk/ui-utils": { + "version": "1.2.11", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "1.1.3", + "@ai-sdk/provider-utils": "2.2.8", + "zod-to-json-schema": "^3.24.1" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "zod": "^3.23.8" + } + }, + "../../../../respan/javascript-sdks/respan-tracing/node_modules/@anthropic-ai/sdk": { + "version": "0.41.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "^18.11.18", + "@types/node-fetch": "^2.6.4", + "abort-controller": "^3.0.0", + "agentkeepalive": "^4.2.1", + "form-data-encoder": "1.7.2", + "formdata-node": "^4.3.2", + "node-fetch": "^2.6.7" + } + }, + "../../../../respan/javascript-sdks/respan-tracing/node_modules/@types/node": { + "version": "18.19.130", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "../../../../respan/javascript-sdks/respan-tracing/node_modules/ai": { + "version": "4.3.19", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "1.1.3", + "@ai-sdk/provider-utils": "2.2.8", + "@ai-sdk/react": "1.2.12", + "@ai-sdk/ui-utils": "1.2.11", + "@opentelemetry/api": "1.9.0", + "jsondiffpatch": "0.6.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "react": "^18 || ^19 || ^19.0.0-rc", + "zod": "^3.23.8" + }, + "peerDependenciesMeta": { + "react": { + "optional": true + } + } + }, + "../../../../respan/javascript-sdks/respan-tracing/node_modules/openai": { + "version": "4.104.0", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@types/node": "^18.11.18", + "@types/node-fetch": "^2.6.4", + "abort-controller": "^3.0.0", + "agentkeepalive": "^4.2.1", + "form-data-encoder": "1.7.2", + "formdata-node": "^4.3.2", + "node-fetch": "^2.6.7" + }, + "bin": { + "openai": "bin/cli" + }, + "peerDependencies": { + "ws": "^8.18.0", + "zod": "^3.23.8" + }, + "peerDependenciesMeta": { + "ws": { + "optional": true + }, + "zod": { + "optional": true + } + } + }, + "../../../../respan/javascript-sdks/respan-tracing/node_modules/undici-types": { + "version": "5.26.5", + "dev": true, + "license": "MIT" + }, + "../../../../respan/javascript-sdks/respan-tracing/node_modules/zod": { + "version": "3.25.76", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, + "../../../../respan/javascript-sdks/respan-tracing/node_modules/zod-to-json-schema": { + "version": "3.25.2", + "dev": true, + "license": "ISC", + "peerDependencies": { + "zod": "^3.25.28 || ^4" + } + }, + "../../../../respan/javascript-sdks/respan/node_modules/@types/node": { + "version": "24.12.2", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~7.16.0" + } + }, + "../../../../respan/javascript-sdks/respan/node_modules/undici-types": { + "version": "7.16.0", + "dev": true, + "license": "MIT" + }, + "node_modules/@anthropic-ai/sdk": { + "version": "0.80.0", + "license": "MIT", + "dependencies": { + "json-schema-to-ts": "^3.1.1" + }, + "bin": { + "anthropic-ai-sdk": "bin/cli" + }, + "peerDependencies": { + "zod": "^3.25.0 || ^4.0.0" + }, + "peerDependenciesMeta": { + "zod": { + "optional": true + } + } + }, + "node_modules/@arizeai/openinference-core": { + "version": "2.5.1", + "license": "Apache-2.0", + "dependencies": { + "@arizeai/openinference-semantic-conventions": "2.7.0", + "@opentelemetry/api": "^1.9.0", + "@opentelemetry/core": "^2.8.0" + } + }, + "node_modules/@arizeai/openinference-instrumentation-anthropic": { + "version": "0.1.20", + "license": "Apache-2.0", + "dependencies": { + "@arizeai/openinference-core": "2.5.1", + "@arizeai/openinference-semantic-conventions": "2.7.0", + "@opentelemetry/api": "^1.9.0", + "@opentelemetry/core": "^2.8.0", + "@opentelemetry/instrumentation": "^0.46.0" + } + }, + "node_modules/@arizeai/openinference-semantic-conventions": { + "version": "2.7.0", + "license": "Apache-2.0" + }, + "node_modules/@babel/runtime": { + "version": "7.29.7", + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.28.2", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@opentelemetry/api": { + "version": "1.9.1", + "license": "Apache-2.0", + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@opentelemetry/core": { + "version": "2.10.0", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/semantic-conventions": "^1.29.0" + }, + "engines": { + "node": "^18.19.0 || >=20.6.0" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.10.0" + } + }, + "node_modules/@opentelemetry/instrumentation": { + "version": "0.46.0", + "license": "Apache-2.0", + "dependencies": { + "@types/shimmer": "^1.0.2", + "import-in-the-middle": "1.7.1", + "require-in-the-middle": "^7.1.1", + "semver": "^7.5.2", + "shimmer": "^1.2.1" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.3.0" + } + }, + "node_modules/@opentelemetry/resources": { + "version": "2.10.0", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/core": "2.10.0", + "@opentelemetry/semantic-conventions": "^1.29.0" + }, + "engines": { + "node": "^18.19.0 || >=20.6.0" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.3.0 <1.10.0" + } + }, + "node_modules/@opentelemetry/sdk-trace": { + "version": "2.10.0", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/core": "2.10.0", + "@opentelemetry/resources": "2.10.0", + "@opentelemetry/semantic-conventions": "^1.29.0" + }, + "engines": { + "node": "^18.19.0 || >=20.6.0" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.3.0 <1.10.0" + } + }, + "node_modules/@opentelemetry/sdk-trace-base": { + "version": "2.10.0", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/core": "2.10.0", + "@opentelemetry/resources": "2.10.0", + "@opentelemetry/sdk-trace": "2.10.0", + "@opentelemetry/semantic-conventions": "^1.29.0" + }, + "engines": { + "node": "^18.19.0 || >=20.6.0" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.3.0 <1.10.0" + } + }, + "node_modules/@opentelemetry/semantic-conventions": { + "version": "1.43.0", + "license": "Apache-2.0", + "engines": { + "node": ">=14" + } + }, + "node_modules/@respan/instrumentation-openinference": { + "resolved": "../../../../respan/javascript-sdks/instrumentations/respan-instrumentation-openinference", + "link": true + }, + "node_modules/@respan/respan": { + "resolved": "../../../../respan/javascript-sdks/respan", + "link": true + }, + "node_modules/@respan/respan-sdk": { + "resolved": "../../../../respan/javascript-sdks/respan-sdk", + "link": true + }, + "node_modules/@respan/tracing": { + "resolved": "../../../../respan/javascript-sdks/respan-tracing", + "link": true + }, + "node_modules/@types/node": { + "version": "22.20.1", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, + "node_modules/@types/shimmer": { + "version": "1.2.0", + "license": "MIT" + }, + "node_modules/acorn": { + "version": "8.18.0", + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-import-assertions": { + "version": "1.9.0", + "license": "MIT", + "peerDependencies": { + "acorn": "^8" + } + }, + "node_modules/cjs-module-lexer": { + "version": "1.4.3", + "license": "MIT" + }, + "node_modules/debug": { + "version": "4.4.3", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/dotenv": { + "version": "16.6.1", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/esbuild": { + "version": "0.28.2", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.28.2", + "@esbuild/android-arm": "0.28.2", + "@esbuild/android-arm64": "0.28.2", + "@esbuild/android-x64": "0.28.2", + "@esbuild/darwin-arm64": "0.28.2", + "@esbuild/darwin-x64": "0.28.2", + "@esbuild/freebsd-arm64": "0.28.2", + "@esbuild/freebsd-x64": "0.28.2", + "@esbuild/linux-arm": "0.28.2", + "@esbuild/linux-arm64": "0.28.2", + "@esbuild/linux-ia32": "0.28.2", + "@esbuild/linux-loong64": "0.28.2", + "@esbuild/linux-mips64el": "0.28.2", + "@esbuild/linux-ppc64": "0.28.2", + "@esbuild/linux-riscv64": "0.28.2", + "@esbuild/linux-s390x": "0.28.2", + "@esbuild/linux-x64": "0.28.2", + "@esbuild/netbsd-arm64": "0.28.2", + "@esbuild/netbsd-x64": "0.28.2", + "@esbuild/openbsd-arm64": "0.28.2", + "@esbuild/openbsd-x64": "0.28.2", + "@esbuild/openharmony-arm64": "0.28.2", + "@esbuild/sunos-x64": "0.28.2", + "@esbuild/win32-arm64": "0.28.2", + "@esbuild/win32-ia32": "0.28.2", + "@esbuild/win32-x64": "0.28.2" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.4", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/import-in-the-middle": { + "version": "1.7.1", + "license": "Apache-2.0", + "dependencies": { + "acorn": "^8.8.2", + "acorn-import-assertions": "^1.9.0", + "cjs-module-lexer": "^1.2.2", + "module-details-from-path": "^1.0.3" + } + }, + "node_modules/is-core-module": { + "version": "2.16.2", + "license": "MIT", + "dependencies": { + "hasown": "^2.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/json-schema-to-ts": { + "version": "3.1.1", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.18.3", + "ts-algebra": "^2.0.0" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/module-details-from-path": { + "version": "1.0.4", + "license": "MIT" + }, + "node_modules/ms": { + "version": "2.1.3", + "license": "MIT" + }, + "node_modules/path-parse": { + "version": "1.0.7", + "license": "MIT" + }, + "node_modules/require-in-the-middle": { + "version": "7.5.2", + "license": "MIT", + "dependencies": { + "debug": "^4.3.5", + "module-details-from-path": "^1.0.3", + "resolve": "^1.22.8" + }, + "engines": { + "node": ">=8.6.0" + } + }, + "node_modules/resolve": { + "version": "1.22.12", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "is-core-module": "^2.16.1", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/semver": { + "version": "7.8.5", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/shimmer": { + "version": "1.2.1", + "license": "BSD-2-Clause" + }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/ts-algebra": { + "version": "2.0.0", + "license": "MIT" + }, + "node_modules/tsx": { + "version": "4.23.12", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "~0.28.0" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, + "node_modules/typescript": { + "version": "5.9.3", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "6.21.0", + "dev": true, + "license": "MIT" + } + } +} diff --git a/typescript/tracing/anthropic-openinference/package.json b/typescript/tracing/anthropic-openinference/package.json index 2783c0a..422afaf 100644 --- a/typescript/tracing/anthropic-openinference/package.json +++ b/typescript/tracing/anthropic-openinference/package.json @@ -3,17 +3,20 @@ "type": "module", "private": true, "scripts": { - "hello": "tsx hello_world.ts" + "hello": "tsx hello_world.ts", + "failure": "tsx failure.ts", + "all": "npm run hello && npm run failure", + "typecheck": "tsc --noEmit" }, "dependencies": { "@anthropic-ai/sdk": "^0.80.0", "@arizeai/openinference-instrumentation-anthropic": "^0.1.7", "@opentelemetry/api": "^1.9.0", - "@opentelemetry/sdk-trace-base": "^1.30.1", - "@respan/instrumentation-openinference": "file:../../instrumentations/respan-instrumentation-openinference", - "@respan/respan": "file:../../respan", - "@respan/respan-sdk": "file:../../respan-sdk", - "@respan/tracing": "file:../../respan-tracing", + "@opentelemetry/sdk-trace-base": "^2.10.0", + "@respan/instrumentation-openinference": "file:../../../../respan/javascript-sdks/instrumentations/respan-instrumentation-openinference", + "@respan/respan": "file:../../../../respan/javascript-sdks/respan", + "@respan/respan-sdk": "file:../../../../respan/javascript-sdks/respan-sdk", + "@respan/tracing": "file:../../../../respan/javascript-sdks/respan-tracing", "dotenv": "^16.0.0" }, "devDependencies": { diff --git a/typescript/tracing/openai-agents-sdk/_runtime.ts b/typescript/tracing/openai-agents-sdk/_runtime.ts index cc29168..904e049 100644 --- a/typescript/tracing/openai-agents-sdk/_runtime.ts +++ b/typescript/tracing/openai-agents-sdk/_runtime.ts @@ -55,7 +55,8 @@ export async function createRuntime(appName: string): Promise { process.env.OPENAI_BASE_URL ?? DEFAULT_GATEWAY_BASE_URL; const model = process.env.RESPAN_MODEL ?? "gpt-4o-mini"; - const runId = `openai-agents-ts-${Date.now()}`; + const runId = + process.env.RESPAN_EXAMPLE_RUN_ID?.trim() || `openai-agents-ts-${Date.now()}`; const respan = new Respan({ apiKey: respanApiKey, @@ -98,6 +99,7 @@ export async function withExampleTrace( groupId: runtime.runId, metadata: { run_id: runtime.runId, + custom_identifier: runtime.runId, example: "openai-agents-sdk", }, }, diff --git a/typescript/tracing/openrouter/01_chat_completion.ts b/typescript/tracing/openrouter/01_chat_completion.ts index 8888cc8..c74dccd 100644 --- a/typescript/tracing/openrouter/01_chat_completion.ts +++ b/typescript/tracing/openrouter/01_chat_completion.ts @@ -19,6 +19,9 @@ export async function runChatCompletion(respan: OpenRouterRespan = createRespan( maxTokens: 80, }, }); + if (!("choices" in response)) { + throw new Error("Expected a non-streaming OpenRouter chat response."); + } return response.choices?.[0]?.message?.content; }); logExampleResult(workflowName, { model: CHAT_MODEL, content }); diff --git a/typescript/tracing/openrouter/02_tool_calling.ts b/typescript/tracing/openrouter/02_tool_calling.ts index 2d7151f..b967589 100644 --- a/typescript/tracing/openrouter/02_tool_calling.ts +++ b/typescript/tracing/openrouter/02_tool_calling.ts @@ -37,7 +37,10 @@ export async function runToolCalling(respan: OpenRouterRespan = createRespan()): maxTokens: 120, }, }); - return response.choices?.[0]?.message?.toolCalls ?? response.choices?.[0]?.message?.tool_calls; + if (!("choices" in response)) { + throw new Error("Expected a non-streaming OpenRouter tool-call response."); + } + return response.choices?.[0]?.message?.toolCalls; }); logExampleResult(workflowName, { model: CHAT_MODEL, toolCalls }); return toolCalls; diff --git a/typescript/tracing/openrouter/04_embeddings.ts b/typescript/tracing/openrouter/04_embeddings.ts index 72f7a94..9d4a5ee 100644 --- a/typescript/tracing/openrouter/04_embeddings.ts +++ b/typescript/tracing/openrouter/04_embeddings.ts @@ -13,10 +13,13 @@ export async function runEmbeddings(respan: OpenRouterRespan = createRespan()): model: EMBEDDING_MODEL, input: [ "Respan captures traces for OpenRouter TypeScript applications.", - "Embedding spans should summarize vector output without exporting vectors.", + "Embedding spans preserve vector output for observability.", ], }, }); + if (typeof response === "string") { + throw new Error("Expected a structured OpenRouter embeddings response."); + } return response.data?.length; }); logExampleResult(workflowName, { model: EMBEDDING_MODEL, vectorCount }); diff --git a/typescript/tracing/openrouter/package-lock.json b/typescript/tracing/openrouter/package-lock.json index 2102577..f6ca658 100644 --- a/typescript/tracing/openrouter/package-lock.json +++ b/typescript/tracing/openrouter/package-lock.json @@ -15,7 +15,9 @@ "tsx": "^4.20.3", "typescript": "^5.8.3" }, - "devDependencies": {} + "devDependencies": { + "@types/node": "^22.15.29" + } }, "../../../../respan/javascript-sdks/instrumentations/respan-instrumentation-openrouter": { "name": "@respan/instrumentation-openrouter", @@ -23,14 +25,15 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/api": "^1.9.0", - "@opentelemetry/sdk-trace-base": "^1.30.1", - "@opentelemetry/semantic-conventions": "^1.30.0", - "@respan/respan-sdk": "workspace:*", - "@respan/tracing": "workspace:*", + "@opentelemetry/sdk-trace-base": "^2.10.0", + "@opentelemetry/semantic-conventions": "^1.43.0", + "@respan/respan-sdk": "^1.1.7", + "@respan/tracing": "^1.1.4", "@traceloop/ai-semantic-conventions": "^0.4.0" }, "devDependencies": { "@openrouter/sdk": "^0.13.7", + "@types/node": "^22.15.29", "rimraf": "^6.0.1", "typescript": "^5.8.3" }, @@ -53,7 +56,14 @@ }, "optionalDependencies": { "@respan/instrumentation-anthropic": "^1.0.0", - "@respan/instrumentation-openai": "^1.0.0" + "@respan/instrumentation-aws-bedrock": "^1.0.0", + "@respan/instrumentation-azure-openai": "^1.0.0", + "@respan/instrumentation-cohere": "^0.1.0", + "@respan/instrumentation-openai": "^1.0.0", + "@respan/instrumentation-openrouter": "^0.1.0", + "@respan/instrumentation-together-ai": "^0.1.0", + "@respan/instrumentation-vertexai": "^0.1.0", + "@respan/instrumentation-writer": "^0.1.0" } }, "node_modules/@esbuild/aix-ppc64": { @@ -490,6 +500,16 @@ "resolved": "../../../../respan/javascript-sdks/respan", "link": true }, + "node_modules/@types/node": { + "version": "22.20.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.1.tgz", + "integrity": "sha512-EANqOCF9QFyra+4pfxUcX9STKJpCLjMbObVzljIJomAWSnuSIEAvyzEU53GaajbXJEgdh0iEcPL+DGvpUd4k1Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, "node_modules/dotenv": { "version": "16.6.1", "resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-16.6.1.tgz", @@ -588,6 +608,13 @@ "node": ">=14.17" } }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "dev": true, + "license": "MIT" + }, "node_modules/zod": { "version": "4.4.3", "resolved": "https://registry.npmmirror.com/zod/-/zod-4.4.3.tgz", diff --git a/typescript/tracing/openrouter/package.json b/typescript/tracing/openrouter/package.json index 4c34ebb..9caf753 100644 --- a/typescript/tracing/openrouter/package.json +++ b/typescript/tracing/openrouter/package.json @@ -8,7 +8,8 @@ "tools": "tsx 02_tool_calling.ts", "stream": "tsx 03_streaming.ts", "embeddings": "tsx 04_embeddings.ts", - "examples": "tsx run_all.ts" + "examples": "tsx run_all.ts", + "typecheck": "tsc --noEmit" }, "dependencies": { "@openrouter/sdk": "^0.13.7", @@ -18,5 +19,7 @@ "tsx": "^4.20.3", "typescript": "^5.8.3" }, - "devDependencies": {} + "devDependencies": { + "@types/node": "^22.15.29" + } }