Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
4 changes: 4 additions & 0 deletions .chloggen/gcp_genai_dynamic_req_attr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
change_type: enhancement
component: [gcp, gen-ai]
Comment thread
gyliu513 marked this conversation as resolved.
note: Define dynamic request attributes for Google generative AI systems.
issues: [2053]
13 changes: 13 additions & 0 deletions docs/attributes-registry/gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [GCP Client Attributes](#gcp-client-attributes)
- [GCP - Google Cloud Run Attributes](#gcp---google-cloud-run-attributes)
- [GCP - Google Compute Engine (GCE) Attributes](#gcp---google-compute-engine-gce-attributes)
- [Generative AI Attributes](#generative-ai-attributes)

## GCP - AppHub Attributes

Expand Down Expand Up @@ -103,3 +104,15 @@ This document defines attributes for Google Compute Engine (GCE).
|---|---|---|---|---|
| <a id="gcp-gce-instance-hostname" href="#gcp-gce-instance-hostname">`gcp.gce.instance.hostname`</a> | string | The hostname of a GCE instance. This is the full value of the default or [custom hostname](https://cloud.google.com/compute/docs/instances/custom-hostname-vm). | `my-host1234.example.com`; `sample-vm.us-west1-b.c.my-project.internal` | ![Development](https://img.shields.io/badge/-development-blue) |
| <a id="gcp-gce-instance-name" href="#gcp-gce-instance-name">`gcp.gce.instance.name`</a> | string | The instance name of a GCE instance. This is the value provided by `host.name`, the visible name of the instance in the Cloud Console UI, and the prefix for the default hostname of the instance as defined by the [default internal DNS name](https://cloud.google.com/compute/docs/internal-dns#instance-fully-qualified-domain-names). | `instance-1`; `my-vm-name` | ![Development](https://img.shields.io/badge/-development-blue) |

## Generative AI Attributes

This documents defines attributes for Google generative AI systems.

| Attribute | Type | Description | Examples | Stability |
|---|---|---|---|---|
| <a id="gcp-gen-ai-request" href="#gcp-gen-ai-request">`gcp.gen_ai.request.<key>`</a> | string[] | Request configuration options named in a Google-specific manner. [6] | | ![Development](https://img.shields.io/badge/-development-blue) |

**[6] `gcp.gen_ai.request`:** Key names are derived from the data structures in the Google Gen AI SDK ("google.genai.types.*" in https://github.com/googleapis/python-genai).
Key names are dependent on the particular operation in question. Each operation has its corresponding "*Config" data structure; for example, the "generate_content" operation has "GenerateContentConfig", while "generate_images" has a corresponding "GenerateImagesConfig".
Key names correspond to a flattened version of the config data structure. For example {"foo": {"bar": {"baz": 5}}} results in a key called "gcp.gen_ai.request.foo.bar.baz" with value 5.
1 change: 1 addition & 0 deletions docs/gen-ai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ Technology specific semantic conventions are defined for the following GenAI sys

* [Azure AI Inference](./azure-ai-inference.md): Semantic Conventions for Azure AI Inference.
* [OpenAI](./openai.md): Semantic Conventions for OpenAI.
* [Google Generative AI](./gcp.md): Semantic Conventions for Gemini and Vertex AI.

[DocumentStatus]: https://opentelemetry.io/docs/specs/otel/document-status
128 changes: 128 additions & 0 deletions docs/gen-ai/gcp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<!--- Hugo front matter used to generate the website version of this page:
linkTitle: Google Generative AI Semantic Conventions
--->

# Semantic conventions for Google Generative AI operations

**Status**: [Development][DocumentStatus]

The Semantic Conventions for [Gemini](https://ai.google.dev/gemini-api/docs) and [Vertex AI](https://cloud.google.com/vertex-ai) extend and override the [GenAI Semantic Conventions](README.md).

## Spans

<!-- semconv span.gen_ai.gcp.client -->
<!-- NOTE: THIS TEXT IS AUTOGENERATED. DO NOT EDIT BY HAND. -->
<!-- see templates/registry/markdown/snippet.md.j2 -->
<!-- prettier-ignore-start -->
<!-- markdownlint-capture -->
<!-- markdownlint-disable -->

**Status:** ![Development](https://img.shields.io/badge/-development-blue)

Semantic Conventions for model inference spans when calling Google systems.

`gen_ai.system` MUST be set to `"gcp.gen_ai"`, `"gcp.vertex_ai"`, or `"gcp.gemini"`.

**Span kind** SHOULD be `CLIENT`.

**Span status** SHOULD follow the [Recording Errors](/docs/general/recording-errors.md) document.

| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
|---|---|---|---|---|---|
| [`gen_ai.operation.name`](/docs/attributes-registry/gen-ai.md) | string | The name of the operation being performed. [1] | `chat`; `generate_content`; `text_completion` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`error.type`](/docs/attributes-registry/error.md) | 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](https://img.shields.io/badge/-stable-lightgreen) |
| [`gcp.client.service`](/docs/attributes-registry/gcp.md) | string | Identifies the Google Cloud service for which the official client library is intended. [3] | `appengine`; `run`; `firestore`; `alloydb`; `spanner` | `Conditionally Required` If available | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.output.type`](/docs/attributes-registry/gen-ai.md) | string | Represents the content type requested by the client. [4] | `text`; `json`; `image` | `Conditionally Required` [5] | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.request.choice.count`](/docs/attributes-registry/gen-ai.md) | int | The target number of candidate completions to return. | `3` | `Conditionally Required` if available, in the request, and !=1 | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.request.model`](/docs/attributes-registry/gen-ai.md) | string | The name of the GenAI model a request is being made to. [6] | `gpt-4` | `Conditionally Required` If available. | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.request.seed`](/docs/attributes-registry/gen-ai.md) | int | Requests with same seed value more likely to return same result. | `100` | `Conditionally Required` if applicable and if the request includes a seed | ![Development](https://img.shields.io/badge/-development-blue) |
| [`server.port`](/docs/attributes-registry/server.md) | int | GenAI server port. [7] | `80`; `8080`; `443` | `Conditionally Required` If `server.address` is set. | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`gen_ai.request.encoding_formats`](/docs/attributes-registry/gen-ai.md) | string[] | The encoding formats requested in an embeddings operation, if specified. [8] | `["base64"]`; `["float", "binary"]` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.request.frequency_penalty`](/docs/attributes-registry/gen-ai.md) | double | The frequency penalty setting for the GenAI request. | `0.1` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.request.max_tokens`](/docs/attributes-registry/gen-ai.md) | int | The maximum number of tokens the model generates for a request. | `100` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.request.presence_penalty`](/docs/attributes-registry/gen-ai.md) | double | The presence penalty setting for the GenAI request. | `0.1` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.request.stop_sequences`](/docs/attributes-registry/gen-ai.md) | string[] | List of sequences that the model will use to stop generating further tokens. | `["forest", "lived"]` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.request.temperature`](/docs/attributes-registry/gen-ai.md) | double | The temperature setting for the GenAI request. | `0.0` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.request.top_p`](/docs/attributes-registry/gen-ai.md) | double | The top_p sampling setting for the GenAI request. | `1.0` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.response.finish_reasons`](/docs/attributes-registry/gen-ai.md) | string[] | Array of reasons the model stopped generating tokens, corresponding to each generation received. | `["stop"]`; `["stop", "length"]` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.response.id`](/docs/attributes-registry/gen-ai.md) | string | The unique identifier for the completion. | `chatcmpl-123` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.response.model`](/docs/attributes-registry/gen-ai.md) | string | The name of the model that generated the response. [9] | `gpt-4-0613` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.usage.input_tokens`](/docs/attributes-registry/gen-ai.md) | int | The number of tokens used in the GenAI input (prompt). | `100` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`gen_ai.usage.output_tokens`](/docs/attributes-registry/gen-ai.md) | int | The number of tokens used in the GenAI response (completion). | `180` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`server.address`](/docs/attributes-registry/server.md) | string | GenAI server address. [10] | `example.com`; `10.1.2.80`; `/tmp/my.sock` | `Recommended` | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`gcp.gen_ai.request.<key>`](/docs/attributes-registry/gcp.md) | string[] | Request configuration options named in a Google-specific manner. [11] | | `Opt-In` | ![Development](https://img.shields.io/badge/-development-blue) |

**[1] `gen_ai.operation.name`:** If one of the predefined values applies, but specific system uses a different name it's RECOMMENDED to document it in the semantic conventions for specific GenAI system and use system-specific name in the instrumentation. If a different name is not documented, instrumentation libraries SHOULD use applicable predefined value.

**[2] `error.type`:** 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] `gcp.client.service`:** Intended to be a stable identifier for Google Cloud client libraries that is uniform across implementation languages. The value should be derived from the canonical service domain for the service; for example, 'foo.googleapis.com' should result in a value of 'foo'.

**[4] `gen_ai.output.type`:** This attribute SHOULD be used when the client requests output of a specific type. The model may return zero or more outputs of this type.
This attribute specifies the output modality and not the actual output format. For example, if an image is requested, the actual output could be a URL pointing to an image file.
Additional output format details may be recorded in the future in the `gen_ai.output.{type}.*` attributes.

**[5] `gen_ai.output.type`:** when applicable and if the request includes an output format.

**[6] `gen_ai.request.model`:** 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.

**[7] `server.port`:** 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.

**[8] `gen_ai.request.encoding_formats`:** In some GenAI systems the encoding formats are called embedding types. Also, some GenAI systems only accept a single format per request.

**[9] `gen_ai.response.model`:** 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.

**[10] `server.address`:** 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.

**[11] `gcp.gen_ai.request`:** Key names are derived from the data structures in the Google Gen AI SDK ("google.genai.types.*" in https://github.com/googleapis/python-genai).
Key names are dependent on the particular operation in question. Each operation has its corresponding "*Config" data structure; for example, the "generate_content" operation has "GenerateContentConfig", while "generate_images" has a corresponding "GenerateImagesConfig".
Key names correspond to a flattened version of the config data structure. For example {"foo": {"bar": {"baz": 5}}} results in a key called "gcp.gen_ai.request.foo.bar.baz" with value 5.

---

`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](https://img.shields.io/badge/-stable-lightgreen) |

---

`gen_ai.operation.name` 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 |
|---|---|---|
| `chat` | Chat completion operation such as [OpenAI Chat API](https://platform.openai.com/docs/api-reference/chat) | ![Development](https://img.shields.io/badge/-development-blue) |
| `create_agent` | Create GenAI agent | ![Development](https://img.shields.io/badge/-development-blue) |
| `embeddings` | Embeddings operation such as [OpenAI Create embeddings API](https://platform.openai.com/docs/api-reference/embeddings/create) | ![Development](https://img.shields.io/badge/-development-blue) |
| `execute_tool` | Execute a tool | ![Development](https://img.shields.io/badge/-development-blue) |
| `generate_content` | Multimodal content generation operation such as [Gemini Generate Content](https://ai.google.dev/api/generate-content) | ![Development](https://img.shields.io/badge/-development-blue) |
| `text_completion` | Text completions operation such as [OpenAI Completions API (Legacy)](https://platform.openai.com/docs/api-reference/completions) | ![Development](https://img.shields.io/badge/-development-blue) |

---

`gen_ai.output.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 |
|---|---|---|
| `image` | Image | ![Development](https://img.shields.io/badge/-development-blue) |
| `json` | JSON object with known or unknown schema | ![Development](https://img.shields.io/badge/-development-blue) |
| `speech` | Speech | ![Development](https://img.shields.io/badge/-development-blue) |
| `text` | Plain text | ![Development](https://img.shields.io/badge/-development-blue) |

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- END AUTOGENERATED TEXT -->
<!-- endsemconv -->

## Events

Google generative AI events follow generic [Generative AI events](gen-ai-events.md).

## Metrics

Google generative AI metrics follow generic [Generative AI metrics](gen-ai-metrics.md).

[DocumentStatus]: https://opentelemetry.io/docs/specs/otel/document-status
33 changes: 33 additions & 0 deletions model/gcp/gen-ai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
groups:
- id: attributes.gcp.gen_ai
type: attribute_group
name: gcp.gen_ai
stability: development
brief: >
Attributes that are used for Google generative AI systems
and that are common to multiple Google endpoints (i.e. common
to both the Vertex AI and to the Gemini API endpoints).
attributes:
- ref: gcp.gen_ai.request

- id: attributes.gcp.vertex_ai
type: attribute_group
extends: attributes.gcp.gen_ai
name: gcp.vertex_ai
stability: development
brief: >
Attributes that are used for Vertex AI.
attributes:
- ref: gcp.client.service
note: Should be "aiplatform" for the Vertex AI endpoint.

- id: attributes.gcp.gemini
type: attribute_group
extends: attributes.gcp.gen_ai
name: gcp.gemini
stability: development
brief: >
Attributes that are used for Gemini.
attributes:
- ref: gcp.client.service
note: Should be "generativelanguage" for the Gemini endpoint.
25 changes: 25 additions & 0 deletions model/gcp/registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,28 @@ groups:
brief: >
The hostname of a GCE instance. This is the full value of the default or [custom hostname](https://cloud.google.com/compute/docs/instances/custom-hostname-vm).
examples: ['my-host1234.example.com', 'sample-vm.us-west1-b.c.my-project.internal']

- id: registry.gcp.gen_ai
type: attribute_group
display_name: Generative AI Attributes
brief: >
This documents defines attributes for Google generative AI systems.
stability: development
attributes:
- id: gcp.gen_ai.request
Comment thread
lmolkova marked this conversation as resolved.
Outdated
stability: development
type: template[string[]]
Comment thread
michaelsafyan marked this conversation as resolved.
Outdated
brief: >
Request configuration options named in a Google-specific manner.
Comment thread
michaelsafyan marked this conversation as resolved.
Outdated
note: >
Key names are derived from the data structures in the Google
Gen AI SDK ("google.genai.types.*" in https://github.com/googleapis/python-genai).
Comment thread
michaelsafyan marked this conversation as resolved.
Outdated

Key names are dependent on the particular operation in question.
Each operation has its corresponding "*Config" data structure; for
example, the "generate_content" operation has "GenerateContentConfig",
while "generate_images" has a corresponding "GenerateImagesConfig".

Key names correspond to a flattened version of the config data
structure. For example {"foo": {"bar": {"baz": 5}}} results in
Comment thread
michaelsafyan marked this conversation as resolved.
Outdated
a key called "gcp.gen_ai.request.foo.bar.baz" with value 5.
Comment thread
michaelsafyan marked this conversation as resolved.
Outdated
16 changes: 16 additions & 0 deletions model/gen-ai/spans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@ groups:
requirement_level:
conditionally_required: If not default (443).

- id: span.gen_ai.gcp.client
type: span
extends: trace.gen_ai.client.common_attributes
stability: development
brief: Semantic Conventions for model inference spans when calling Google systems.
span_kind: client
note: |
`gen_ai.system` MUST be set to `"gcp.gen_ai"`, `"gcp.vertex_ai"`, or `"gcp.gemini"`.
attributes:
- ref: gcp.gen_ai.request
requirement_level: opt_in
- ref: gcp.client.service
Comment thread
michaelsafyan marked this conversation as resolved.
requirement_level:
note: Expected to be "aiplatform" (Vertex AI) or "generativelanguage" (Gemini).
conditionally_required: If available

- id: span.gen_ai.create_agent.client
type: span
stability: development
Expand Down