package genaiconv

import "go.opentelemetry.io/otel/semconv/v1.38.0/genaiconv"

Package genaiconv provides types and functionality for OpenTelemetry semantic conventions in the "gen_ai" namespace.

Index

Types

type ClientOperationDuration

type ClientOperationDuration struct {
	metric.Float64Histogram
}

ClientOperationDuration is an instrument used to record metric values conforming to the "gen_ai.client.operation.duration" semantic conventions. It represents the genAI operation duration.

func NewClientOperationDuration

func NewClientOperationDuration(
	m metric.Meter,
	opt ...metric.Float64HistogramOption,
) (ClientOperationDuration, error)

NewClientOperationDuration returns a new ClientOperationDuration instrument.

func (ClientOperationDuration) AttrErrorType

AttrErrorType returns an optional attribute for the "error.type" semantic convention. It represents the describes a class of error the operation ended with.

func (ClientOperationDuration) AttrRequestModel

func (ClientOperationDuration) AttrRequestModel(val string) attribute.KeyValue

AttrRequestModel returns an optional attribute for the "gen_ai.request.model" semantic convention. It represents the name of the GenAI model a request is being made to.

func (ClientOperationDuration) AttrResponseModel

func (ClientOperationDuration) AttrResponseModel(val string) attribute.KeyValue

AttrResponseModel returns an optional attribute for the "gen_ai.response.model" semantic convention. It represents the name of the model that generated the response.

func (ClientOperationDuration) AttrServerAddress

func (ClientOperationDuration) AttrServerAddress(val string) attribute.KeyValue

AttrServerAddress returns an optional attribute for the "server.address" semantic convention. It represents the genAI server address.

func (ClientOperationDuration) AttrServerPort

func (ClientOperationDuration) AttrServerPort(val int) attribute.KeyValue

AttrServerPort returns an optional attribute for the "server.port" semantic convention. It represents the genAI server port.

func (ClientOperationDuration) Description

func (ClientOperationDuration) Description() string

Description returns the semantic convention description of the instrument

func (ClientOperationDuration) Inst

Inst returns the underlying metric instrument.

func (ClientOperationDuration) Name

Name returns the semantic convention name of the instrument.

func (ClientOperationDuration) Record

func (m ClientOperationDuration) Record(
	ctx context.Context,
	val float64,
	operationName OperationNameAttr,
	providerName ProviderNameAttr,
	attrs ...attribute.KeyValue,
)

Record records val to the current distribution for attrs.

The operationName is the the name of the operation being performed.

The providerName is the the Generative AI provider as identified by the client or server instrumentation.

All additional attrs passed are included in the recorded value.

func (ClientOperationDuration) RecordSet

func (m ClientOperationDuration) RecordSet(ctx context.Context, val float64, set attribute.Set)

RecordSet records val to the current distribution for set.

func (ClientOperationDuration) Unit

Unit returns the semantic convention unit of the instrument

type ClientTokenUsage

type ClientTokenUsage struct {
	metric.Int64Histogram
}

ClientTokenUsage is an instrument used to record metric values conforming to the "gen_ai.client.token.usage" semantic conventions. It represents the number of input and output tokens used.

func NewClientTokenUsage

func NewClientTokenUsage(
	m metric.Meter,
	opt ...metric.Int64HistogramOption,
) (ClientTokenUsage, error)

NewClientTokenUsage returns a new ClientTokenUsage instrument.

func (ClientTokenUsage) AttrRequestModel

func (ClientTokenUsage) AttrRequestModel(val string) attribute.KeyValue

AttrRequestModel returns an optional attribute for the "gen_ai.request.model" semantic convention. It represents the name of the GenAI model a request is being made to.

func (ClientTokenUsage) AttrResponseModel

func (ClientTokenUsage) AttrResponseModel(val string) attribute.KeyValue

AttrResponseModel returns an optional attribute for the "gen_ai.response.model" semantic convention. It represents the name of the model that generated the response.

func (ClientTokenUsage) AttrServerAddress

func (ClientTokenUsage) AttrServerAddress(val string) attribute.KeyValue

AttrServerAddress returns an optional attribute for the "server.address" semantic convention. It represents the genAI server address.

func (ClientTokenUsage) AttrServerPort

func (ClientTokenUsage) AttrServerPort(val int) attribute.KeyValue

AttrServerPort returns an optional attribute for the "server.port" semantic convention. It represents the genAI server port.

func (ClientTokenUsage) Description

func (ClientTokenUsage) Description() string

Description returns the semantic convention description of the instrument

func (ClientTokenUsage) Inst

Inst returns the underlying metric instrument.

func (ClientTokenUsage) Name

func (ClientTokenUsage) Name() string

Name returns the semantic convention name of the instrument.

func (ClientTokenUsage) Record

func (m ClientTokenUsage) Record(
	ctx context.Context,
	val int64,
	operationName OperationNameAttr,
	providerName ProviderNameAttr,
	tokenType TokenTypeAttr,
	attrs ...attribute.KeyValue,
)

Record records val to the current distribution for attrs.

The operationName is the the name of the operation being performed.

The providerName is the the Generative AI provider as identified by the client or server instrumentation.

The tokenType is the the type of token being counted.

All additional attrs passed are included in the recorded value.

func (ClientTokenUsage) RecordSet

func (m ClientTokenUsage) RecordSet(ctx context.Context, val int64, set attribute.Set)

RecordSet records val to the current distribution for set.

func (ClientTokenUsage) Unit

func (ClientTokenUsage) Unit() string

Unit returns the semantic convention unit of the instrument

type ErrorTypeAttr

type ErrorTypeAttr string

ErrorTypeAttr is an attribute conforming to the error.type semantic conventions. It represents the describes a class of error the operation ended with.

var (
	// ErrorTypeOther is a fallback error value to be used when the instrumentation
	// doesn't define a custom value.
	ErrorTypeOther ErrorTypeAttr = "_OTHER"
)

type OperationNameAttr

type OperationNameAttr string

OperationNameAttr is an attribute conforming to the gen_ai.operation.name semantic conventions. It represents the name of the operation being performed.

var (
	// OperationNameChat is the chat completion operation such as [OpenAI Chat API]
	// .
	//
	// [OpenAI Chat API]: https://platform.openai.com/docs/api-reference/chat
	OperationNameChat OperationNameAttr = "chat"
	// OperationNameGenerateContent is the multimodal content generation operation
	// such as [Gemini Generate Content].
	//
	// [Gemini Generate Content]: https://ai.google.dev/api/generate-content
	OperationNameGenerateContent OperationNameAttr = "generate_content"
	// OperationNameTextCompletion is the text completions operation such as
	// [OpenAI Completions API (Legacy)].
	//
	// [OpenAI Completions API (Legacy)]: https://platform.openai.com/docs/api-reference/completions
	OperationNameTextCompletion OperationNameAttr = "text_completion"
	// OperationNameEmbeddings is the embeddings operation such as
	// [OpenAI Create embeddings API].
	//
	// [OpenAI Create embeddings API]: https://platform.openai.com/docs/api-reference/embeddings/create
	OperationNameEmbeddings OperationNameAttr = "embeddings"
	// OperationNameCreateAgent is the create GenAI agent.
	OperationNameCreateAgent OperationNameAttr = "create_agent"
	// OperationNameInvokeAgent is the invoke GenAI agent.
	OperationNameInvokeAgent OperationNameAttr = "invoke_agent"
	// OperationNameExecuteTool is the execute a tool.
	OperationNameExecuteTool OperationNameAttr = "execute_tool"
)

type ProviderNameAttr

type ProviderNameAttr string

ProviderNameAttr is an attribute conforming to the gen_ai.provider.name semantic conventions. It represents the Generative AI provider as identified by the client or server instrumentation.

var (
	// ProviderNameOpenAI is the [OpenAI].
	//
	// [OpenAI]: https://openai.com/
	ProviderNameOpenAI ProviderNameAttr = "openai"
	// ProviderNameGCPGenAI is the any Google generative AI endpoint.
	ProviderNameGCPGenAI ProviderNameAttr = "gcp.gen_ai"
	// ProviderNameGCPVertexAI is the [Vertex AI].
	//
	// [Vertex AI]: https://cloud.google.com/vertex-ai
	ProviderNameGCPVertexAI ProviderNameAttr = "gcp.vertex_ai"
	// ProviderNameGCPGemini is the [Gemini].
	//
	// [Gemini]: https://cloud.google.com/products/gemini
	ProviderNameGCPGemini ProviderNameAttr = "gcp.gemini"
	// ProviderNameAnthropic is the [Anthropic].
	//
	// [Anthropic]: https://www.anthropic.com/
	ProviderNameAnthropic ProviderNameAttr = "anthropic"
	// ProviderNameCohere is the [Cohere].
	//
	// [Cohere]: https://cohere.com/
	ProviderNameCohere ProviderNameAttr = "cohere"
	// ProviderNameAzureAIInference is the azure AI Inference.
	ProviderNameAzureAIInference ProviderNameAttr = "azure.ai.inference"
	// ProviderNameAzureAIOpenAI is the [Azure OpenAI].
	//
	// [Azure OpenAI]: https://azure.microsoft.com/products/ai-services/openai-service/
	ProviderNameAzureAIOpenAI ProviderNameAttr = "azure.ai.openai"
	// ProviderNameIBMWatsonxAI is the [IBM Watsonx AI].
	//
	// [IBM Watsonx AI]: https://www.ibm.com/products/watsonx-ai
	ProviderNameIBMWatsonxAI ProviderNameAttr = "ibm.watsonx.ai"
	// ProviderNameAWSBedrock is the [AWS Bedrock].
	//
	// [AWS Bedrock]: https://aws.amazon.com/bedrock
	ProviderNameAWSBedrock ProviderNameAttr = "aws.bedrock"
	// ProviderNamePerplexity is the [Perplexity].
	//
	// [Perplexity]: https://www.perplexity.ai/
	ProviderNamePerplexity ProviderNameAttr = "perplexity"
	// ProviderNameXAI is the [xAI].
	//
	// [xAI]: https://x.ai/
	ProviderNameXAI ProviderNameAttr = "x_ai"
	// ProviderNameDeepseek is the [DeepSeek].
	//
	// [DeepSeek]: https://www.deepseek.com/
	ProviderNameDeepseek ProviderNameAttr = "deepseek"
	// ProviderNameGroq is the [Groq].
	//
	// [Groq]: https://groq.com/
	ProviderNameGroq ProviderNameAttr = "groq"
	// ProviderNameMistralAI is the [Mistral AI].
	//
	// [Mistral AI]: https://mistral.ai/
	ProviderNameMistralAI ProviderNameAttr = "mistral_ai"
)

type ServerRequestDuration

type ServerRequestDuration struct {
	metric.Float64Histogram
}

ServerRequestDuration is an instrument used to record metric values conforming to the "gen_ai.server.request.duration" semantic conventions. It represents the generative AI server request duration such as time-to-last byte or last output token.

func NewServerRequestDuration

func NewServerRequestDuration(
	m metric.Meter,
	opt ...metric.Float64HistogramOption,
) (ServerRequestDuration, error)

NewServerRequestDuration returns a new ServerRequestDuration instrument.

func (ServerRequestDuration) AttrErrorType

AttrErrorType returns an optional attribute for the "error.type" semantic convention. It represents the describes a class of error the operation ended with.

func (ServerRequestDuration) AttrRequestModel

func (ServerRequestDuration) AttrRequestModel(val string) attribute.KeyValue

AttrRequestModel returns an optional attribute for the "gen_ai.request.model" semantic convention. It represents the name of the GenAI model a request is being made to.

func (ServerRequestDuration) AttrResponseModel

func (ServerRequestDuration) AttrResponseModel(val string) attribute.KeyValue

AttrResponseModel returns an optional attribute for the "gen_ai.response.model" semantic convention. It represents the name of the model that generated the response.

func (ServerRequestDuration) AttrServerAddress

func (ServerRequestDuration) AttrServerAddress(val string) attribute.KeyValue

AttrServerAddress returns an optional attribute for the "server.address" semantic convention. It represents the genAI server address.

func (ServerRequestDuration) AttrServerPort

func (ServerRequestDuration) AttrServerPort(val int) attribute.KeyValue

AttrServerPort returns an optional attribute for the "server.port" semantic convention. It represents the genAI server port.

func (ServerRequestDuration) Description

func (ServerRequestDuration) Description() string

Description returns the semantic convention description of the instrument

func (ServerRequestDuration) Inst

Inst returns the underlying metric instrument.

func (ServerRequestDuration) Name

Name returns the semantic convention name of the instrument.

func (ServerRequestDuration) Record

func (m ServerRequestDuration) Record(
	ctx context.Context,
	val float64,
	operationName OperationNameAttr,
	providerName ProviderNameAttr,
	attrs ...attribute.KeyValue,
)

Record records val to the current distribution for attrs.

The operationName is the the name of the operation being performed.

The providerName is the the Generative AI provider as identified by the client or server instrumentation.

All additional attrs passed are included in the recorded value.

func (ServerRequestDuration) RecordSet

func (m ServerRequestDuration) RecordSet(ctx context.Context, val float64, set attribute.Set)

RecordSet records val to the current distribution for set.

func (ServerRequestDuration) Unit

Unit returns the semantic convention unit of the instrument

type ServerTimePerOutputToken

type ServerTimePerOutputToken struct {
	metric.Float64Histogram
}

ServerTimePerOutputToken is an instrument used to record metric values conforming to the "gen_ai.server.time_per_output_token" semantic conventions. It represents the time per output token generated after the first token for successful responses.

func NewServerTimePerOutputToken

func NewServerTimePerOutputToken(
	m metric.Meter,
	opt ...metric.Float64HistogramOption,
) (ServerTimePerOutputToken, error)

NewServerTimePerOutputToken returns a new ServerTimePerOutputToken instrument.

func (ServerTimePerOutputToken) AttrRequestModel

func (ServerTimePerOutputToken) AttrRequestModel(val string) attribute.KeyValue

AttrRequestModel returns an optional attribute for the "gen_ai.request.model" semantic convention. It represents the name of the GenAI model a request is being made to.

func (ServerTimePerOutputToken) AttrResponseModel

func (ServerTimePerOutputToken) AttrResponseModel(val string) attribute.KeyValue

AttrResponseModel returns an optional attribute for the "gen_ai.response.model" semantic convention. It represents the name of the model that generated the response.

func (ServerTimePerOutputToken) AttrServerAddress

func (ServerTimePerOutputToken) AttrServerAddress(val string) attribute.KeyValue

AttrServerAddress returns an optional attribute for the "server.address" semantic convention. It represents the genAI server address.

func (ServerTimePerOutputToken) AttrServerPort

func (ServerTimePerOutputToken) AttrServerPort(val int) attribute.KeyValue

AttrServerPort returns an optional attribute for the "server.port" semantic convention. It represents the genAI server port.

func (ServerTimePerOutputToken) Description

func (ServerTimePerOutputToken) Description() string

Description returns the semantic convention description of the instrument

func (ServerTimePerOutputToken) Inst

Inst returns the underlying metric instrument.

func (ServerTimePerOutputToken) Name

Name returns the semantic convention name of the instrument.

func (ServerTimePerOutputToken) Record

func (m ServerTimePerOutputToken) Record(
	ctx context.Context,
	val float64,
	operationName OperationNameAttr,
	providerName ProviderNameAttr,
	attrs ...attribute.KeyValue,
)

Record records val to the current distribution for attrs.

The operationName is the the name of the operation being performed.

The providerName is the the Generative AI provider as identified by the client or server instrumentation.

All additional attrs passed are included in the recorded value.

func (ServerTimePerOutputToken) RecordSet

func (m ServerTimePerOutputToken) RecordSet(ctx context.Context, val float64, set attribute.Set)

RecordSet records val to the current distribution for set.

func (ServerTimePerOutputToken) Unit

Unit returns the semantic convention unit of the instrument

type ServerTimeToFirstToken

type ServerTimeToFirstToken struct {
	metric.Float64Histogram
}

ServerTimeToFirstToken is an instrument used to record metric values conforming to the "gen_ai.server.time_to_first_token" semantic conventions. It represents the time to generate first token for successful responses.

func NewServerTimeToFirstToken

func NewServerTimeToFirstToken(
	m metric.Meter,
	opt ...metric.Float64HistogramOption,
) (ServerTimeToFirstToken, error)

NewServerTimeToFirstToken returns a new ServerTimeToFirstToken instrument.

func (ServerTimeToFirstToken) AttrRequestModel

func (ServerTimeToFirstToken) AttrRequestModel(val string) attribute.KeyValue

AttrRequestModel returns an optional attribute for the "gen_ai.request.model" semantic convention. It represents the name of the GenAI model a request is being made to.

func (ServerTimeToFirstToken) AttrResponseModel

func (ServerTimeToFirstToken) AttrResponseModel(val string) attribute.KeyValue

AttrResponseModel returns an optional attribute for the "gen_ai.response.model" semantic convention. It represents the name of the model that generated the response.

func (ServerTimeToFirstToken) AttrServerAddress

func (ServerTimeToFirstToken) AttrServerAddress(val string) attribute.KeyValue

AttrServerAddress returns an optional attribute for the "server.address" semantic convention. It represents the genAI server address.

func (ServerTimeToFirstToken) AttrServerPort

func (ServerTimeToFirstToken) AttrServerPort(val int) attribute.KeyValue

AttrServerPort returns an optional attribute for the "server.port" semantic convention. It represents the genAI server port.

func (ServerTimeToFirstToken) Description

func (ServerTimeToFirstToken) Description() string

Description returns the semantic convention description of the instrument

func (ServerTimeToFirstToken) Inst

Inst returns the underlying metric instrument.

func (ServerTimeToFirstToken) Name

Name returns the semantic convention name of the instrument.

func (ServerTimeToFirstToken) Record

func (m ServerTimeToFirstToken) Record(
	ctx context.Context,
	val float64,
	operationName OperationNameAttr,
	providerName ProviderNameAttr,
	attrs ...attribute.KeyValue,
)

Record records val to the current distribution for attrs.

The operationName is the the name of the operation being performed.

The providerName is the the Generative AI provider as identified by the client or server instrumentation.

All additional attrs passed are included in the recorded value.

func (ServerTimeToFirstToken) RecordSet

func (m ServerTimeToFirstToken) RecordSet(ctx context.Context, val float64, set attribute.Set)

RecordSet records val to the current distribution for set.

func (ServerTimeToFirstToken) Unit

Unit returns the semantic convention unit of the instrument

type TokenTypeAttr

type TokenTypeAttr string

TokenTypeAttr is an attribute conforming to the gen_ai.token.type semantic conventions. It represents the type of token being counted.

var (
	// TokenTypeInput is the input tokens (prompt, input, etc.).
	TokenTypeInput TokenTypeAttr = "input"
	// TokenTypeOutput is the output tokens (completion, response, etc.).
	TokenTypeOutput TokenTypeAttr = "output"
)

Source Files

metric.go

Version
v1.43.0 (latest)
Published
Apr 3, 2026
Platform
linux/amd64
Imports
5 packages
Last checked
47 minutes ago

Tools for package owners.