9.5 KiB
Semantic Conventions for GenAI operations
Status: Experimental
A request to an Generative AI is modeled as a span in a trace.
Span kind: MUST always be CLIENT.
The span name SHOULD be set to a low cardinality value describing an operation made to an Generative AI system.
For example, the API name such as Create chat completion could be represented as completion gpt-4 to include the API and the model name.
Configuration
Instrumentations for Generative AI clients MAY capture prompts and completions. Instrumentations that support it, MUST offer the ability to turn off capture of prompts and completions. This is for three primary reasons:
- Data privacy concerns. End users of GenAI applications may input sensitive information or personally identifiable information (PII) that they do not wish to be sent to a telemetry backend.
- Data size concerns. Although there is no specified limit to sizes, there are practical limitations in programming languages and telemetry systems. Some GenAI systems allow for extremely large context windows that end users may take full advantage of.
- Performance concerns. Sending large amounts of data to a telemetry backend may cause performance issues for the application.
GenAI attributes
These attributes track input data and metadata for a request to an GenAI model. Each attribute represents a concept that is common to most Generative AI clients.
| Attribute | Type | Description | Examples | Requirement Level | Stability |
|---|---|---|---|---|---|
gen_ai.request.model |
string | The name of the GenAI model a request is being made to. [1] | gpt-4 |
Required |
|
gen_ai.system |
string | The Generative AI product as identified by the client instrumentation. [2] | openai |
Required |
|
gen_ai.request.frequency_penalty |
double | The frequency penalty setting for the GenAI request. | 0.1 |
Recommended |
|
gen_ai.request.max_tokens |
int | The maximum number of tokens the model generates for a request. | 100 |
Recommended |
|
gen_ai.request.presence_penalty |
double | The presence penalty setting for the GenAI request. | 0.1 |
Recommended |
|
gen_ai.request.stop_sequences |
string[] | List of sequences that the model will use to stop generating further tokens. | ["forest", "lived"] |
Recommended |
|
gen_ai.request.temperature |
double | The temperature setting for the GenAI request. | 0.0 |
Recommended |
|
gen_ai.request.top_k |
double | The top_k sampling setting for the GenAI request. | 1.0 |
Recommended |
|
gen_ai.request.top_p |
double | The top_p sampling setting for the GenAI request. | 1.0 |
Recommended |
|
gen_ai.response.finish_reasons |
string[] | Array of reasons the model stopped generating tokens, corresponding to each generation received. | ["stop"] |
Recommended |
|
gen_ai.response.id |
string | The unique identifier for the completion. | chatcmpl-123 |
Recommended |
|
gen_ai.response.model |
string | The name of the model that generated the response. [3] | gpt-4-0613 |
Recommended |
|
gen_ai.usage.completion_tokens |
int | The number of tokens used in the GenAI response (completion). | 180 |
Recommended |
|
gen_ai.usage.prompt_tokens |
int | The number of tokens used in the GenAI input or prompt. | 100 |
Recommended |
[1]: The name of the GenAI model a request is being made to. If the model is supplied by a vendor, then the value must be the exact name of the model requested. If the model is a fine-tuned custom model, the value should have a more specific name than the base model that's been fine-tuned.
[2]: The actual GenAI product may differ from the one identified by the client. For example, when using OpenAI client libraries to communicate with Mistral, the gen_ai.system is set to openai based on the instrumentation's best knowledge.
For custom model, a custom friendly name SHOULD be used. If none of these options apply, the gen_ai.system SHOULD be set to _OTHER.
[3]: If available. The name of the GenAI model that provided the response. If the model is supplied by a vendor, then the value must be the exact name of the model actually used. If the model is a fine-tuned custom model, the value should have a more specific name than the base model that's been fine-tuned.
gen_ai.system has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.
| Value | Description | Stability |
|---|---|---|
anthropic |
Anthropic | |
cohere |
Cohere | |
openai |
OpenAI | |
vertex_ai |
Vertex AI |
Events
In the lifetime of a GenAI span, an event for prompts sent and completions received MAY be created, depending on the configuration of the instrumentation.
The event name MUST be gen_ai.content.prompt.
| Attribute | Type | Description | Examples | Requirement Level | Stability |
|---|---|---|---|---|---|
gen_ai.prompt |
string | The full prompt sent to the GenAI model. [1] | [{'role': 'user', 'content': 'What is the capital of France?'}] |
Conditionally Required if and only if corresponding event is enabled |
[1]: It's RECOMMENDED to format prompts as JSON string matching OpenAI messages format
The event name MUST be gen_ai.content.completion.
| Attribute | Type | Description | Examples | Requirement Level | Stability |
|---|---|---|---|---|---|
gen_ai.completion |
string | The full response received from the GenAI model. [1] | [{'role': 'assistant', 'content': 'The capital of France is Paris.'}] |
Conditionally Required if and only if corresponding event is enabled |
[1]: It's RECOMMENDED to format completions as JSON string matching OpenAI messages format