diff --git a/docs/ai/llm-spans.md b/docs/ai/llm-spans.md index 12884056f9..894d464786 100644 --- a/docs/ai/llm-spans.md +++ b/docs/ai/llm-spans.md @@ -12,7 +12,6 @@ linkTitle: LLM Calls - [Configuration](#configuration) - [LLM Request attributes](#llm-request-attributes) -- [LLM Response attributes](#llm-response-attributes) - [Events](#events) @@ -36,65 +35,52 @@ By default, these configurations SHOULD NOT capture prompts and completions. These attributes track input data and metadata for a request to an LLM. Each attribute represents a concept that is common to most LLMs. - + | Attribute | Type | Description | Examples | Requirement Level | |---|---|---|---|---| -| `llm.vendor` | string | The name of the LLM foundation model vendor, if applicable. If not using a vendor-supplied model, this field is left blank. | `openai` | Recommended | -| `llm.request.model` | string | The name of the LLM a request is being made to. If the LLM is supplied by a vendor, then the value must be the exact name of the model requested. If the LLM is a fine-tuned custom model, the value SHOULD have a more specific name than the base model that's been fine-tuned. | `gpt-4` | Required | -| `llm.request.max_tokens` | int | The maximum number of tokens the LLM generates for a request. | `100` | Recommended | -| `llm.temperature` | float | The temperature setting for the LLM request. | `0.0` | Recommended | -| `llm.top_p` | float | The top_p sampling setting for the LLM request. | `1.0` | Recommended | -| `llm.stream` | bool | Whether the LLM responds with a stream. | `false` | Recommended | -| `llm.stop_sequences` | array | Array of strings the LLM uses as a stop sequence. | `["stop1"]` | Recommended | - -`llm.model` 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 | -|---|---| -| `gpt-4` | GPT-4 | -| `gpt-4-32k` | GPT-4 with 32k context window | -| `gpt-3.5-turbo` | GPT-3.5-turbo | -| `gpt-3.5-turbo-16k` | GPT-3.5-turbo with 16k context window| -| `claude-instant-1` | Claude Instant (latest version) | -| `claude-2` | Claude 2 (latest version) | -| `other-llm` | Any LLM not listed in this table. Use for any fine-tuned version of a model. | +| [`llm.request.is_stream`](../attributes-registry/llm.md) | boolean | Whether the LLM responds with a stream. | `False` | Recommended | +| [`llm.request.max_tokens`](../attributes-registry/llm.md) | int | The maximum number of tokens the LLM generates for a request. | `100` | Recommended | +| [`llm.request.model`](../attributes-registry/llm.md) | string | The name of the LLM a request is being made to. [1] | `gpt-4` | Required | +| [`llm.request.stop_sequences`](../attributes-registry/llm.md) | string | Array of strings the LLM uses as a stop sequence. | `stop1` | Recommended | +| [`llm.request.temperature`](../attributes-registry/llm.md) | double | The temperature setting for the LLM request. | `0.0` | Recommended | +| [`llm.request.top_p`](../attributes-registry/llm.md) | double | The top_p sampling setting for the LLM request. | `1.0` | Recommended | +| [`llm.response.finish_reason`](../attributes-registry/llm.md) | string | The reason the model stopped generating tokens. | `stop` | Recommended | +| [`llm.response.id`](../attributes-registry/llm.md) | string[] | The unique identifier for the completion. | `[chatcmpl-123]` | Recommended | +| [`llm.response.model`](../attributes-registry/llm.md) | string | The name of the LLM a response is being made to. [2] | `gpt-4-0613` | Required | +| [`llm.system`](../attributes-registry/llm.md) | string | The name of the LLM foundation model vendor, if applicable. [3] | `openai` | Recommended | +| [`llm.usage.completion_tokens`](../attributes-registry/llm.md) | int | The number of tokens used in the LLM response (completion). | `180` | Recommended | +| [`llm.usage.prompt_tokens`](../attributes-registry/llm.md) | int | The number of tokens used in the LLM prompt. | `100` | Recommended | +| [`llm.usage.total_tokens`](../attributes-registry/llm.md) | int | The total number of tokens used in the LLM prompt and response. | `280` | Recommended | + +**[1]:** The name of the LLM a request is being made to. If the LLM is supplied by a vendor, then the value must be the exact name of the model requested. If the LLM 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 name of the LLM a response is being made to. If the LLM is supplied by a vendor, then the value must be the exact name of the model actually used. If the LLM is a fine-tuned custom model, the value should have a more specific name than the base model that's been fine-tuned. + +**[3]:** The name of the LLM foundation model vendor, if applicable. If not using a vendor-supplied model, this field is left blank. -## LLM Response attributes +## Events + +In the lifetime of an LLM span, an event for prompts sent and completions received MAY be created, depending on the configuration of the instrumentation. -These attributes track output data and metadata for a response from an LLM. Each attribute represents a concept that is common to most LLMs. + +The event name MUST be `llm.content.prompt`. - | Attribute | Type | Description | Examples | Requirement Level | |---|---|---|---|---| -| `llm.response.id` | string | The unique identifier for the completion. | `chatcmpl-123` | Recommended | -| `llm.response.model` | string | The name of the LLM a response is being made to. If the LLM is supplied by a vendor, then the value must be the exact name of the model actually used. If the LLM is a fine-tuned custom model, the value SHOULD have a more specific name than the base model that's been fine-tuned. | `gpt-4-0613` | Required | -| `llm.response.finish_reason` | string | The reason the model stopped generating tokens | `stop` | Recommended | -| `llm.usage.prompt_tokens` | int | The number of tokens used in the LLM prompt. | `100` | Recommended | -| `llm.usage.completion_tokens` | int | The number of tokens used in the LLM response (completion). | `180` | Recommended | -| `llm.usage.total_tokens` | int | The total number of tokens used in the LLM prompt and response. | `280` | Recommended | - -`llm.response.finish_reason` MUST be one of the following: - -| Value | Description | -|---|---| -| `stop` | If the model hit a natural stop point or a provided stop sequence. | -| `max_tokens` | If the maximum number of tokens specified in the request was reached. | -| `tool_call` | If a function / tool call was made by the model (for models that support such functionality). | - +| [`llm.prompt`](../attributes-registry/llm.md) | string | The full prompt string sent to an LLM in a request. [1] | `\\n\\nHuman:You are an AI assistant that tells jokes. Can you tell me a joke about OpenTelemetry?\\n\\nAssistant:` | Recommended | -## Events +**[1]:** The full prompt string sent to an LLM in a request. If the LLM accepts a more complex input like a JSON object, this field is blank, and the response is instead captured in an event determined by the specific LLM technology semantic convention. + -In the lifetime of an LLM span, an event for prompts sent and completions received MAY be created, depending on the configuration of the instrumentation. + +The event name MUST be `llm.content.completion`. - | Attribute | Type | Description | Examples | Requirement Level | -| `llm.prompt` | string | The full prompt string sent to an LLM in a request. If the LLM accepts a more complex input like a JSON object made up of several pieces (such as OpenAI's different message types), this field is blank, and the response is instead captured in an event determined by the specific LLM technology semantic convention. | `\n\nHuman:You are an AI assistant that tells jokes. Can you tell me a joke about OpenTelemetry?\n\nAssistant:` | Recommended | - +|---|---|---|---|---| +| [`llm.completion`](../attributes-registry/llm.md) | string | The full response string from an LLM in a response. [1] | `Why did the developer stop using OpenTelemetry? Because they couldnt trace their steps!` | Recommended | - -| Attribute | Type | Description | Examples | Requirement Level | -| `llm.completion` | string | The full response string from an LLM. If the LLM responds with a more complex output like a JSON object made up of several pieces (such as OpenAI's message choices), this field is the content of the response. If the LLM produces multiple responses, then this field is left blank, and each response is instead captured in an event determined by the specific LLM technology semantic convention.| `Why did the developer stop using OpenTelemetry? Because they couldn't trace their steps!` | Recommended | +**[1]:** The full response string from an LLM. If the LLM responds with a more complex output like a JSON object made up of several pieces (such as OpenAI's message choices), this field is the content of the response. If the LLM produces multiple responses, then this field is left blank, and each response is instead captured in an event determined by the specific LLM technology semantic convention. [DocumentStatus]: https://github.com/open-telemetry/opentelemetry-specification/tree/v1.22.0/specification/document-status.md diff --git a/docs/ai/openai-metrics.md b/docs/ai/openai-metrics.md index 656148318a..bf39882d9e 100644 --- a/docs/ai/openai-metrics.md +++ b/docs/ai/openai-metrics.md @@ -341,7 +341,7 @@ of `[ 0, 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, | Attribute | Type | Description | Examples | Requirement Level | |---|---|---|---|---| | [`error.type`](../attributes-registry/error.md) | string | Describes a class of error the operation ended with. [1] | `timeout`; `java.net.UnknownHostException`; `server_certificate_invalid`; `500` | Recommended | -| [`llm.response.model`](../attributes-registry/llm.md) | string | The name of the LLM a response is being made to. | `gpt-4-0613` | Required | +| [`llm.response.model`](../attributes-registry/llm.md) | string | The name of the LLM a response is being made to. | `gpt-4-0613` | Conditionally Required: if the operation ended in error | | [`server.address`](../attributes-registry/server.md) | string | Server domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name. [2] | `example.com`; `10.1.2.80`; `/tmp/my.sock` | Required | **[1]:** The `error.type` SHOULD be predictable and SHOULD have low cardinality. diff --git a/docs/ai/openai.md b/docs/ai/openai.md index 8105be0f29..001d751ce5 100644 --- a/docs/ai/openai.md +++ b/docs/ai/openai.md @@ -24,40 +24,30 @@ to maintain consistency and clarity in telemetry data. These are the attributes when instrumenting OpenAI LLM requests with the `/chat/completions` endpoint. - + | Attribute | Type | Description | Examples | Requirement Level | |---|---|---|---|---| -| `llm.vendor` | string | The name of the LLM foundation model vendor, if applicable. If not using a vendor-supplied model, this field is left blank. | `openai` | Recommended | -| `llm.request.model` | string | The name of the LLM a request is being made to. If the LLM is supplied by a vendor, then the value must be the exact name of the model requested. If the LLM is a fine-tuned custom model, the value SHOULD have a more specific name than the base model that's been fine-tuned. | `gpt-4` | Required | -| `llm.request.max_tokens` | int | The maximum number of tokens the LLM generates for a request. | `100` | Recommended | -| `llm.temperature` | float | The temperature setting for the LLM request. | `0.0` | Recommended | -| `llm.top_p` | float | The top_p sampling setting for the LLM request. | `1.0` | Recommended | -| `llm.stream` | bool | Whether the LLM responds with a stream. | `false` | Recommended | -| `llm.stop_sequences` | array | Array of strings the LLM uses as a stop sequence. | `["stop1"]` | Recommended | -| `llm.openai.n` | integer | The number of completions to generate. | `1` | Recommended | -| `llm.openai.presence_penalty` | float | If present, the `presence_penalty` used in an OpenAI request. Value is between -2.0 and 2.0. | `-0.5` | Recommended | -| `llm.openai.frequency_penalty` | float | If present, the `frequency_penalty` used in an OpenAI request. Value is between -2.0 and 2.0. | `-0.5` | Recommended | -| `llm.openai.logit_bias` | string | If present, the JSON-encoded string of a `logit_bias` used in an OpenAI request. | `{2435:-100, 640:-100}` | Recommended | -| `llm.openai.user` | string | If present, the `user` used in an OpenAI request. | `bob` | Opt-in | -| `llm.openai.response_format` | string | An object specifying the format that the model must output. Either `text` or `json_object` | `text` | Recommended | -| `llm.openai.seed` | integer | Seed used in request to improve determinism. | `1234` | Recommended | - - -## Response attributes - -Attributes for chat completion responses SHOULD follow these conventions: - - -| Attribute | Type | Description | Examples | Requirement Level | -|---|---|---|---|---| -| `llm.response.id` | string | The unique identifier for the completion. | `chatcmpl-123` | Recommended | -| `llm.response.model` | string | The name of the LLM a response is being made to. If the LLM is supplied by a vendor, then the value must be the exact name of the model actually used. If the LLM is a fine-tuned custom model, the value SHOULD have a more specific name than the base model that's been fine-tuned. | `gpt-4-0613` | Required | -| `llm.response.finish_reason` | string | The reason the model stopped generating tokens | `stop` | Recommended | -| `llm.usage.prompt_tokens` | int | The number of tokens used in the LLM prompt. | `100` | Recommended | -| `llm.usage.completion_tokens` | int | The number of tokens used in the LLM response (completion). | `180` | Recommended | -| `llm.usage.total_tokens` | int | The total number of tokens used in the LLM prompt and response. | `280` | Recommended | -| `llm.openai.created` | int | The UNIX timestamp (in seconds) if when the completion was created. | `1677652288` | Recommended | -| `llm.openai.system_fingerprint` | string | This fingerprint represents the backend configuration that the model runs with. | asdf987123 | Recommended | +| [`llm.request.is_stream`](../attributes-registry/llm.md) | boolean | Whether the LLM responds with a stream. | `False` | Recommended | +| [`llm.request.max_tokens`](../attributes-registry/llm.md) | int | The maximum number of tokens the LLM generates for a request. | `100` | Recommended | +| [`llm.request.model`](../attributes-registry/llm.md) | string | The name of the LLM a request is being made to. [1] | `gpt-4` | Required | +| [`llm.request.openai.logit_bias`](../attributes-registry/llm.md) | string | If present, the JSON-encoded string of a `logit_bias` used in an OpenAI request | `{2435:-100, 640:-100}` | Recommended | +| [`llm.request.openai.presence_penalty`](../attributes-registry/llm.md) | double | If present, the `presence_penalty` used in an OpenAI request. Value is between -2.0 and 2.0. | `-0.5` | Recommended | +| [`llm.request.openai.response_format`](../attributes-registry/llm.md) | string | An object specifying the format that the model must output. Either `text` or `json_object` | `text` | Recommended | +| [`llm.request.openai.seed`](../attributes-registry/llm.md) | int | Seed used in request to improve determinism. | `1234` | Recommended | +| [`llm.request.openai.user`](../attributes-registry/llm.md) | string | If present, the `user` used in an OpenAI request. | `bob` | Recommended | +| [`llm.request.stop_sequences`](../attributes-registry/llm.md) | string | Array of strings the LLM uses as a stop sequence. | `stop1` | Recommended | +| [`llm.request.temperature`](../attributes-registry/llm.md) | double | The temperature setting for the LLM request. | `0.0` | Recommended | +| [`llm.request.top_p`](../attributes-registry/llm.md) | double | The top_p sampling setting for the LLM request. | `1.0` | Recommended | +| [`llm.response.finish_reason`](../attributes-registry/llm.md) | string | The reason the model stopped generating tokens. | `stop` | Recommended | +| [`llm.response.id`](../attributes-registry/llm.md) | string[] | The unique identifier for the completion. | `[chatcmpl-123]` | Recommended | +| [`llm.response.openai.created`](../attributes-registry/llm.md) | int | The UNIX timestamp (in seconds) if when the completion was created. | `1677652288` | Recommended | +| [`llm.response.openai.system_fingerprint`](../attributes-registry/llm.md) | string | This fingerprint represents the backend configuration that the model runs with. | `asdf987123` | Recommended | +| [`llm.system`](../attributes-registry/llm.md) | string | The name of the LLM foundation model vendor, if applicable. | `openai`; `microsoft` | Recommended | +| [`llm.usage.completion_tokens`](../attributes-registry/llm.md) | int | The number of tokens used in the LLM response (completion). | `180` | Recommended | +| [`llm.usage.prompt_tokens`](../attributes-registry/llm.md) | int | The number of tokens used in the LLM prompt. | `100` | Recommended | +| [`llm.usage.total_tokens`](../attributes-registry/llm.md) | int | The total number of tokens used in the LLM prompt and response. | `280` | Recommended | + +**[1]:** The name of the LLM a request is being made to. If the LLM is supplied by a vendor, then the value must be the exact name of the model requested. If the LLM is a fine-tuned custom model, the value should have a more specific name than the base model that's been fine-tuned. ## Request Events @@ -67,27 +57,31 @@ Because OpenAI uses a more complex prompt structure, these events will be used i ### Prompt Events -Prompt event name SHOULD be `llm.openai.prompt`. +Prompt event name SHOULD be `llm.content.openai.prompt`. + + +The event name MUST be `llm.content.openai.prompt`. - | Attribute | Type | Description | Examples | Requirement Level | |---|---|---|---|---| -| `role` | string | The role of the prompt author, can be one of `system`, `user`, `assistant`, or `tool` | `system` | Required | -| `content` | string | The content for a given OpenAI response, denoted by ``. The value for `` starts with 0, where 0 is the first message. | `Why did the developer stop using OpenTelemetry? Because they couldn't trace their steps!` | Required | -| `tool_call_id` | string | If role is `tool` or `function`, then this tool call that this message is responding to. | `get_current_weather` | Conditionally Required: If `role` is `tool`. | +| [`llm.openai.content`](../attributes-registry/llm.md) | string | The content for a given OpenAI response. | `Why did the developer stop using OpenTelemetry? Because they couldn't trace their steps!` | Required | +| [`llm.openai.role`](../attributes-registry/llm.md) | string | The role of the prompt author, can be one of `system`, `user`, `assistant`, or `tool` | `user` | Required | +| [`llm.openai.tool_call.id`](../attributes-registry/llm.md) | string | If role is `tool` or `function`, then this tool call that this message is responding to. | `get_current_weather` | Conditionally Required: Required if the prompt role is `tool`. | ### Tools Events -Tools event name SHOULD be `llm.openai.tool`, specifying potential tools or functions the LLM can use. +Tools event name SHOULD be `llm.content.openai.tool`, specifying potential tools or functions the LLM can use. + + +The event name MUST be `llm.content.openai.tool`. - | Attribute | Type | Description | Examples | Requirement Level | |---|---|---|---|---| -| `type` | string | They type of the tool. Currently, only `function` is supported. | `function` | Required | -| `function.name` | string | The name of the function to be called. | `get_weather` | Required ! -| `function.description` | string | A description of what the function does, used by the model to choose when and how to call the function. | `` | Required | -| `function.parameters` | string | JSON-encoded string of the parameter object for the function. | `{"type": "object", "properties": {}}` | Required | +| [`llm.openai.function.description`](../attributes-registry/llm.md) | string | A description of what the function does, used by the model to choose when and how to call the function. | `Gets the current weather for a location` | Required | +| [`llm.openai.function.name`](../attributes-registry/llm.md) | string | The name of the function to be called. | `get_weather` | Required | +| [`llm.openai.function.parameters`](../attributes-registry/llm.md) | string | JSON-encoded string of the parameter object for the function. | `{"type": "object", "properties": {}}` | Required | +| [`llm.openai.tool.type`](../attributes-registry/llm.md) | string | The type of the tool. Currently, only `function` is supported. | `function` | Required | ### Choice Events @@ -95,20 +89,31 @@ Tools event name SHOULD be `llm.openai.tool`, specifying potential tools or func Recording details about Choices in each response MAY be included as Span Events. -Choice event name SHOULD be `llm.openai.choice`. +Choice event name SHOULD be `llm.content.openai.choice`. + +If there is more than one `choice`, separate events SHOULD be used. -If there is more than one `tool_call`, separate events SHOULD be used. + +The event name MUST be `llm.content.openai.completion.choice`. - -| `type` | string | Either `delta` or `message`. | `message` | Required | +| Attribute | Type | Description | Examples | Requirement Level | |---|---|---|---|---| -| `finish_reason` | string | The reason the OpenAI model stopped generating tokens for this chunk. | `stop` | Recommended | -| `role` | string | The assigned role for a given OpenAI response, denoted by ``. The value for `` starts with 0, where 0 is the first message. | `system` | Required | -| `content` | string | The content for a given OpenAI response, denoted by ``. The value for `` starts with 0, where 0 is the first message. | `Why did the developer stop using OpenTelemetry? Because they couldn't trace their steps!` | Required | -| `tool_call.id` | string | If exists, the ID of the tool call. | `call_BP08xxEhU60txNjnz3z9R4h9` | Required | -| `tool_call.type` | string | Currently only `function` is supported. | `function` | Required | -| `tool_call.function.name` | string | If exists, the name of a function call for a given OpenAI response, denoted by ``. The value for `` starts with 0, where 0 is the first message. | `get_weather_report` | Required | -| `tool_call.function.arguments` | string | If exists, the arguments to call a function call with for a given OpenAI response, denoted by ``. The value for `` starts with 0, where 0 is the first message. | `{"type": "object", "properties": {"some":"data"}}` | Required | +| [`llm.openai.choice.type`](../attributes-registry/llm.md) | string | The type of the choice, either `delta` or `message`. | `message` | Required | +| [`llm.openai.content`](../attributes-registry/llm.md) | string | The content for a given OpenAI response. | `Why did the developer stop using OpenTelemetry? Because they couldn't trace their steps!` | Required | +| [`llm.openai.function.arguments`](../attributes-registry/llm.md) | string | If exists, the arguments to call a function call with for a given OpenAI response, denoted by ``. The value for `` starts with 0, where 0 is the first message. | `{"type": "object", "properties": {"some":"data"}}` | Conditionally Required: [1] | +| [`llm.openai.function.name`](../attributes-registry/llm.md) | string | The name of the function to be called. | `get_weather` | Conditionally Required: [2] | +| [`llm.openai.role`](../attributes-registry/llm.md) | string | The role of the prompt author, can be one of `system`, `user`, `assistant`, or `tool` | `user` | Required | +| [`llm.openai.tool.type`](../attributes-registry/llm.md) | string | The type of the tool. Currently, only `function` is supported. | `function` | Conditionally Required: [3] | +| [`llm.openai.tool_call.id`](../attributes-registry/llm.md) | string | If role is `tool` or `function`, then this tool call that this message is responding to. | `get_current_weather` | Conditionally Required: [4] | +| [`llm.response.finish_reason`](../attributes-registry/llm.md) | string | The reason the model stopped generating tokens. | `stop` | Recommended | + +**[1]:** Required if the choice is the result of a tool call of type `function`. + +**[2]:** Required if the choice is the result of a tool call of type `function`. + +**[3]:** Required if the choice is the result of a tool call. + +**[4]:** Required if the choice is the result of a tool call. [DocumentStatus]: https://github.com/open-telemetry/opentelemetry-specification/tree/v1.22.0/specification/document-status.md diff --git a/docs/attributes-registry/llm.md b/docs/attributes-registry/llm.md index 5dfb91d272..e9a66e9021 100644 --- a/docs/attributes-registry/llm.md +++ b/docs/attributes-registry/llm.md @@ -23,13 +23,13 @@ | Attribute | Type | Description | Examples | |---|---|---|---| +| `llm.request.is_stream` | boolean | Whether the LLM responds with a stream. | `False` | | `llm.request.max_tokens` | int | The maximum number of tokens the LLM generates for a request. | `100` | | `llm.request.model` | string | The name of the LLM a request is being made to. | `gpt-4` | | `llm.request.stop_sequences` | string | Array of strings the LLM uses as a stop sequence. | `stop1` | -| `llm.request.stream` | boolean | Whether the LLM responds with a stream. | `False` | | `llm.request.temperature` | double | The temperature setting for the LLM request. | `0.0` | | `llm.request.top_p` | double | The top_p sampling setting for the LLM request. | `1.0` | -| `llm.request.vendor` | string | The name of the LLM foundation model vendor, if applicable. | `openai` | +| `llm.system` | string | The name of the LLM foundation model vendor, if applicable. | `openai` | ### Response Attributes @@ -38,7 +38,7 @@ | Attribute | Type | Description | Examples | |---|---|---|---| | `llm.response.finish_reason` | string | The reason the model stopped generating tokens. | `stop` | -| `llm.response.id` | string | The unique identifier for the completion. | `chatcmpl-123` | +| `llm.response.id` | string[] | The unique identifier for the completion. | `[chatcmpl-123]` | | `llm.response.model` | string | The name of the LLM a response is being made to. | `gpt-4-0613` | | `llm.usage.completion_tokens` | int | The number of tokens used in the LLM response (completion). | `180` | | `llm.usage.prompt_tokens` | int | The number of tokens used in the LLM prompt. | `100` |