diff --git a/package-lock.json b/package-lock.json index 016a9fb4..cd7539d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3919,18 +3919,6 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, - "node_modules/@jest/expect-utils": { - "version": "29.7.0", - "resolved": "https://registry.npmjs.org/@jest/expect-utils/-/expect-utils-29.7.0.tgz", - "integrity": "sha512-GlsNBWiFQFCVi9QVSx7f5AgMeLxe9YCCs5PuP2O2LdjDAA8Jh9eX7lA1Jq/xdXw3Wb3hyvlFNfZIfcRetSzYcA==", - "dev": true, - "dependencies": { - "jest-get-type": "^29.6.3" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, "node_modules/@jest/schemas": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", @@ -3943,23 +3931,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/@jest/types": { - "version": "29.6.3", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", - "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", - "dev": true, - "dependencies": { - "@jest/schemas": "^29.6.3", - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^17.0.8", - "chalk": "^4.0.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.5", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", @@ -7517,40 +7488,6 @@ "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", "dev": true }, - "node_modules/@types/expect": { - "version": "24.3.0", - "resolved": "https://registry.npmjs.org/@types/expect/-/expect-24.3.0.tgz", - "integrity": "sha512-aq5Z+YFBz5o2b6Sp1jigx5nsmoZMK5Ceurjwy6PZmRv7dEi1jLtkARfvB1ME+OXJUG+7TZUDcv3WoCr/aor6dQ==", - "deprecated": "This is a stub types definition. expect provides its own type definitions, so you do not need this installed.", - "dev": true, - "dependencies": { - "expect": "*" - } - }, - "node_modules/@types/istanbul-lib-coverage": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz", - "integrity": "sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==", - "dev": true - }, - "node_modules/@types/istanbul-lib-report": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.3.tgz", - "integrity": "sha512-NQn7AHQnk/RSLOxrBbGyJM/aVQ+pjj5HCgasFxc0K/KhoATfQ/47AyUl15I2yBUpihjmas+a+VJBOqecrFH+uA==", - "dev": true, - "dependencies": { - "@types/istanbul-lib-coverage": "*" - } - }, - "node_modules/@types/istanbul-reports": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.4.tgz", - "integrity": "sha512-pk2B1NWalF9toCRu6gjBzR69syFjP4Od8WRAX+0mmf9lAjCRicLOWc+ZrxZHx/0XRjotgkF9t6iaMJ+aXcOdZQ==", - "dev": true, - "dependencies": { - "@types/istanbul-lib-report": "*" - } - }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -7753,12 +7690,6 @@ "resolved": "https://registry.npmjs.org/@types/shimmer/-/shimmer-1.0.5.tgz", "integrity": "sha512-9Hp0ObzwwO57DpLFF0InUjUm/II8GmKAvzbefxQTihCb7KI6yc9yzf0nLc4mVdby5N4DRCgQM2wCup9KTieeww==" }, - "node_modules/@types/stack-utils": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz", - "integrity": "sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==", - "dev": true - }, "node_modules/@types/tough-cookie": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz", @@ -7787,21 +7718,6 @@ "@types/webidl-conversions": "*" } }, - "node_modules/@types/yargs": { - "version": "17.0.32", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", - "integrity": "sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==", - "dev": true, - "dependencies": { - "@types/yargs-parser": "*" - } - }, - "node_modules/@types/yargs-parser": { - "version": "21.0.3", - "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.3.tgz", - "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==", - "dev": true - }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "6.21.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.21.0.tgz", @@ -11197,22 +11113,6 @@ "node": ">=0.10.0" } }, - "node_modules/expect": { - "version": "29.7.0", - "resolved": "https://registry.npmjs.org/expect/-/expect-29.7.0.tgz", - "integrity": "sha512-2Zks0hf1VLFYI1kbh0I5jP3KHHyCHpkfyHBzsSXRFgl/Bg9mWYfMW8oD+PdMPlEwy5HNsR9JutYy6pMeOh61nw==", - "dev": true, - "dependencies": { - "@jest/expect-utils": "^29.7.0", - "jest-get-type": "^29.6.3", - "jest-matcher-utils": "^29.7.0", - "jest-message-util": "^29.7.0", - "jest-util": "^29.7.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, "node_modules/exponential-backoff": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/exponential-backoff/-/exponential-backoff-3.1.1.tgz", @@ -13430,58 +13330,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-matcher-utils": { - "version": "29.7.0", - "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-29.7.0.tgz", - "integrity": "sha512-sBkD+Xi9DtcChsI3L3u0+N0opgPYnCRPtGcQYrgXmR+hmt/fYfWAL0xRXYU8eWOdfuLgBe0YCW3AFtnRLagq/g==", - "dev": true, - "dependencies": { - "chalk": "^4.0.0", - "jest-diff": "^29.7.0", - "jest-get-type": "^29.6.3", - "pretty-format": "^29.7.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-message-util": { - "version": "29.7.0", - "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-29.7.0.tgz", - "integrity": "sha512-GBEV4GRADeP+qtB2+6u61stea8mGcOT4mCtrYISZwfu9/ISHFJ/5zOMXYbpBE9RsS5+Gb63DW4FgmnKJ79Kf6w==", - "dev": true, - "dependencies": { - "@babel/code-frame": "^7.12.13", - "@jest/types": "^29.6.3", - "@types/stack-utils": "^2.0.0", - "chalk": "^4.0.0", - "graceful-fs": "^4.2.9", - "micromatch": "^4.0.4", - "pretty-format": "^29.7.0", - "slash": "^3.0.0", - "stack-utils": "^2.0.3" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-util": { - "version": "29.7.0", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.7.0.tgz", - "integrity": "sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA==", - "dev": true, - "dependencies": { - "@jest/types": "^29.6.3", - "@types/node": "*", - "chalk": "^4.0.0", - "ci-info": "^3.2.0", - "graceful-fs": "^4.2.9", - "picomatch": "^2.2.3" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, "node_modules/jiti": { "version": "1.21.0", "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.0.tgz", @@ -20145,27 +19993,6 @@ "node": "*" } }, - "node_modules/stack-utils": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.6.tgz", - "integrity": "sha512-XlkWvfIm6RmsWtNJx+uqtKLS8eqFbxUg0ZzLXqY0caEy9l7hruX8IpiDnjsLavoBgqCCR71TqWO8MaXYheJ3RQ==", - "dev": true, - "dependencies": { - "escape-string-regexp": "^2.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/stack-utils/node_modules/escape-string-regexp": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", - "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", @@ -21947,7 +21774,6 @@ "@pollyjs/adapter-node-http": "^6.0.6", "@pollyjs/core": "^6.0.6", "@pollyjs/persister-fs": "^6.0.6", - "@types/expect": "^24.3.0", "@types/mocha": "^10.0.6", "llamaindex": "^0.0.40", "ts-mocha": "^10.0.0" @@ -22068,7 +21894,6 @@ "@pollyjs/adapter-node-http": "^6.0.6", "@pollyjs/core": "^6.0.6", "@pollyjs/persister-fs": "^6.0.6", - "@types/expect": "^24.3.0", "@types/mocha": "^10.0.6", "hnswlib-node": "^1.4.2", "langchain": "^0.1.25", @@ -22656,7 +22481,6 @@ "@pollyjs/adapter-node-http": "^6.0.6", "@pollyjs/core": "^6.0.6", "@pollyjs/persister-fs": "^6.0.6", - "@types/expect": "^24.3.0", "@types/mocha": "^10.0.6", "llamaindex": "^0.1.16", "ts-mocha": "^10.0.0" @@ -22887,7 +22711,6 @@ "@pollyjs/adapter-node-http": "^6.0.6", "@pollyjs/core": "^6.0.6", "@pollyjs/persister-fs": "^6.0.6", - "@types/expect": "^24.3.0", "@types/mocha": "^10.0.6", "mocha": "^10.2.0", "openai": "^4.12.4", @@ -23587,15 +23410,15 @@ "dependencies": { "@opentelemetry/exporter-trace-otlp-proto": "^0.49.1", "@opentelemetry/sdk-node": "^0.49.1", - "@traceloop/ai-semantic-conventions": "^0.5.19", - "@traceloop/instrumentation-azure": "^0.5.21", - "@traceloop/instrumentation-bedrock": "^0.5.21", - "@traceloop/instrumentation-cohere": "^0.5.21", - "@traceloop/instrumentation-langchain": "^0.5.21", - "@traceloop/instrumentation-llamaindex": "^0.5.22", - "@traceloop/instrumentation-openai": "^0.5.21", - "@traceloop/instrumentation-pinecone": "^0.5.21", - "@traceloop/instrumentation-vertexai": "^0.5.21", + "@traceloop/ai-semantic-conventions": "*", + "@traceloop/instrumentation-azure": "*", + "@traceloop/instrumentation-bedrock": "*", + "@traceloop/instrumentation-cohere": "*", + "@traceloop/instrumentation-langchain": "*", + "@traceloop/instrumentation-llamaindex": "*", + "@traceloop/instrumentation-openai": "*", + "@traceloop/instrumentation-pinecone": "*", + "@traceloop/instrumentation-vertexai": "*", "@types/nunjucks": "^3.2.5", "cross-fetch": "^4.0.0", "fetch-retry": "^5.0.6", @@ -23609,7 +23432,6 @@ "@pollyjs/core": "^6.0.6", "@pollyjs/persister-fs": "^6.0.6", "@rollup/plugin-typescript": "^11.1.6", - "@types/expect": "^24.3.0", "@types/mocha": "^10.0.6", "@types/node": "^20.9.0", "@types/uuid": "^9.0.7", diff --git a/packages/instrumentation-azure/package.json b/packages/instrumentation-azure/package.json index c64faf1b..b0b312d2 100644 --- a/packages/instrumentation-azure/package.json +++ b/packages/instrumentation-azure/package.json @@ -46,7 +46,6 @@ "@pollyjs/adapter-node-http": "^6.0.6", "@pollyjs/core": "^6.0.6", "@pollyjs/persister-fs": "^6.0.6", - "@types/expect": "^24.3.0", "@types/mocha": "^10.0.6", "llamaindex": "^0.0.40", "ts-mocha": "^10.0.0" diff --git a/packages/instrumentation-azure/src/instrumentation.ts b/packages/instrumentation-azure/src/instrumentation.ts index 7c32cd3c..d505280a 100644 --- a/packages/instrumentation-azure/src/instrumentation.ts +++ b/packages/instrumentation-azure/src/instrumentation.ts @@ -33,7 +33,7 @@ import { SpanAttributes, } from "@traceloop/ai-semantic-conventions"; import { AzureOpenAIInstrumentationConfig } from "./types"; -import { +import type { ChatCompletions, ChatRequestMessage, Completions, diff --git a/packages/instrumentation-bedrock/src/instrumentation.ts b/packages/instrumentation-bedrock/src/instrumentation.ts index 7761e674..5edd4416 100644 --- a/packages/instrumentation-bedrock/src/instrumentation.ts +++ b/packages/instrumentation-bedrock/src/instrumentation.ts @@ -28,7 +28,7 @@ import { safeExecuteInTheMiddle, } from "@opentelemetry/instrumentation"; import { BedrockInstrumentationConfig } from "./types"; -import * as bedrock from "@aws-sdk/client-bedrock-runtime"; +import type * as bedrock from "@aws-sdk/client-bedrock-runtime"; import { CONTEXT_KEY_ALLOW_TRACE_CONTENT, LLMRequestTypeValues, diff --git a/packages/instrumentation-cohere/src/instrumentation.ts b/packages/instrumentation-cohere/src/instrumentation.ts index 95ce664b..d7cfbca6 100644 --- a/packages/instrumentation-cohere/src/instrumentation.ts +++ b/packages/instrumentation-cohere/src/instrumentation.ts @@ -28,13 +28,12 @@ import { safeExecuteInTheMiddle, } from "@opentelemetry/instrumentation"; import { CohereInstrumentationConfig } from "./types"; -import * as cohere from "cohere-ai"; +import type * as cohere from "cohere-ai"; import { CONTEXT_KEY_ALLOW_TRACE_CONTENT, LLMRequestTypeValues, SpanAttributes, } from "@traceloop/ai-semantic-conventions"; -import { Stream } from "cohere-ai/core"; type LLM_COMPLETION_TYPE = "chat" | "completion" | "rerank"; export class CohereInstrumentation extends InstrumentationBase { @@ -70,27 +69,27 @@ export class CohereInstrumentation extends InstrumentationBase { this._wrap( module.CohereClient.prototype, "generate", - this.wrapperMethod("completion"), + this.wrapperMethod("completion", false), ); this._wrap( module.CohereClient.prototype, "generateStream", - this.wrapperMethod("completion"), + this.wrapperMethod("completion", true), ); this._wrap( module.CohereClient.prototype, "chat", - this.wrapperMethod("chat"), + this.wrapperMethod("chat", false), ); this._wrap( module.CohereClient.prototype, "chatStream", - this.wrapperMethod("chat"), + this.wrapperMethod("chat", true), ); this._wrap( module.CohereClient.prototype, "rerank", - this.wrapperMethod("rerank"), + this.wrapperMethod("rerank", false), ); return module; @@ -105,7 +104,7 @@ export class CohereInstrumentation extends InstrumentationBase { this._unwrap(module.CohereClient.prototype, "rerank"); } - private wrapperMethod(type: LLM_COMPLETION_TYPE) { + private wrapperMethod(type: LLM_COMPLETION_TYPE, streaming: boolean) { // eslint-disable-next-line @typescript-eslint/no-this-alias const plugin = this; // eslint-disable-next-line @typescript-eslint/ban-types @@ -128,7 +127,12 @@ export class CohereInstrumentation extends InstrumentationBase { } }, ); - const wrappedPromise = plugin._wrapPromise(type, span, execPromise); + const wrappedPromise = plugin._wrapPromise( + type, + streaming, + span, + execPromise, + ); return context.bind(execContext, wrappedPromise as any); }; }; @@ -136,23 +140,51 @@ export class CohereInstrumentation extends InstrumentationBase { private _wrapPromise( type: LLM_COMPLETION_TYPE, + streaming: boolean, span: Span, promise: Promise, ): Promise { return promise .then(async (result) => { - const awaitedResult = (await result) as - | cohere.Cohere.Generation - | cohere.Cohere.GenerateStreamedResponse - | cohere.Cohere.NonStreamedChatResponse - | cohere.Cohere.StreamedChatResponse - | cohere.Cohere.RerankResponse; - - await this._endSpan({ - type, - span, - result: awaitedResult, - }); + const awaitedResult = await result; + if (type === "completion" && streaming) { + await this._endSpan({ + type, + span, + streaming, + result: + (await awaitedResult) as AsyncIterable, + }); + } else if (type === "completion" && !streaming) { + await this._endSpan({ + type, + span, + streaming, + result: awaitedResult as cohere.Cohere.Generation, + }); + } else if (type === "chat" && streaming) { + await this._endSpan({ + type, + span, + streaming, + result: + (await awaitedResult) as AsyncIterable, + }); + } else if (type === "chat" && !streaming) { + await this._endSpan({ + type, + span, + streaming, + result: awaitedResult as cohere.Cohere.NonStreamedChatResponse, + }); + } else if (type === "rerank" && !streaming) { + await this._endSpan({ + type, + span, + streaming, + result: awaitedResult as cohere.Cohere.RerankResponse, + }); + } return new Promise((resolve) => resolve(result)); }) @@ -240,19 +272,41 @@ export class CohereInstrumentation extends InstrumentationBase { private async _endSpan({ type, span, + streaming, result, - }: { - type: LLM_COMPLETION_TYPE; - span: Span; - result: - | cohere.Cohere.Generation - | cohere.Cohere.GenerateStreamedResponse - | cohere.Cohere.NonStreamedChatResponse - | cohere.Cohere.StreamedChatResponse - | cohere.Cohere.RerankResponse; - }) { + }: + | { + type: "completion"; + span: Span; + streaming: false; + result: cohere.Cohere.Generation; + } + | { + type: "completion"; + span: Span; + streaming: true; + result: AsyncIterable; + } + | { + type: "chat"; + span: Span; + streaming: false; + result: cohere.Cohere.NonStreamedChatResponse; + } + | { + type: "chat"; + span: Span; + streaming: true; + result: AsyncIterable; + } + | { + type: "rerank"; + span: Span; + streaming: false; + result: cohere.Cohere.RerankResponse; + }) { if (type === "completion") { - if (result instanceof Stream) { + if (streaming) { for await (const message of result) { if (message.eventType === "stream-end") { this._setResponseSpanForGenerate(span, message.response); @@ -262,7 +316,7 @@ export class CohereInstrumentation extends InstrumentationBase { this._setResponseSpanForGenerate(span, result); } } else if (type === "chat") { - if (result instanceof Stream) { + if (streaming) { for await (const message of result) { if (message.eventType === "stream-end") { this._setResponseSpanForChat(span, message.response); @@ -404,9 +458,9 @@ export class CohereInstrumentation extends InstrumentationBase { private _setResponseSpanForGenerate( span: Span, - result: cohere.Cohere.Generation, + result: cohere.Cohere.Generation | cohere.Cohere.GenerateStreamEndResponse, ) { - if ("meta" in result) { + if (result && "meta" in result) { if (typeof result.meta?.billedUnits?.inputTokens === "number") { span.setAttribute( SpanAttributes.LLM_USAGE_PROMPT_TOKENS, @@ -433,7 +487,7 @@ export class CohereInstrumentation extends InstrumentationBase { } } - if (this._shouldSendPrompts()) { + if (this._shouldSendPrompts() && result.generations) { span.setAttribute( `${SpanAttributes.LLM_COMPLETIONS}.0.role`, "assistant", @@ -445,6 +499,7 @@ export class CohereInstrumentation extends InstrumentationBase { } if ( + result.generations && "finish_reason" in result.generations[0] && typeof result.generations[0].finish_reason === "string" ) @@ -454,6 +509,7 @@ export class CohereInstrumentation extends InstrumentationBase { ); if ( + result.generations && "finishReason" in result.generations[0] && typeof result.generations[0].finishReason === "string" ) diff --git a/packages/instrumentation-langchain/package.json b/packages/instrumentation-langchain/package.json index 51989dc1..6297de7d 100644 --- a/packages/instrumentation-langchain/package.json +++ b/packages/instrumentation-langchain/package.json @@ -47,7 +47,6 @@ "@pollyjs/adapter-node-http": "^6.0.6", "@pollyjs/core": "^6.0.6", "@pollyjs/persister-fs": "^6.0.6", - "@types/expect": "^24.3.0", "@types/mocha": "^10.0.6", "hnswlib-node": "^1.4.2", "langchain": "^0.1.25", diff --git a/packages/instrumentation-llamaindex/package.json b/packages/instrumentation-llamaindex/package.json index c45b4f79..bc3af6e1 100644 --- a/packages/instrumentation-llamaindex/package.json +++ b/packages/instrumentation-llamaindex/package.json @@ -45,7 +45,6 @@ "@pollyjs/adapter-node-http": "^6.0.6", "@pollyjs/core": "^6.0.6", "@pollyjs/persister-fs": "^6.0.6", - "@types/expect": "^24.3.0", "@types/mocha": "^10.0.6", "llamaindex": "^0.1.16", "ts-mocha": "^10.0.0" diff --git a/packages/instrumentation-llamaindex/src/instrumentation.ts b/packages/instrumentation-llamaindex/src/instrumentation.ts index 00b3cef1..07e3952c 100644 --- a/packages/instrumentation-llamaindex/src/instrumentation.ts +++ b/packages/instrumentation-llamaindex/src/instrumentation.ts @@ -25,7 +25,12 @@ import { LlamaIndexInstrumentationConfig } from "./types"; import { CustomLLMInstrumentation } from "./custom-llm-instrumentation"; import { genericWrapper, shouldSendPrompts } from "./utils"; -import { BaseEmbedding, BaseSynthesizer, LLM, BaseRetriever } from "llamaindex"; +import type { + BaseEmbedding, + BaseSynthesizer, + LLM, + BaseRetriever, +} from "llamaindex"; import { TraceloopSpanKindValues } from "@traceloop/ai-semantic-conventions"; export class LlamaIndexInstrumentation extends InstrumentationBase { @@ -64,10 +69,7 @@ export class LlamaIndexInstrumentation extends InstrumentationBase { } private isEmbedding(embedding: any): embedding is BaseEmbedding { - return ( - embedding instanceof BaseEmbedding && - embedding.getQueryEmbedding !== undefined - ); + return !!(embedding as BaseEmbedding)?.getQueryEmbedding; } private isSynthesizer(synthesizer: any): synthesizer is BaseSynthesizer { diff --git a/packages/instrumentation-llamaindex/src/utils.ts b/packages/instrumentation-llamaindex/src/utils.ts index efc2c57f..1bd52848 100644 --- a/packages/instrumentation-llamaindex/src/utils.ts +++ b/packages/instrumentation-llamaindex/src/utils.ts @@ -1,5 +1,5 @@ import * as lodash from "lodash"; -import * as llamaindex from "llamaindex"; +import type * as llamaindex from "llamaindex"; import { trace, context, Tracer, SpanStatusCode } from "@opentelemetry/api"; import { LlamaIndexInstrumentationConfig } from "./types"; import { safeExecuteInTheMiddle } from "@opentelemetry/instrumentation"; diff --git a/packages/instrumentation-openai/package.json b/packages/instrumentation-openai/package.json index b6251de3..31ce4a53 100644 --- a/packages/instrumentation-openai/package.json +++ b/packages/instrumentation-openai/package.json @@ -44,7 +44,6 @@ "@pollyjs/adapter-node-http": "^6.0.6", "@pollyjs/core": "^6.0.6", "@pollyjs/persister-fs": "^6.0.6", - "@types/expect": "^24.3.0", "@types/mocha": "^10.0.6", "mocha": "^10.2.0", "openai": "^4.12.4", diff --git a/packages/instrumentation-openai/src/instrumentation.ts b/packages/instrumentation-openai/src/instrumentation.ts index 33fbe883..9f409786 100644 --- a/packages/instrumentation-openai/src/instrumentation.ts +++ b/packages/instrumentation-openai/src/instrumentation.ts @@ -33,7 +33,7 @@ import { SpanAttributes, } from "@traceloop/ai-semantic-conventions"; import { OpenAIInstrumentationConfig } from "./types"; -import { +import type { ChatCompletion, ChatCompletionChunk, ChatCompletionCreateParamsNonStreaming, @@ -42,7 +42,7 @@ import { CompletionCreateParamsNonStreaming, CompletionCreateParamsStreaming, } from "openai/resources"; -import { Stream } from "openai/streaming"; +import type { Stream } from "openai/streaming"; export class OpenAIInstrumentation extends InstrumentationBase { protected override _config!: OpenAIInstrumentationConfig; diff --git a/packages/instrumentation-pinecone/src/instrumentation.ts b/packages/instrumentation-pinecone/src/instrumentation.ts index 7e636b62..f31dc437 100644 --- a/packages/instrumentation-pinecone/src/instrumentation.ts +++ b/packages/instrumentation-pinecone/src/instrumentation.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as pinecone from "@pinecone-database/pinecone"; +import type * as pinecone from "@pinecone-database/pinecone"; import { context, trace, Tracer, SpanStatusCode } from "@opentelemetry/api"; import { diff --git a/packages/instrumentation-vertexai/src/aiplatform-instrumentation.ts b/packages/instrumentation-vertexai/src/aiplatform-instrumentation.ts index 0132a24a..bed4e855 100644 --- a/packages/instrumentation-vertexai/src/aiplatform-instrumentation.ts +++ b/packages/instrumentation-vertexai/src/aiplatform-instrumentation.ts @@ -32,8 +32,8 @@ import { CONTEXT_KEY_ALLOW_TRACE_CONTENT, SpanAttributes, } from "@traceloop/ai-semantic-conventions"; -import * as aiplatform from "@google-cloud/aiplatform"; -import { CallOptions, Callback } from "google-gax"; +import type * as aiplatform from "@google-cloud/aiplatform"; +import type { CallOptions, Callback } from "google-gax"; export class AIPlatformInstrumentation extends InstrumentationBase { protected override _config!: AIPlatformInstrumentationConfig; diff --git a/packages/instrumentation-vertexai/src/vertexai-instrumentation.ts b/packages/instrumentation-vertexai/src/vertexai-instrumentation.ts index a92536e2..78ec887a 100644 --- a/packages/instrumentation-vertexai/src/vertexai-instrumentation.ts +++ b/packages/instrumentation-vertexai/src/vertexai-instrumentation.ts @@ -32,7 +32,7 @@ import { CONTEXT_KEY_ALLOW_TRACE_CONTENT, SpanAttributes, } from "@traceloop/ai-semantic-conventions"; -import * as vertexAI from "@google-cloud/vertexai"; +import type * as vertexAI from "@google-cloud/vertexai"; export class VertexAIInstrumentation extends InstrumentationBase { protected override _config!: VertexAIInstrumentationConfig; diff --git a/packages/traceloop-sdk/package.json b/packages/traceloop-sdk/package.json index f90e3ed3..d9d27d31 100644 --- a/packages/traceloop-sdk/package.json +++ b/packages/traceloop-sdk/package.json @@ -37,15 +37,15 @@ "dependencies": { "@opentelemetry/exporter-trace-otlp-proto": "^0.49.1", "@opentelemetry/sdk-node": "^0.49.1", - "@traceloop/ai-semantic-conventions": "^0.5.19", - "@traceloop/instrumentation-azure": "^0.5.21", - "@traceloop/instrumentation-bedrock": "^0.5.21", - "@traceloop/instrumentation-cohere": "^0.5.21", - "@traceloop/instrumentation-langchain": "^0.5.21", - "@traceloop/instrumentation-llamaindex": "^0.5.22", - "@traceloop/instrumentation-openai": "^0.5.21", - "@traceloop/instrumentation-pinecone": "^0.5.21", - "@traceloop/instrumentation-vertexai": "^0.5.21", + "@traceloop/ai-semantic-conventions": "*", + "@traceloop/instrumentation-azure": "*", + "@traceloop/instrumentation-bedrock": "*", + "@traceloop/instrumentation-cohere": "*", + "@traceloop/instrumentation-langchain": "*", + "@traceloop/instrumentation-llamaindex": "*", + "@traceloop/instrumentation-openai": "*", + "@traceloop/instrumentation-pinecone": "*", + "@traceloop/instrumentation-vertexai": "*", "@types/nunjucks": "^3.2.5", "cross-fetch": "^4.0.0", "fetch-retry": "^5.0.6", @@ -61,7 +61,6 @@ "@pollyjs/core": "^6.0.6", "@pollyjs/persister-fs": "^6.0.6", "@rollup/plugin-typescript": "^11.1.6", - "@types/expect": "^24.3.0", "@types/mocha": "^10.0.6", "@types/node": "^20.9.0", "@types/uuid": "^9.0.7", diff --git a/packages/traceloop-sdk/src/lib/tracing/index.ts b/packages/traceloop-sdk/src/lib/tracing/index.ts index 1dfd8ccb..0e2f759f 100644 --- a/packages/traceloop-sdk/src/lib/tracing/index.ts +++ b/packages/traceloop-sdk/src/lib/tracing/index.ts @@ -218,8 +218,6 @@ export const manuallyInitInstrumentations = ( export const startTracing = (options: InitializeOptions) => { if (Object.keys(options.instrumentModules || {}).length > 0) { manuallyInitInstrumentations(options.instrumentModules); - } else { - initInstrumentations(); } if (!shouldSendTraces()) { openAIInstrumentation?.setConfig({