Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ai-semantic-conventions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/semantic-conventions": "^1.38.0"
"@opentelemetry/semantic-conventions": "^1.40.0"
},
"homepage": "https://github.com/traceloop/openllmetry-js/tree/main/packages/ai-semantic-conventions",
"gitHead": "ef1e70d6037f7b5c061056ef2be16e3f55f02ed5"
Expand Down
66 changes: 54 additions & 12 deletions packages/ai-semantic-conventions/src/SemanticAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,56 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// TODO: Remove unnecessary comments after all instrumentations are updated before (parent branch merge)

export const SpanAttributes = {
// Attributes not yet in @opentelemetry/semantic-conventions
GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS:
"gen_ai.usage.cache_creation_input_tokens",

// TODO: Remove after all instrumentations are updated
// Kept for backwards compatibility
GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS: "gen_ai.usage.cache_creation_input_tokens",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is exists in the official Otel then we should replace it to that and delete this one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kept until we migrate all instrumentations.
Marked in todo for removal


// TODO: Remove after all instrumentations are updated
// Kept for backwards compatibility
GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS: "gen_ai.usage.cache_read_input_tokens",

GEN_AI_USAGE_REASONING_TOKENS: "gen_ai.usage.reasoning_tokens",

GEN_AI_REQUEST_THINKING_TYPE: "gen_ai.request.thinking_type",

GEN_AI_REQUEST_THINKING_BUDGET_TOKENS: "gen_ai.request.thinking.budget_tokens",
// LLM

// TODO: Remove after all instrumentations are updated
// Kept for backwards compatibility
LLM_REQUEST_TYPE: "llm.request.type",

GEN_AI_USAGE_TOTAL_TOKENS: "gen_ai.usage.total_tokens",

// TODO: Remove after all instrumentations are updated
// Kept for backwards compatibility
LLM_USAGE_TOTAL_TOKENS: "llm.usage.total_tokens",

// TODO: Remove after all instrumentations are updated
// Kept for backwards compatibility
LLM_TOP_K: "llm.top_k",

// TODO: Remove after all instrumentations are updated
// Kept for backwards compatibility
LLM_FREQUENCY_PENALTY: "llm.frequency_penalty",

// TODO: Remove after all instrumentations are updated
// Kept for backwards compatibility
LLM_PRESENCE_PENALTY: "llm.presence_penalty",

// TODO: Remove after all instrumentations are updated
// Kept for backwards compatibility
LLM_CHAT_STOP_SEQUENCES: "llm.chat.stop_sequences",
LLM_REQUEST_FUNCTIONS: "llm.request.functions",

// TODO: Remove after all instrumentations are updated
// Kept for backwards compatibility
LLM_REQUEST_FUNCTIONS: "llm.request.functions",

// Vector DB
VECTOR_DB_VENDOR: "db.system",
VECTOR_DB_QUERY_TOP_K: "db.vector.query.top_k",
Expand All @@ -42,7 +75,7 @@ export const SpanAttributes = {
VECTOR_DB_GET_INCLUDE_METADATA: "db.vector.get.include_metadata",
VECTOR_DB_GET_INCLUDE_VALUES: "db.vector.get.include_values",

// LLM Workflows
// LLM Workflows (all Traceloop-specific, no OTel equivalents yet)
TRACELOOP_SPAN_KIND: "traceloop.span.kind",
TRACELOOP_WORKFLOW_NAME: "traceloop.workflow.name",
TRACELOOP_ENTITY_NAME: "traceloop.entity.name",
Expand Down Expand Up @@ -84,19 +117,15 @@ export const EventAttributes = {

// DEPRECATED: Vector DB Query Response
VECTOR_DB_QUERY_RESULT_NAMESPACE: "db.vector.query.result.namespace",
VECTOR_DB_QUERY_RESULT_READ_UNITS_CONSUMED:
"db.vector.query.result.read_units",
VECTOR_DB_QUERY_RESULT_MATCHES_LENGTH:
"db.vector.query.result.matches_length",
VECTOR_DB_QUERY_RESULT_READ_UNITS_CONSUMED: "db.vector.query.result.read_units",
VECTOR_DB_QUERY_RESULT_MATCHES_LENGTH: "db.vector.query.result.matches_length",

// DEPRECATED: Vector DB Query Response of each result
VECTOR_DB_QUERY_RESULT_SCORE: "db.vector.query.result.{i}.score",
VECTOR_DB_QUERY_RESULT_ID: "db.vector.query.result.{i}.id",
VECTOR_DB_QUERY_RESULT_VALUES: "db.vector.query.result.{i}.values",
VECTOR_DB_QUERY_RESULT_SPARSE_INDICES:
"db.vector.query.result.{i}.sparse.indices",
VECTOR_DB_QUERY_RESULT_SPARSE_VALUES:
"db.vector.query.result.{i}.sparse.values",
VECTOR_DB_QUERY_RESULT_SPARSE_INDICES: "db.vector.query.result.{i}.sparse.indices",
VECTOR_DB_QUERY_RESULT_SPARSE_VALUES: "db.vector.query.result.{i}.sparse.values",
VECTOR_DB_QUERY_RESULT_METADATA: "db.vector.query.result.{i}.metadata",
};

Expand All @@ -115,3 +144,16 @@ export enum TraceloopSpanKindValues {
SESSION = "session",
UNKNOWN = "unknown",
}

/**
* Standardized finish reason values following OpenTelemetry semantic conventions.
* These should be used by all LLM provider instrumentations when mapping
* provider-specific stop reasons to standard values.
*/
export const FinishReasons = {
STOP: "stop",
LENGTH: "length",
TOOL_CALL: "tool_call",
CONTENT_FILTER: "content_filter",
ERROR: "error",
} as const;
5 changes: 3 additions & 2 deletions packages/instrumentation-anthropic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/core": "^2.0.1",
"@opentelemetry/instrumentation": "^0.203.0",
"@opentelemetry/semantic-conventions": "^1.38.0",
"@opentelemetry/semantic-conventions": "^1.40.0",
"@traceloop/ai-semantic-conventions": "workspace:*",
"@traceloop/instrumentation-utils": "workspace:*",
"tslib": "^2.8.1"
},
"devDependencies": {
"@anthropic-ai/sdk": "^0.71.0",
"@anthropic-ai/sdk": "^0.80.0",
"@opentelemetry/context-async-hooks": "^2.0.1",
"@opentelemetry/sdk-trace-node": "^2.0.1",
"@pollyjs/adapter-fetch": "^6.0.7",
Expand Down
Loading
Loading