Skip to content

Commit 619b303

Browse files
committed
merge
2 parents 4bf8808 + 8e05349 commit 619b303

File tree

82 files changed

+2055
-1810
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2055
-1810
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## [0.22.4](https://github.com/traceloop/openllmetry-js/compare/v0.22.3...v0.22.4) (2025-12-11)
7+
8+
### Bug Fixes
9+
10+
- **ai-sdk:** nest agent spans attribution ([#844](https://github.com/traceloop/openllmetry-js/issues/844)) ([b8ff3d5](https://github.com/traceloop/openllmetry-js/commit/b8ff3d5191d506162c54b2210d6a23987660af27))
11+
612
## [0.22.3](https://github.com/traceloop/openllmetry-js/compare/v0.22.2...v0.22.3) (2025-12-08)
713

814
### Bug Fixes

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
3-
"version": "0.22.3",
3+
"version": "0.22.4",
44
"packages": ["packages/*"],
55
"useNx": true
66
}

packages/ai-semantic-conventions/src/SemanticAttributes.ts

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,60 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {
18-
ATTR_GEN_AI_AGENT_NAME,
19-
ATTR_GEN_AI_COMPLETION,
20-
ATTR_GEN_AI_CONVERSATION_ID,
21-
ATTR_GEN_AI_INPUT_MESSAGES,
22-
ATTR_GEN_AI_OPERATION_NAME,
23-
ATTR_GEN_AI_OUTPUT_MESSAGES,
24-
ATTR_GEN_AI_PROMPT,
25-
ATTR_GEN_AI_PROVIDER_NAME,
26-
ATTR_GEN_AI_REQUEST_MAX_TOKENS,
27-
ATTR_GEN_AI_REQUEST_MODEL,
28-
ATTR_GEN_AI_REQUEST_TEMPERATURE,
29-
ATTR_GEN_AI_REQUEST_TOP_P,
30-
ATTR_GEN_AI_RESPONSE_FINISH_REASONS,
31-
ATTR_GEN_AI_RESPONSE_ID,
32-
ATTR_GEN_AI_RESPONSE_MODEL,
33-
ATTR_GEN_AI_SYSTEM,
34-
ATTR_GEN_AI_TOOL_CALL_ARGUMENTS,
35-
ATTR_GEN_AI_TOOL_CALL_ID,
36-
ATTR_GEN_AI_TOOL_CALL_RESULT,
37-
ATTR_GEN_AI_TOOL_NAME,
38-
ATTR_GEN_AI_USAGE_COMPLETION_TOKENS,
39-
ATTR_GEN_AI_USAGE_INPUT_TOKENS,
40-
ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,
41-
ATTR_GEN_AI_USAGE_PROMPT_TOKENS,
42-
// @ts-expect-error - Using exports path that TypeScript doesn't recognize but works at runtime
43-
} from "@opentelemetry/semantic-conventions/incubating";
44-
4517
export const SpanAttributes = {
46-
ATTR_GEN_AI_SYSTEM,
47-
ATTR_GEN_AI_REQUEST_MODEL,
48-
ATTR_GEN_AI_REQUEST_MAX_TOKENS,
49-
ATTR_GEN_AI_REQUEST_TEMPERATURE,
50-
ATTR_GEN_AI_REQUEST_TOP_P,
51-
ATTR_GEN_AI_PROMPT,
52-
ATTR_GEN_AI_COMPLETION,
53-
ATTR_GEN_AI_INPUT_MESSAGES,
54-
ATTR_GEN_AI_OUTPUT_MESSAGES,
55-
ATTR_GEN_AI_RESPONSE_MODEL,
56-
ATTR_GEN_AI_USAGE_PROMPT_TOKENS,
57-
ATTR_GEN_AI_USAGE_COMPLETION_TOKENS,
58-
ATTR_GEN_AI_USAGE_INPUT_TOKENS,
59-
ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,
60-
ATTR_GEN_AI_OPERATION_NAME,
61-
ATTR_GEN_AI_PROVIDER_NAME,
62-
ATTR_GEN_AI_TOOL_NAME,
63-
ATTR_GEN_AI_TOOL_CALL_ID,
64-
ATTR_GEN_AI_TOOL_CALL_ARGUMENTS,
65-
ATTR_GEN_AI_TOOL_CALL_RESULT,
66-
ATTR_GEN_AI_RESPONSE_ID,
67-
ATTR_GEN_AI_RESPONSE_FINISH_REASONS,
68-
ATTR_GEN_AI_CONVERSATION_ID,
69-
ATTR_GEN_AI_AGENT_NAME,
70-
7118
// Attributes not yet in @opentelemetry/semantic-conventions
7219
GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS:
7320
"gen_ai.usage.cache_creation_input_tokens",

packages/ai-semantic-conventions/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
44
"outDir": "dist",
5-
"rootDir": "."
5+
"rootDir": ".",
6+
"moduleResolution": "node16",
7+
"module": "node16"
68
},
79
"files": [],
810
"include": ["src/**/*.ts", "test/**/*.ts"],

packages/instrumentation-anthropic/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"build": "rollup -c",
1111
"lint": "eslint .",
1212
"lint:fix": "eslint . --fix",
13-
"test": "ts-mocha -p tsconfig.json 'test/**/*.test.ts'"
13+
"test": "ts-mocha -p tsconfig.test.json 'test/**/*.test.ts'"
1414
},
1515
"keywords": [
1616
"opentelemetry",
@@ -41,7 +41,7 @@
4141
"@opentelemetry/api": "^1.9.0",
4242
"@opentelemetry/core": "^2.0.1",
4343
"@opentelemetry/instrumentation": "^0.203.0",
44-
"@opentelemetry/semantic-conventions": "^1.36.0",
44+
"@opentelemetry/semantic-conventions": "^1.38.0",
4545
"@traceloop/ai-semantic-conventions": "workspace:*",
4646
"tslib": "^2.8.1"
4747
},

packages/instrumentation-anthropic/src/instrumentation.ts

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ import {
3131
CONTEXT_KEY_ALLOW_TRACE_CONTENT,
3232
SpanAttributes,
3333
} from "@traceloop/ai-semantic-conventions";
34+
import {
35+
ATTR_GEN_AI_COMPLETION,
36+
ATTR_GEN_AI_PROMPT,
37+
ATTR_GEN_AI_REQUEST_MAX_TOKENS,
38+
ATTR_GEN_AI_REQUEST_MODEL,
39+
ATTR_GEN_AI_REQUEST_TEMPERATURE,
40+
ATTR_GEN_AI_REQUEST_TOP_P,
41+
ATTR_GEN_AI_RESPONSE_MODEL,
42+
ATTR_GEN_AI_SYSTEM,
43+
ATTR_GEN_AI_USAGE_COMPLETION_TOKENS,
44+
ATTR_GEN_AI_USAGE_PROMPT_TOKENS,
45+
} from "@opentelemetry/semantic-conventions/incubating";
3446
import { AnthropicInstrumentationConfig } from "./types";
3547
import { version } from "../package.json";
3648
import type * as anthropic from "@anthropic-ai/sdk";
@@ -204,15 +216,14 @@ export class AnthropicInstrumentation extends InstrumentationBase {
204216
};
205217
}): Span {
206218
const attributes: Attributes = {
207-
[SpanAttributes.ATTR_GEN_AI_SYSTEM]: "Anthropic",
219+
[ATTR_GEN_AI_SYSTEM]: "Anthropic",
208220
[SpanAttributes.LLM_REQUEST_TYPE]: type,
209221
};
210222

211223
try {
212-
attributes[SpanAttributes.ATTR_GEN_AI_REQUEST_MODEL] = params.model;
213-
attributes[SpanAttributes.ATTR_GEN_AI_REQUEST_TEMPERATURE] =
214-
params.temperature;
215-
attributes[SpanAttributes.ATTR_GEN_AI_REQUEST_TOP_P] = params.top_p;
224+
attributes[ATTR_GEN_AI_REQUEST_MODEL] = params.model;
225+
attributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] = params.temperature;
226+
attributes[ATTR_GEN_AI_REQUEST_TOP_P] = params.top_p;
216227
attributes[SpanAttributes.LLM_TOP_K] = params.top_k;
217228

218229
// Handle thinking parameters (for beta messages)
@@ -224,11 +235,10 @@ export class AnthropicInstrumentation extends InstrumentationBase {
224235
}
225236

226237
if (type === "completion") {
227-
attributes[SpanAttributes.ATTR_GEN_AI_REQUEST_MAX_TOKENS] =
238+
attributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =
228239
params.max_tokens_to_sample;
229240
} else {
230-
attributes[SpanAttributes.ATTR_GEN_AI_REQUEST_MAX_TOKENS] =
231-
params.max_tokens;
241+
attributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] = params.max_tokens;
232242
}
233243

234244
if (
@@ -246,9 +256,8 @@ export class AnthropicInstrumentation extends InstrumentationBase {
246256

247257
// If a system prompt is provided, it should always be first
248258
if ("system" in params && params.system !== undefined) {
249-
attributes[`${SpanAttributes.ATTR_GEN_AI_PROMPT}.0.role`] =
250-
"system";
251-
attributes[`${SpanAttributes.ATTR_GEN_AI_PROMPT}.0.content`] =
259+
attributes[`${ATTR_GEN_AI_PROMPT}.0.role`] = "system";
260+
attributes[`${ATTR_GEN_AI_PROMPT}.0.content`] =
252261
typeof params.system === "string"
253262
? params.system
254263
: JSON.stringify(params.system);
@@ -257,23 +266,19 @@ export class AnthropicInstrumentation extends InstrumentationBase {
257266

258267
params.messages.forEach((message, index) => {
259268
const currentIndex = index + promptIndex;
260-
attributes[
261-
`${SpanAttributes.ATTR_GEN_AI_PROMPT}.${currentIndex}.role`
262-
] = message.role;
269+
attributes[`${ATTR_GEN_AI_PROMPT}.${currentIndex}.role`] =
270+
message.role;
263271
if (typeof message.content === "string") {
264-
attributes[
265-
`${SpanAttributes.ATTR_GEN_AI_PROMPT}.${currentIndex}.content`
266-
] = (message.content as string) || "";
272+
attributes[`${ATTR_GEN_AI_PROMPT}.${currentIndex}.content`] =
273+
(message.content as string) || "";
267274
} else {
268-
attributes[
269-
`${SpanAttributes.ATTR_GEN_AI_PROMPT}.${currentIndex}.content`
270-
] = JSON.stringify(message.content);
275+
attributes[`${ATTR_GEN_AI_PROMPT}.${currentIndex}.content`] =
276+
JSON.stringify(message.content);
271277
}
272278
});
273279
} else {
274-
attributes[`${SpanAttributes.ATTR_GEN_AI_PROMPT}.0.role`] = "user";
275-
attributes[`${SpanAttributes.ATTR_GEN_AI_PROMPT}.0.content`] =
276-
params.prompt;
280+
attributes[`${ATTR_GEN_AI_PROMPT}.0.role`] = "user";
281+
attributes[`${ATTR_GEN_AI_PROMPT}.0.content`] = params.prompt;
277282
}
278283
}
279284
} catch (e) {
@@ -482,49 +487,40 @@ export class AnthropicInstrumentation extends InstrumentationBase {
482487
result: Completion;
483488
}) {
484489
try {
485-
span.setAttribute(
486-
SpanAttributes.ATTR_GEN_AI_RESPONSE_MODEL,
487-
result.model,
488-
);
490+
span.setAttribute(ATTR_GEN_AI_RESPONSE_MODEL, result.model);
489491
if (type === "chat" && result.usage) {
490492
span.setAttribute(
491493
SpanAttributes.LLM_USAGE_TOTAL_TOKENS,
492494
result.usage?.input_tokens + result.usage?.output_tokens,
493495
);
494496
span.setAttribute(
495-
SpanAttributes.ATTR_GEN_AI_USAGE_COMPLETION_TOKENS,
497+
ATTR_GEN_AI_USAGE_COMPLETION_TOKENS,
496498
result.usage?.output_tokens,
497499
);
498500
span.setAttribute(
499-
SpanAttributes.ATTR_GEN_AI_USAGE_PROMPT_TOKENS,
501+
ATTR_GEN_AI_USAGE_PROMPT_TOKENS,
500502
result.usage?.input_tokens,
501503
);
502504
}
503505

504506
if (result.stop_reason) {
505507
span.setAttribute(
506-
`${SpanAttributes.ATTR_GEN_AI_COMPLETION}.0.finish_reason`,
508+
`${ATTR_GEN_AI_COMPLETION}.0.finish_reason`,
507509
result.stop_reason,
508510
);
509511
}
510512

511513
if (this._shouldSendPrompts()) {
512514
if (type === "chat") {
515+
span.setAttribute(`${ATTR_GEN_AI_COMPLETION}.0.role`, "assistant");
513516
span.setAttribute(
514-
`${SpanAttributes.ATTR_GEN_AI_COMPLETION}.0.role`,
515-
"assistant",
516-
);
517-
span.setAttribute(
518-
`${SpanAttributes.ATTR_GEN_AI_COMPLETION}.0.content`,
517+
`${ATTR_GEN_AI_COMPLETION}.0.content`,
519518
JSON.stringify(result.content),
520519
);
521520
} else {
521+
span.setAttribute(`${ATTR_GEN_AI_COMPLETION}.0.role`, "assistant");
522522
span.setAttribute(
523-
`${SpanAttributes.ATTR_GEN_AI_COMPLETION}.0.role`,
524-
"assistant",
525-
);
526-
span.setAttribute(
527-
`${SpanAttributes.ATTR_GEN_AI_COMPLETION}.0.content`,
523+
`${ATTR_GEN_AI_COMPLETION}.0.content`,
528524
result.completion,
529525
);
530526
}

0 commit comments

Comments
 (0)