openinference-semantic-conventions 0.1.1

OpenInference semantic conventions for LLM observability in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
//! OpenInference semantic convention attribute keys.
//!
//! These constants define the attribute keys used in OpenInference spans.
//! See: <https://github.com/Arize-ai/openinference/blob/main/spec/semantic_conventions.md>

use opentelemetry::Key;

// =============================================================================
// Core Attributes
// =============================================================================

/// The kind of span (LLM, EMBEDDING, CHAIN, TOOL, AGENT, RETRIEVER, RERANKER, GUARDRAIL, EVALUATOR).
/// This attribute is required for all OpenInference spans.
pub const OPENINFERENCE_SPAN_KIND: Key = Key::from_static_str("openinference.span.kind");

// =============================================================================
// LLM Attributes
// =============================================================================

/// Attributes for Large Language Model spans.
pub mod llm {
    use opentelemetry::Key;

    /// The name of the language model being used.
    pub const MODEL_NAME: Key = Key::from_static_str("llm.model_name");

    /// The LLM system or provider (e.g., "openai", "anthropic").
    pub const SYSTEM: Key = Key::from_static_str("llm.system");

    /// The LLM provider name.
    pub const PROVIDER: Key = Key::from_static_str("llm.provider");

    /// JSON string of invocation parameters (temperature, max_tokens, etc.).
    pub const INVOCATION_PARAMETERS: Key = Key::from_static_str("llm.invocation_parameters");

    /// Deprecated function call (use tool_calls instead).
    pub const FUNCTION_CALL: Key = Key::from_static_str("llm.function_call");

    /// Input messages to the LLM.
    pub mod input_messages {
        use opentelemetry::Key;

        /// Format: llm.input_messages.{index}.message.role
        pub fn role(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("llm.input_messages.{index}.message.role").into_boxed_str(),
            ))
        }

        /// Format: llm.input_messages.{index}.message.content
        pub fn content(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("llm.input_messages.{index}.message.content").into_boxed_str(),
            ))
        }

        /// Format: llm.input_messages.{index}.message.contents.{content_index}.message_content.type
        pub fn content_type(index: usize, content_index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("llm.input_messages.{index}.message.contents.{content_index}.message_content.type").into_boxed_str(),
            ))
        }

        /// Format: llm.input_messages.{index}.message.contents.{content_index}.message_content.text
        pub fn content_text(index: usize, content_index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("llm.input_messages.{index}.message.contents.{content_index}.message_content.text").into_boxed_str(),
            ))
        }
    }

    /// Output messages from the LLM.
    pub mod output_messages {
        use opentelemetry::Key;

        /// Format: llm.output_messages.{index}.message.role
        pub fn role(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("llm.output_messages.{index}.message.role").into_boxed_str(),
            ))
        }

        /// Format: llm.output_messages.{index}.message.content
        pub fn content(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("llm.output_messages.{index}.message.content").into_boxed_str(),
            ))
        }

        /// Tool calls in output messages.
        pub mod tool_calls {
            use opentelemetry::Key;

            /// Format: llm.output_messages.{msg_index}.message.tool_calls.{call_index}.tool_call.id
            pub fn id(msg_index: usize, call_index: usize) -> Key {
                Key::from_static_str(Box::leak(
                    format!("llm.output_messages.{msg_index}.message.tool_calls.{call_index}.tool_call.id").into_boxed_str(),
                ))
            }

            /// Format: llm.output_messages.{msg_index}.message.tool_calls.{call_index}.tool_call.function.name
            pub fn function_name(msg_index: usize, call_index: usize) -> Key {
                Key::from_static_str(Box::leak(
                    format!("llm.output_messages.{msg_index}.message.tool_calls.{call_index}.tool_call.function.name").into_boxed_str(),
                ))
            }

            /// Format: llm.output_messages.{msg_index}.message.tool_calls.{call_index}.tool_call.function.arguments
            pub fn function_arguments(msg_index: usize, call_index: usize) -> Key {
                Key::from_static_str(Box::leak(
                    format!("llm.output_messages.{msg_index}.message.tool_calls.{call_index}.tool_call.function.arguments").into_boxed_str(),
                ))
            }
        }
    }

    /// Prompts for text completion (non-chat).
    pub mod prompts {
        use opentelemetry::Key;

        /// Format: llm.prompts.{index}.prompt.text
        pub fn text(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("llm.prompts.{index}.prompt.text").into_boxed_str(),
            ))
        }
    }

    /// Choices/completions from text completion.
    pub mod choices {
        use opentelemetry::Key;

        /// Format: llm.choices.{index}.completion.text
        pub fn text(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("llm.choices.{index}.completion.text").into_boxed_str(),
            ))
        }
    }

    /// Tools available to the LLM.
    pub mod tools {
        use opentelemetry::Key;

        /// Format: llm.tools.{index}.tool.json_schema
        pub fn json_schema(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("llm.tools.{index}.tool.json_schema").into_boxed_str(),
            ))
        }
    }

    /// Prompt template information.
    pub mod prompt_template {
        use opentelemetry::Key;

        /// The prompt template string.
        pub const TEMPLATE: Key = Key::from_static_str("llm.prompt_template.template");

        /// JSON string of template variables.
        pub const VARIABLES: Key = Key::from_static_str("llm.prompt_template.variables");

        /// Version of the prompt template.
        pub const VERSION: Key = Key::from_static_str("llm.prompt_template.version");
    }

    /// Token count attributes.
    pub mod token_count {
        use opentelemetry::Key;

        /// Number of tokens in the prompt/input.
        pub const PROMPT: Key = Key::from_static_str("llm.token_count.prompt");

        /// Number of tokens in the completion/output.
        pub const COMPLETION: Key = Key::from_static_str("llm.token_count.completion");

        /// Total number of tokens (prompt + completion).
        pub const TOTAL: Key = Key::from_static_str("llm.token_count.total");

        /// Detailed prompt token breakdown.
        pub mod prompt_details {
            use opentelemetry::Key;

            /// Tokens read from cache.
            pub const CACHE_READ: Key =
                Key::from_static_str("llm.token_count.prompt_details.cache_read");

            /// Tokens written to cache.
            pub const CACHE_WRITE: Key =
                Key::from_static_str("llm.token_count.prompt_details.cache_write");

            /// Audio tokens in prompt.
            pub const AUDIO: Key = Key::from_static_str("llm.token_count.prompt_details.audio");
        }

        /// Detailed completion token breakdown.
        pub mod completion_details {
            use opentelemetry::Key;

            /// Reasoning tokens in completion.
            pub const REASONING: Key =
                Key::from_static_str("llm.token_count.completion_details.reasoning");

            /// Audio tokens in completion.
            pub const AUDIO: Key = Key::from_static_str("llm.token_count.completion_details.audio");
        }
    }

    /// Cost attributes.
    pub mod cost {
        use opentelemetry::Key;

        /// Cost of the prompt.
        pub const PROMPT: Key = Key::from_static_str("llm.cost.prompt");

        /// Cost of the completion.
        pub const COMPLETION: Key = Key::from_static_str("llm.cost.completion");

        /// Total cost.
        pub const TOTAL: Key = Key::from_static_str("llm.cost.total");

        /// Detailed prompt cost breakdown.
        pub mod prompt_details {
            use opentelemetry::Key;

            pub const INPUT: Key = Key::from_static_str("llm.cost.prompt_details.input");
            pub const CACHE_WRITE: Key =
                Key::from_static_str("llm.cost.prompt_details.cache_write");
            pub const CACHE_READ: Key = Key::from_static_str("llm.cost.prompt_details.cache_read");
            pub const CACHE_INPUT: Key =
                Key::from_static_str("llm.cost.prompt_details.cache_input");
            pub const AUDIO: Key = Key::from_static_str("llm.cost.prompt_details.audio");
        }

        /// Detailed completion cost breakdown.
        pub mod completion_details {
            use opentelemetry::Key;

            pub const OUTPUT: Key = Key::from_static_str("llm.cost.completion_details.output");
            pub const REASONING: Key =
                Key::from_static_str("llm.cost.completion_details.reasoning");
            pub const AUDIO: Key = Key::from_static_str("llm.cost.completion_details.audio");
        }
    }
}

// =============================================================================
// Embedding Attributes
// =============================================================================

/// Attributes for embedding spans.
pub mod embedding {
    use opentelemetry::Key;

    /// The name of the embedding model.
    pub const MODEL_NAME: Key = Key::from_static_str("embedding.model_name");

    /// The text being embedded (single embedding).
    pub const TEXT: Key = Key::from_static_str("embedding.text");

    /// The embedding vector (single embedding).
    pub const VECTOR: Key = Key::from_static_str("embedding.vector");

    /// JSON string of invocation parameters.
    pub const INVOCATION_PARAMETERS: Key = Key::from_static_str("embedding.invocation_parameters");

    /// Multiple embeddings.
    pub mod embeddings {
        use opentelemetry::Key;

        /// Format: embedding.embeddings.{index}.embedding.vector
        pub fn vector(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("embedding.embeddings.{index}.embedding.vector").into_boxed_str(),
            ))
        }

        /// Format: embedding.embeddings.{index}.embedding.text
        pub fn text(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("embedding.embeddings.{index}.embedding.text").into_boxed_str(),
            ))
        }
    }
}

// =============================================================================
// Tool Attributes
// =============================================================================

/// Attributes for tool spans.
pub mod tool {
    use opentelemetry::Key;

    /// Name of the tool.
    pub const NAME: Key = Key::from_static_str("tool.name");

    /// Description of the tool's purpose.
    pub const DESCRIPTION: Key = Key::from_static_str("tool.description");

    /// JSON schema of the tool.
    pub const JSON_SCHEMA: Key = Key::from_static_str("tool.json_schema");

    /// Parameters passed to the tool (JSON string).
    pub const PARAMETERS: Key = Key::from_static_str("tool.parameters");

    /// Tool ID.
    pub const ID: Key = Key::from_static_str("tool.id");
}

/// Attributes for tool calls.
pub mod tool_call {
    use opentelemetry::Key;

    /// Tool call ID.
    pub const ID: Key = Key::from_static_str("tool_call.id");

    /// Function attributes.
    pub mod function {
        use opentelemetry::Key;

        /// Function name.
        pub const NAME: Key = Key::from_static_str("tool_call.function.name");

        /// Function arguments (JSON string).
        pub const ARGUMENTS: Key = Key::from_static_str("tool_call.function.arguments");
    }
}

// =============================================================================
// Document Attributes
// =============================================================================

/// Attributes for documents (used in retrieval/reranking).
pub mod document {
    use opentelemetry::Key;

    /// Document ID.
    pub const ID: Key = Key::from_static_str("document.id");

    /// Document content.
    pub const CONTENT: Key = Key::from_static_str("document.content");

    /// Document score (relevance, similarity, etc.).
    pub const SCORE: Key = Key::from_static_str("document.score");

    /// Document metadata (JSON string).
    pub const METADATA: Key = Key::from_static_str("document.metadata");
}

// =============================================================================
// Retrieval Attributes
// =============================================================================

/// Attributes for retriever spans.
pub mod retrieval {
    /// Documents returned by retrieval.
    pub mod documents {
        use opentelemetry::Key;

        /// Format: retrieval.documents.{index}.document.id
        pub fn id(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("retrieval.documents.{index}.document.id").into_boxed_str(),
            ))
        }

        /// Format: retrieval.documents.{index}.document.content
        pub fn content(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("retrieval.documents.{index}.document.content").into_boxed_str(),
            ))
        }

        /// Format: retrieval.documents.{index}.document.score
        pub fn score(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("retrieval.documents.{index}.document.score").into_boxed_str(),
            ))
        }

        /// Format: retrieval.documents.{index}.document.metadata
        pub fn metadata(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("retrieval.documents.{index}.document.metadata").into_boxed_str(),
            ))
        }
    }
}

// =============================================================================
// Reranker Attributes
// =============================================================================

/// Attributes for reranker spans.
pub mod reranker {
    use opentelemetry::Key;

    /// The reranker model name.
    pub const MODEL_NAME: Key = Key::from_static_str("reranker.model_name");

    /// The query used for reranking.
    pub const QUERY: Key = Key::from_static_str("reranker.query");

    /// Number of top documents to return.
    pub const TOP_K: Key = Key::from_static_str("reranker.top_k");

    /// Input documents.
    pub mod input_documents {
        use opentelemetry::Key;

        pub fn id(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("reranker.input_documents.{index}.document.id").into_boxed_str(),
            ))
        }

        pub fn content(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("reranker.input_documents.{index}.document.content").into_boxed_str(),
            ))
        }

        pub fn score(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("reranker.input_documents.{index}.document.score").into_boxed_str(),
            ))
        }
    }

    /// Output documents (reranked).
    pub mod output_documents {
        use opentelemetry::Key;

        pub fn id(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("reranker.output_documents.{index}.document.id").into_boxed_str(),
            ))
        }

        pub fn content(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("reranker.output_documents.{index}.document.content").into_boxed_str(),
            ))
        }

        pub fn score(index: usize) -> Key {
            Key::from_static_str(Box::leak(
                format!("reranker.output_documents.{index}.document.score").into_boxed_str(),
            ))
        }
    }
}

// =============================================================================
// Input/Output Attributes
// =============================================================================

/// Input attributes.
pub mod input {
    use opentelemetry::Key;

    /// The input value.
    pub const VALUE: Key = Key::from_static_str("input.value");

    /// The MIME type of the input.
    pub const MIME_TYPE: Key = Key::from_static_str("input.mime_type");
}

/// Output attributes.
pub mod output {
    use opentelemetry::Key;

    /// The output value.
    pub const VALUE: Key = Key::from_static_str("output.value");

    /// The MIME type of the output.
    pub const MIME_TYPE: Key = Key::from_static_str("output.mime_type");
}

// =============================================================================
// Session/User Attributes
// =============================================================================

/// User attributes.
pub mod user {
    use opentelemetry::Key;

    /// User ID.
    pub const ID: Key = Key::from_static_str("user.id");
}

/// Session attributes.
pub mod session {
    use opentelemetry::Key;

    /// Session ID.
    pub const ID: Key = Key::from_static_str("session.id");
}

// =============================================================================
// Exception Attributes
// =============================================================================

/// Exception attributes for error tracking.
pub mod exception {
    use opentelemetry::Key;

    /// Exception type/class name.
    pub const TYPE: Key = Key::from_static_str("exception.type");

    /// Exception message.
    pub const MESSAGE: Key = Key::from_static_str("exception.message");

    /// Exception stack trace.
    pub const STACKTRACE: Key = Key::from_static_str("exception.stacktrace");

    /// Whether the exception escaped the span.
    pub const ESCAPED: Key = Key::from_static_str("exception.escaped");
}

// =============================================================================
// Metadata Attributes
// =============================================================================

/// General metadata attribute (JSON string).
pub const METADATA: Key = Key::from_static_str("metadata");

/// Tags attributes.
pub mod tag {
    use opentelemetry::Key;

    /// List of tags.
    pub const TAGS: Key = Key::from_static_str("tag.tags");
}

// =============================================================================
// Multimodal Attributes
// =============================================================================

/// Image attributes.
pub mod image {
    use opentelemetry::Key;

    /// Image URL.
    pub const URL: Key = Key::from_static_str("image.url");
}

/// Audio attributes.
pub mod audio {
    use opentelemetry::Key;

    /// Audio URL.
    pub const URL: Key = Key::from_static_str("audio.url");

    /// Audio MIME type.
    pub const MIME_TYPE: Key = Key::from_static_str("audio.mime_type");

    /// Audio transcript.
    pub const TRANSCRIPT: Key = Key::from_static_str("audio.transcript");
}

// =============================================================================
// Agent/Graph Attributes
// =============================================================================

/// Agent attributes.
pub mod agent {
    use opentelemetry::Key;

    /// Agent name.
    pub const NAME: Key = Key::from_static_str("agent.name");
}

/// Graph node attributes.
pub mod graph {
    /// Node attributes.
    pub mod node {
        use opentelemetry::Key;

        /// Node ID.
        pub const ID: Key = Key::from_static_str("graph.node.id");

        /// Node name.
        pub const NAME: Key = Key::from_static_str("graph.node.name");

        /// Parent node ID.
        pub const PARENT_ID: Key = Key::from_static_str("graph.node.parent_id");
    }
}

// =============================================================================
// Prompt Attributes
// =============================================================================

/// Prompt management attributes.
pub mod prompt {
    use opentelemetry::Key;

    /// Prompt vendor/provider.
    pub const VENDOR: Key = Key::from_static_str("prompt.vendor");

    /// Prompt ID.
    pub const ID: Key = Key::from_static_str("prompt.id");

    /// Prompt URL.
    pub const URL: Key = Key::from_static_str("prompt.url");
}

// =============================================================================
// Message Attributes (standalone)
// =============================================================================

/// Standalone message attributes.
pub mod message {
    use opentelemetry::Key;

    /// Message role.
    pub const ROLE: Key = Key::from_static_str("message.role");

    /// Message content.
    pub const CONTENT: Key = Key::from_static_str("message.content");

    /// Function call name (deprecated, use tool_calls).
    pub const FUNCTION_CALL_NAME: Key = Key::from_static_str("message.function_call_name");

    /// Function call arguments (deprecated, use tool_calls).
    pub const FUNCTION_CALL_ARGUMENTS_JSON: Key =
        Key::from_static_str("message.function_call_arguments_json");

    /// Tool call ID (for tool responses).
    pub const TOOL_CALL_ID: Key = Key::from_static_str("message.tool_call_id");
}