Skip to content

Commit 643425a

Browse files
authored
feat(ai-semantic-conventions, instrumentation-anthropic): align GenAI semconv with OTel 1.40 and migrate Anthropic instrumentation (#896)
1 parent 50a591c commit 643425a

File tree

18 files changed

+2171
-193
lines changed

18 files changed

+2171
-193
lines changed

packages/ai-semantic-conventions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
"dependencies": {
3737
"@opentelemetry/api": "^1.9.0",
38-
"@opentelemetry/semantic-conventions": "^1.38.0"
38+
"@opentelemetry/semantic-conventions": "^1.40.0"
3939
},
4040
"homepage": "https://github.com/traceloop/openllmetry-js/tree/main/packages/ai-semantic-conventions",
4141
"gitHead": "ef1e70d6037f7b5c061056ef2be16e3f55f02ed5"

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,56 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
// TODO: Remove unnecessary comments after all instrumentations are updated before (parent branch merge)
1617

1718
export const SpanAttributes = {
1819
// Attributes not yet in @opentelemetry/semantic-conventions
20+
21+
// TODO: Remove after all instrumentations are updated
22+
// Kept for backwards compatibility
1923
GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS:
2024
"gen_ai.usage.cache_creation_input_tokens",
25+
26+
// TODO: Remove after all instrumentations are updated
27+
// Kept for backwards compatibility
2128
GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS: "gen_ai.usage.cache_read_input_tokens",
29+
2230
GEN_AI_USAGE_REASONING_TOKENS: "gen_ai.usage.reasoning_tokens",
2331

32+
GEN_AI_REQUEST_THINKING_TYPE: "gen_ai.request.thinking_type",
33+
34+
GEN_AI_REQUEST_THINKING_BUDGET_TOKENS:
35+
"gen_ai.request.thinking.budget_tokens",
2436
// LLM
37+
38+
// TODO: Remove after all instrumentations are updated
39+
// Kept for backwards compatibility
2540
LLM_REQUEST_TYPE: "llm.request.type",
41+
42+
GEN_AI_USAGE_TOTAL_TOKENS: "gen_ai.usage.total_tokens",
43+
44+
// TODO: Remove after all instrumentations are updated
45+
// Kept for backwards compatibility
2646
LLM_USAGE_TOTAL_TOKENS: "llm.usage.total_tokens",
47+
48+
// TODO: Remove after all instrumentations are updated
49+
// Kept for backwards compatibility
2750
LLM_TOP_K: "llm.top_k",
51+
52+
// TODO: Remove after all instrumentations are updated
53+
// Kept for backwards compatibility
2854
LLM_FREQUENCY_PENALTY: "llm.frequency_penalty",
55+
56+
// TODO: Remove after all instrumentations are updated
57+
// Kept for backwards compatibility
2958
LLM_PRESENCE_PENALTY: "llm.presence_penalty",
59+
60+
// TODO: Remove after all instrumentations are updated
61+
// Kept for backwards compatibility
3062
LLM_CHAT_STOP_SEQUENCES: "llm.chat.stop_sequences",
63+
64+
// TODO: Remove after all instrumentations are updated
65+
// Kept for backwards compatibility
3166
LLM_REQUEST_FUNCTIONS: "llm.request.functions",
3267

3368
// Vector DB
@@ -42,7 +77,7 @@ export const SpanAttributes = {
4277
VECTOR_DB_GET_INCLUDE_METADATA: "db.vector.get.include_metadata",
4378
VECTOR_DB_GET_INCLUDE_VALUES: "db.vector.get.include_values",
4479

45-
// LLM Workflows
80+
// LLM Workflows (all Traceloop-specific, no OTel equivalents yet)
4681
TRACELOOP_SPAN_KIND: "traceloop.span.kind",
4782
TRACELOOP_WORKFLOW_NAME: "traceloop.workflow.name",
4883
TRACELOOP_ENTITY_NAME: "traceloop.entity.name",
@@ -115,3 +150,16 @@ export enum TraceloopSpanKindValues {
115150
SESSION = "session",
116151
UNKNOWN = "unknown",
117152
}
153+
154+
/**
155+
* Standardized finish reason values following OpenTelemetry semantic conventions.
156+
* These should be used by all LLM provider instrumentations when mapping
157+
* provider-specific stop reasons to standard values.
158+
*/
159+
export const FinishReasons = {
160+
STOP: "stop",
161+
LENGTH: "length",
162+
TOOL_CALL: "tool_call",
163+
CONTENT_FILTER: "content_filter",
164+
ERROR: "error",
165+
} as const;

packages/instrumentation-anthropic/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141
"@opentelemetry/api": "^1.9.0",
4242
"@opentelemetry/core": "^2.0.1",
4343
"@opentelemetry/instrumentation": "^0.203.0",
44-
"@opentelemetry/semantic-conventions": "^1.38.0",
44+
"@opentelemetry/semantic-conventions": "^1.40.0",
4545
"@traceloop/ai-semantic-conventions": "workspace:*",
46+
"@traceloop/instrumentation-utils": "workspace:*",
4647
"tslib": "^2.8.1"
4748
},
4849
"devDependencies": {
49-
"@anthropic-ai/sdk": "^0.71.0",
50+
"@anthropic-ai/sdk": "^0.80.0",
5051
"@opentelemetry/context-async-hooks": "^2.0.1",
5152
"@opentelemetry/sdk-trace-node": "^2.0.1",
5253
"@pollyjs/adapter-fetch": "^6.0.7",

0 commit comments

Comments
 (0)