Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLM Semantic Conventions: Initial PR #825

Merged
merged 47 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8fe6a5f
chore: continuing work by cartermp
nirga Jan 12, 2024
a521fc1
Update to use Yaml model files
drobbins-msft Jan 22, 2024
5843c65
chore: fixes in yaml according to reviews
nirga Jan 23, 2024
0203aea
Merge branch 'main' into ai
nirga Jan 23, 2024
0891f91
chore: @lmolkova reviews
nirga Jan 12, 2024
bdc1982
Merge branch 'main' into ai
nirga Jan 28, 2024
d5a9753
Add OpenAI metrics
drewby Jan 28, 2024
0ef1c1b
Fix linting errors
drewby Jan 29, 2024
fd57c6c
Fix yamllint errors
drewby Jan 29, 2024
c80b80c
Regenerate markdown based on yaml model
drewby Jan 29, 2024
fdb3ba4
Merge pull request #2 from drewby/ai
nirga Jan 29, 2024
a844a28
Merge branch 'main' into ai
nirga Jan 30, 2024
e1b1d6a
minimal set of llm semconv
nirga Mar 19, 2024
902ac95
Merge branch 'main' into first-gen-ai
nirga Mar 19, 2024
5c6df3e
fix: prompt/completion format
nirga Mar 19, 2024
28d6100
Merge branch 'main' into first-gen-ai
nirga Mar 20, 2024
bcc3473
fix: lint and CI errors
nirga Mar 20, 2024
b7ddb90
fix: llm -> gen-ai
nirga Mar 20, 2024
7745569
fix: following @lmolkova review
nirga Mar 21, 2024
e8129d0
Merge branch 'main' into first-gen-ai
nirga Mar 22, 2024
42551ce
Update model/registry/gen-ai.yaml
nirga Mar 22, 2024
57aaf77
Update model/registry/gen-ai.yaml
nirga Mar 22, 2024
e49c3db
Update .github/CODEOWNERS
nirga Mar 22, 2024
cef4ca2
Update model/trace/gen-ai.yaml
nirga Mar 22, 2024
3265778
Update model/trace/gen-ai.yaml
nirga Mar 22, 2024
c0fdb9b
Update model/registry/gen-ai.yaml
nirga Mar 22, 2024
9b25c20
Update model/registry/gen-ai.yaml
nirga Mar 22, 2024
fa15a8f
Update model/trace/gen-ai.yaml
nirga Mar 22, 2024
677c86a
Update model/trace/gen-ai.yaml
nirga Mar 22, 2024
61ffd91
Update model/registry/gen-ai.yaml
nirga Mar 22, 2024
ddcd1ce
Merge branch 'main' into first-gen-ai
nirga Mar 22, 2024
7f8f1e8
fix: lint; regeneration
nirga Mar 22, 2024
74426de
Update docs/gen-ai/README.md
nirga Mar 22, 2024
87cbd17
fix: opt-in prompts / completions
nirga Mar 22, 2024
7662655
Update docs/gen-ai/README.md
nirga Mar 22, 2024
94ee6ea
Update docs/attributes-registry/gen-ai.md
nirga Mar 22, 2024
d5d5dab
Update model/registry/gen-ai.yaml
nirga Mar 22, 2024
3672d94
Update docs/gen-ai/README.md
nirga Mar 22, 2024
68ad466
fix: lint
nirga Mar 22, 2024
f1fe748
Apply suggestions from code review
nirga Apr 1, 2024
0c058cb
Merge branch 'main' into first-gen-ai
nirga Apr 1, 2024
17c4d01
chore: regenerated tables
nirga Apr 1, 2024
d2e4bef
chore: top-level README
nirga Apr 1, 2024
4ec72e5
Apply suggestions from code review
nirga Apr 10, 2024
c755d78
Merge branch 'main' into first-gen-ai
nirga Apr 16, 2024
a8ebe22
fix: PR reviews
nirga Apr 16, 2024
4ee7433
Merge branch 'main' into first-gen-ai
nirga Apr 16, 2024
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
20 changes: 20 additions & 0 deletions docs/ai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--- Hugo front matter used to generate the website version of this page:
linkTitle: AI
path_base_for_github_subdir:
from: content/en/docs/specs/semconv/ai/_index.md
to: database/README.md
--->

# Semantic Conventions for AI systems

**Status**: [Experimental][DocumentStatus]

This document defines semantic conventions for the following kind of AI systems:

* LLMs

Semantic conventions for LLM operations are defined for the following signals:

* [LLM Spans](llm-spans.md): Semantic Conventions for LLM requests - *spans*.

[DocumentStatus]: https://github.com/open-telemetry/opentelemetry-specification/tree/v1.26.0/specification/document-status.md
83 changes: 83 additions & 0 deletions docs/ai/llm-spans.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!--- Hugo front matter used to generate the website version of this page:
linkTitle: LLM Calls
--->

# Semantic Conventions for LLM requests

**Status**: [Experimental][DocumentStatus]

<!-- Re-generate TOC with `markdown-toc --no-first-h1 -i` -->

<!-- toc -->

- [Configuration](#configuration)
- [LLM Request attributes](#llm-request-attributes)
- [Events](#events)

<!-- tocstop -->

A request to an LLM is modeled as a span in a trace.

The **span name** SHOULD be set to a low cardinality value representing the request made to an LLM.
It MAY be a name of the API endpoint for the LLM being called.

## Configuration

Instrumentations for LLMs MUST offer the ability to turn off capture of prompts and completions. This is for three primary reasons:

1. Data privacy concerns. End users of LLM applications may input sensitive information or personally identifiable information (PII) that they do not wish to be sent to a telemetry backend.
2. Data size concerns. Although there is no specified limit to sizes, there are practical limitations in programming languages and telemety systems. Some LLMs allow for extremely large context windows that end users may take full advantage of.
3. Performance concerns. Sending large amounts of data to a telemetry backend may cause performance issues for the application.

By default, these configurations SHOULD NOT capture prompts and completions.

## LLM Request attributes

These attributes track input data and metadata for a request to an LLM. Each attribute represents a concept that is common to most LLMs.

<!-- semconv gen_ai.llm.request -->
| Attribute | Type | Description | Examples | Requirement Level |
|---|---|---|---|---|
| [`gen_ai.llm.request.max_tokens`](../attributes-registry/llm.md) | int | The maximum number of tokens the LLM generates for a request. | `100` | Recommended |
| [`gen_ai.llm.request.model`](../attributes-registry/llm.md) | string | The name of the LLM a request is being made to. [1] | `gpt-4` | Required |
| [`gen_ai.llm.request.temperature`](../attributes-registry/llm.md) | double | The temperature setting for the LLM request. | `0.0` | Recommended |
| [`gen_ai.llm.request.top_p`](../attributes-registry/llm.md) | double | The top_p sampling setting for the LLM request. | `1.0` | Recommended |
| [`gen_ai.llm.response.finish_reason`](../attributes-registry/llm.md) | string[] | Array of reasons the model stopped generating tokens, corresponding to each generation received. | `[['stop']]` | Recommended |
| [`gen_ai.llm.response.id`](../attributes-registry/llm.md) | string | The unique identifier for the completion. | `chatcmpl-123` | Recommended |
| [`gen_ai.llm.response.model`](../attributes-registry/llm.md) | string | The name of the LLM a response is being made to. [2] | `gpt-4-0613` | Required |
| [`gen_ai.llm.system`](../attributes-registry/llm.md) | string | The name of the LLM foundation model vendor, if applicable. [3] | `openai` | Recommended |
| [`gen_ai.llm.usage.completion_tokens`](../attributes-registry/llm.md) | int | The number of tokens used in the LLM response (completion). | `180` | Recommended |
| [`gen_ai.llm.usage.prompt_tokens`](../attributes-registry/llm.md) | int | The number of tokens used in the LLM prompt. | `100` | 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.
<!-- endsemconv -->

## 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.

<!-- semconv gen_ai.llm.content.prompt -->
The event name MUST be `gen_ai.llm.content.prompt`.

| Attribute | Type | Description | Examples | Requirement Level |
|---|---|---|---|---|
| [`gen_ai.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 |

**[1]:** The full prompt sent to an LLM in a request, structured as a JSON in OpenAI's format.
<!-- endsemconv -->

<!-- semconv gen_ai.llm.content.completion -->
The event name MUST be `gen_ai.llm.content.completion`.

| Attribute | Type | Description | Examples | Requirement Level |
|---|---|---|---|---|
| [`gen_ai.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 |

**[1]:** The full response from an LLM, structured as a JSON in OpenAI's format.
<!-- endsemconv -->

[DocumentStatus]: https://github.com/open-telemetry/opentelemetry-specification/tree/v1.22.0/specification/document-status.md
52 changes: 52 additions & 0 deletions docs/attributes-registry/llm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!--- Hugo front matter used to generate the website version of this page:
--->

# Large Language Model (LLM)

<!-- toc -->

- [Generic LLM Attributes](#generic-llm-attributes)
* [Request Attributes](#request-attributes)
* [Response Attributes](#response-attributes)
* [Event Attributes](#event-attributes)
- [OpenAI Attributes](#openai-attributes)
* [Request Attributes](#request-attributes-1)
* [Response Attributes](#response-attributes-1)
* [Event Attributes](#event-attributes-1)

<!-- tocstop -->

## Generic LLM Attributes

### Request Attributes

<!-- semconv registry.llm(omit_requirement_level,tag=llm-generic-request) -->
| Attribute | Type | Description | Examples |
|---|---|---|---|
| `gen_ai.llm.request.max_tokens` | int | The maximum number of tokens the LLM generates for a request. | `100` |
| `gen_ai.llm.request.model` | string | The name of the LLM a request is being made to. | `gpt-4` |
| `gen_ai.llm.request.temperature` | double | The temperature setting for the LLM request. | `0.0` |
| `gen_ai.llm.request.top_p` | double | The top_p sampling setting for the LLM request. | `1.0` |
| `gen_ai.llm.system` | string | The name of the LLM foundation model vendor, if applicable. | `openai` |
<!-- endsemconv -->

### Response Attributes

<!-- semconv registry.llm(omit_requirement_level,tag=llm-generic-response) -->
| Attribute | Type | Description | Examples |
|---|---|---|---|
| `gen_ai.llm.response.finish_reason` | string[] | Array of reasons the model stopped generating tokens, corresponding to each generation received. | `[['stop']]` |
| `gen_ai.llm.response.id` | string | The unique identifier for the completion. | `chatcmpl-123` |
| `gen_ai.llm.response.model` | string | The name of the LLM a response is being made to. | `gpt-4-0613` |
| `gen_ai.llm.usage.completion_tokens` | int | The number of tokens used in the LLM response (completion). | `180` |
| `gen_ai.llm.usage.prompt_tokens` | int | The number of tokens used in the LLM prompt. | `100` |
<!-- endsemconv -->

### Event Attributes

<!-- semconv registry.llm(omit_requirement_level,tag=llm-generic-events) -->
| Attribute | Type | Description | Examples |
|---|---|---|---|
| `gen_ai.llm.completion` | string | The full response string from an LLM in a response. | `Why did the developer stop using OpenTelemetry? Because they couldnt trace their steps!` |
| `gen_ai.llm.prompt` | string | The full prompt string sent to an LLM in a request. | `\\n\\nHuman:You are an AI assistant that tells jokes. Can you tell me a joke about OpenTelemetry?\\n\\nAssistant:` |
nirga marked this conversation as resolved.
Show resolved Hide resolved
<!-- endsemconv -->
67 changes: 67 additions & 0 deletions model/registry/llm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
groups:
- id: registry.llm
prefix: gen_ai.llm
type: attribute_group
brief: >
This document defines the attributes used to describe telemetry in the context of LLM (Large Language Models) requests and responses.
attributes:
- id: system
type: string
brief: The name of the LLM foundation model vendor, if applicable.
examples: 'openai'
tag: llm-generic-request
- id: request.model
type: string
brief: The name of the LLM a request is being made to.
examples: 'gpt-4'
tag: llm-generic-request
- id: request.max_tokens
type: int
brief: The maximum number of tokens the LLM generates for a request.
examples: [100]
tag: llm-generic-request
- id: request.temperature
type: double
brief: The temperature setting for the LLM request.
examples: [0.0]
tag: llm-generic-request
- id: request.top_p
type: double
brief: The top_p sampling setting for the LLM request.
examples: [1.0]
tag: llm-generic-request
- id: response.id
type: string
brief: The unique identifier for the completion.
examples: ['chatcmpl-123']
tag: llm-generic-response
- id: response.model
type: string
brief: The name of the LLM a response is being made to.
examples: ['gpt-4-0613']
tag: llm-generic-response
- id: response.finish_reason
type: string[]
brief: Array of reasons the model stopped generating tokens, corresponding to each generation received.
examples: [['stop']]
tag: llm-generic-response
- id: usage.prompt_tokens
type: int
brief: The number of tokens used in the LLM prompt.
examples: [100]
tag: llm-generic-response
- id: usage.completion_tokens
type: int
brief: The number of tokens used in the LLM response (completion).
examples: [180]
tag: llm-generic-response
- id: prompt
type: string
brief: The full prompt string sent to an LLM in a request.
examples: ['\\n\\nHuman:You are an AI assistant that tells jokes. Can you tell me a joke about OpenTelemetry?\\n\\nAssistant:']
tag: llm-generic-events
- id: completion
type: string
brief: The full response string from an LLM in a response.
examples: ['Why did the developer stop using OpenTelemetry? Because they couldnt trace their steps!']
tag: llm-generic-events
63 changes: 63 additions & 0 deletions model/trace/llm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
groups:
- id: gen_ai.llm.request
type: span
brief: >
A request to an LLM is modeled as a span in a trace. The span name should be a low cardinality value representing the request made to an LLM, like the name of the API endpoint being called.
attributes:
- ref: gen_ai.llm.system
requirement_level: recommended
note: >
The name of the LLM foundation model vendor, if applicable. If not using a vendor-supplied model, this field is left blank.
- ref: gen_ai.llm.request.model
requirement_level: required
note: >
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.
- ref: gen_ai.llm.request.max_tokens
requirement_level: recommended
- ref: gen_ai.llm.request.temperature
requirement_level: recommended
- ref: gen_ai.llm.request.top_p
requirement_level: recommended
- ref: gen_ai.llm.response.id
requirement_level: recommended
- ref: gen_ai.llm.response.model
requirement_level: required
note: >
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.
- ref: gen_ai.llm.response.finish_reason
requirement_level: recommended
- ref: gen_ai.llm.usage.prompt_tokens
requirement_level: recommended
- ref: gen_ai.llm.usage.completion_tokens
requirement_level: recommended
events:
- gen_ai.llm.content.prompt
- gen_ai.llm.content.completion

- id: gen_ai.llm.content.prompt
name: gen_ai.llm.content.prompt
type: event
brief: >
In the lifetime of an LLM span, events for prompts sent and completions received
may be created, depending on the configuration of the instrumentation.
attributes:
- ref: gen_ai.llm.prompt
requirement_level: recommended
note: >
The full prompt sent to an LLM in a request, structured as a JSON in OpenAI's format.

- id: gen_ai.llm.content.completion
name: gen_ai.llm.content.completion
type: event
brief: >
In the lifetime of an LLM span, events for prompts sent and completions received
may be created, depending on the configuration of the instrumentation.
attributes:
- ref: gen_ai.llm.completion
requirement_level: recommended
note: >
The full response from an LLM, structured as a JSON in OpenAI's format.
Loading