diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f7fc3ba..d5b3f8cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.8.4](https://github.com/traceloop/openllmetry-js/compare/v0.8.3...v0.8.4) (2024-05-20) + +### Bug Fixes + +- **manual-tracing:** add missing llm.request.type attribute ([#269](https://github.com/traceloop/openllmetry-js/issues/269)) ([528c498](https://github.com/traceloop/openllmetry-js/commit/528c49850fb2a9b87cea92466b87aa6b0681d285)) +- **sdk:** serialize map outputs for non-promise outputs ([#276](https://github.com/traceloop/openllmetry-js/issues/276)) ([b4a8948](https://github.com/traceloop/openllmetry-js/commit/b4a8948314e413bbbee47c9f8d8698d98634ff18)) +- **sdk:** used wrong completion attribute in manual instrumentations ([#277](https://github.com/traceloop/openllmetry-js/issues/277)) ([b434f61](https://github.com/traceloop/openllmetry-js/commit/b434f61dd55da9967738bf4aa6110e1816a730e0)) + ## [0.8.3](https://github.com/traceloop/openllmetry-js/compare/v0.8.2...v0.8.3) (2024-05-16) ### Bug Fixes diff --git a/lerna.json b/lerna.json index 664bb0fa..f3337b7a 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "0.8.3", + "version": "0.8.4", "packages": ["packages/*"], "useNx": true } diff --git a/package-lock.json b/package-lock.json index 480f5440..f25d6721 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24139,7 +24139,7 @@ }, "packages/traceloop-sdk": { "name": "@traceloop/node-server-sdk", - "version": "0.8.3", + "version": "0.8.4", "license": "Apache-2.0", "dependencies": { "@opentelemetry/exporter-trace-otlp-proto": "^0.49.1", diff --git a/packages/traceloop-sdk/CHANGELOG.md b/packages/traceloop-sdk/CHANGELOG.md index 4bd902af..a68fe3c3 100644 --- a/packages/traceloop-sdk/CHANGELOG.md +++ b/packages/traceloop-sdk/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.8.4](https://github.com/traceloop/openllmetry-js/compare/v0.8.3...v0.8.4) (2024-05-20) + +### Bug Fixes + +- **manual-tracing:** add missing llm.request.type attribute ([#269](https://github.com/traceloop/openllmetry-js/issues/269)) ([528c498](https://github.com/traceloop/openllmetry-js/commit/528c49850fb2a9b87cea92466b87aa6b0681d285)) +- **sdk:** serialize map outputs for non-promise outputs ([#276](https://github.com/traceloop/openllmetry-js/issues/276)) ([b4a8948](https://github.com/traceloop/openllmetry-js/commit/b4a8948314e413bbbee47c9f8d8698d98634ff18)) +- **sdk:** used wrong completion attribute in manual instrumentations ([#277](https://github.com/traceloop/openllmetry-js/issues/277)) ([b434f61](https://github.com/traceloop/openllmetry-js/commit/b434f61dd55da9967738bf4aa6110e1816a730e0)) + ## [0.8.3](https://github.com/traceloop/openllmetry-js/compare/v0.8.2...v0.8.3) (2024-05-16) ### Bug Fixes diff --git a/packages/traceloop-sdk/package.json b/packages/traceloop-sdk/package.json index 65c506e8..121c9c85 100644 --- a/packages/traceloop-sdk/package.json +++ b/packages/traceloop-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@traceloop/node-server-sdk", - "version": "0.8.3", + "version": "0.8.4", "description": "Traceloop Software Development Kit (SDK) for Node.js", "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/packages/traceloop-sdk/src/lib/tracing/decorators.ts b/packages/traceloop-sdk/src/lib/tracing/decorators.ts index 239bd1aa..c6e79bbc 100644 --- a/packages/traceloop-sdk/src/lib/tracing/decorators.ts +++ b/packages/traceloop-sdk/src/lib/tracing/decorators.ts @@ -7,6 +7,7 @@ import { } from "@traceloop/ai-semantic-conventions"; import { withAssociationProperties } from "./association"; import { shouldSendTraces } from "."; +import { Telemetry } from "../telemetry/telemetry"; export type DecoratorConfig = { name: string; @@ -82,8 +83,8 @@ function withEntity< }), ); } - } catch { - /* empty */ + } catch (error) { + Telemetry.getInstance().logException(error); } } @@ -92,19 +93,14 @@ function withEntity< return res.then((resolvedRes) => { try { if (shouldSendTraces()) { - if (resolvedRes instanceof Map) { - span.setAttribute( - SpanAttributes.TRACELOOP_ENTITY_OUTPUT, - JSON.stringify(Array.from(resolvedRes.entries())), - ); - } else { - span.setAttribute( - SpanAttributes.TRACELOOP_ENTITY_OUTPUT, - JSON.stringify(resolvedRes), - ); - } + span.setAttribute( + SpanAttributes.TRACELOOP_ENTITY_OUTPUT, + serialize(resolvedRes), + ); } return resolvedRes; + } catch (error) { + Telemetry.getInstance().logException(error); } finally { span.end(); } @@ -114,10 +110,12 @@ function withEntity< if (shouldSendTraces()) { span.setAttribute( SpanAttributes.TRACELOOP_ENTITY_OUTPUT, - JSON.stringify(res), + serialize(res), ); } return res; + } catch (error) { + Telemetry.getInstance().logException(error); } finally { span.end(); } @@ -240,3 +238,11 @@ export function tool( ) { return entity(TraceloopSpanKindValues.TOOL, config ?? {}); } + +function serialize(input: unknown): string { + if (input instanceof Map) { + return JSON.stringify(Array.from(input.entries())); + } else { + return JSON.stringify(input); + } +} diff --git a/packages/traceloop-sdk/src/lib/tracing/manual.ts b/packages/traceloop-sdk/src/lib/tracing/manual.ts index 7c123e75..9a00fe06 100644 --- a/packages/traceloop-sdk/src/lib/tracing/manual.ts +++ b/packages/traceloop-sdk/src/lib/tracing/manual.ts @@ -126,9 +126,9 @@ export class LLMSpan { this.span.setAttributes({ [`${SpanAttributes.LLM_COMPLETIONS}.${index}.finish_reason`]: completion.finish_reason, - [`${SpanAttributes.LLM_COMPLETIONS}.${index}.message.role`]: + [`${SpanAttributes.LLM_COMPLETIONS}.${index}.role`]: completion.message.role, - [`${SpanAttributes.LLM_COMPLETIONS}.${index}.message.content`]: + [`${SpanAttributes.LLM_COMPLETIONS}.${index}.content`]: completion.message.content || "", }); }); @@ -163,6 +163,7 @@ export function withLLMCall< F extends ({ span }: { span: LLMSpan }) => ReturnType, >({ vendor, type }: LLMCallConfig, fn: F, thisArg?: ThisParameterType) { const span = getTracer().startSpan(`${vendor}.${type}`, {}, context.active()); + span.setAttribute(SpanAttributes.LLM_REQUEST_TYPE, type); trace.setSpan(context.active(), span); const res = fn.apply(thisArg, [{ span: new LLMSpan(span) }]); diff --git a/packages/traceloop-sdk/test/decorators.test.ts b/packages/traceloop-sdk/test/decorators.test.ts index f7f85923..eb50a0bf 100644 --- a/packages/traceloop-sdk/test/decorators.test.ts +++ b/packages/traceloop-sdk/test/decorators.test.ts @@ -414,8 +414,11 @@ describe("Test SDK Decorators", () => { completionSpan.parentSpanId, workflowSpan.spanContext().spanId, ); - assert.ok(workflowSpan.startTime <= completionSpan.startTime); - assert.ok(workflowSpan.endTime >= completionSpan.endTime); + + assert.strictEqual( + completionSpan.attributes[`${SpanAttributes.LLM_REQUEST_TYPE}`], + "chat", + ); assert.strictEqual( completionSpan.attributes[`${SpanAttributes.LLM_REQUEST_MODEL}`], "gpt-3.5-turbo", @@ -432,6 +435,10 @@ describe("Test SDK Decorators", () => { completionSpan.attributes[`${SpanAttributes.LLM_PROMPTS}.0.content`], "Tell me a joke about OpenTelemetry", ); + assert.strictEqual( + completionSpan.attributes[`${SpanAttributes.LLM_COMPLETIONS}.0.content`], + result.choices[0].message.content, + ); assert.ok( completionSpan.attributes[`${SpanAttributes.LLM_USAGE_TOTAL_TOKENS}`], );