semantic-conventions/docs/gen-ai/gen-ai-metrics.md

12 KiB

Semantic Conventions for Generative AI Client Metrics

Status: Experimental

The conventions described in this section are specific to Generative AI client applications.

Disclaimer: These are initial Generative AI client metric instruments and attributes but more may be added in the future.

Generative AI Client Metrics

The following metric instruments describe Generative AI operations. An operation may be a request to an LLM, a function call, or some other distinct action within a larger Generative AI workflow.

Metric: gen_ai.client.token.usage

This metric is recommended when an operation involves the usage of tokens and the count is readily available.

For example, if GenAI system returns usage information in the streaming response, it SHOULD be used. Or if GenAI system returns each token independently, instrumentation SHOULD count number of output tokens and record the result.

If instrumentation cannot efficiently obtain number of input and/or output tokens, it MAY allow users to enable offline token counting. Otherwise it MUST NOT report usage metric.

When systems report both used tokens and billable tokens, instrumentation MUST report billable tokens.

This metric SHOULD be specified with ExplicitBucketBoundaries of [1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, 67108864].

Name Instrument Type Unit (UCUM) Description Stability
gen_ai.client.token.usage Histogram {token} Measures number of input and output tokens used Experimental
Attribute Type Description Examples Requirement Level Stability
gen_ai.operation.name string The name of the operation being performed. chat; completion Required Experimental
gen_ai.request.model string The name of the LLM a request is being made to. gpt-4 Required Experimental
gen_ai.system string The Generative AI product as identified by the client instrumentation. [1] openai Required Experimental
gen_ai.token.type string The type of token being counted. input; output Required Experimental
server.port int Server port number. [2] 80; 8080; 443 Conditionally Required If sever.address is set. Stable
gen_ai.response.model string The name of the LLM a response was generated from. gpt-4-0613 Recommended Experimental
server.address string Server domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name. [3] example.com; 10.1.2.80; /tmp/my.sock Recommended Stable

[1]: 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.

[2]: When observed from the client side, and when communicating through an intermediary, server.port SHOULD represent the server port behind any intermediaries, for example proxies, if it's available.

[3]: When observed from the client side, and when communicating through an intermediary, server.address SHOULD represent the server address behind any intermediaries, for example proxies, if it's available.

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 Experimental
cohere Cohere Experimental
openai OpenAI Experimental
vertex_ai Vertex AI Experimental

gen_ai.token.type 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
input Input tokens (prompt, input, etc.) Experimental
output Output tokens (completion, response, etc.) Experimental

Metric: gen_ai.client.operation.duration

This metric is required.

This metric SHOULD be specified with ExplicitBucketBoundaries of [ 0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12,10.24, 20.48, 40.96, 81.92].

Name Instrument Type Unit (UCUM) Description Stability
gen_ai.client.operation.duration Histogram s GenAI operation duration Experimental
Attribute Type Description Examples Requirement Level Stability
gen_ai.operation.name string The name of the operation being performed. chat; completion Required Experimental
gen_ai.request.model string The name of the LLM a request is being made to. gpt-4 Required Experimental
gen_ai.system string The Generative AI product as identified by the client instrumentation. [1] openai Required Experimental
error.type string Describes a class of error the operation ended with. [2] timeout; java.net.UnknownHostException; server_certificate_invalid; 500 Conditionally Required if the operation ended in an error Stable
server.port int Server port number. [3] 80; 8080; 443 Conditionally Required If sever.address is set. Stable
gen_ai.response.model string The name of the LLM a response was generated from. gpt-4-0613 Recommended Experimental
server.address string Server domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name. [4] example.com; 10.1.2.80; /tmp/my.sock Recommended Stable

[1]: 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.

[2]: The error.type SHOULD match the error code returned by the Generative AI provider or the client library, the canonical name of exception that occurred, or another low-cardinality error identifier. Instrumentations SHOULD document the list of errors they report.

[3]: When observed from the client side, and when communicating through an intermediary, server.port SHOULD represent the server port behind any intermediaries, for example proxies, if it's available.

[4]: When observed from the client side, and when communicating through an intermediary, server.address SHOULD represent the server address behind any intermediaries, for example proxies, if it's available.

error.type 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
_OTHER A fallback error value to be used when the instrumentation doesn't define a custom value. Stable

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 Experimental
cohere Cohere Experimental
openai OpenAI Experimental
vertex_ai Vertex AI Experimental