genaiconv
v1.47.0
Documentation
pkg.go.dev ↗Package genaiconv provides types and functionality for OpenTelemetry semantic conventions in the "gen_ai" namespace.
Types
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.
NewClientOperationDuration
func NewClientOperationDuration( m metric.Meter, opt ...metric.Float64HistogramOption, ) (ClientOperationDuration, error)
NewClientOperationDuration returns a new ClientOperationDuration instrument.
ClientOperationDuration.AttrErrorType
func (ClientOperationDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue
AttrErrorType returns an optional attribute for the "error.type" semantic convention. It represents the describes a class of error the operation ended with.
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.
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.
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.
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.
ClientOperationDuration.Description
func (ClientOperationDuration) Description() string
Description returns the semantic convention description of the instrument
ClientOperationDuration.Inst
func (m ClientOperationDuration) Inst() metric.Float64Histogram
Inst returns the underlying metric instrument.
ClientOperationDuration.Name
func (ClientOperationDuration) Name() string
Name returns the semantic convention name of the instrument.
ClientOperationDuration.Record
func (m ClientOperationDuration) Record( ctx context.Context, val float64, operationName OperationNameAttr, system SystemAttr, attrs ...attribute.KeyValue, )
Record records val to the current distribution.
The operationName is the the name of the operation being performed.
The system is the the Generative AI product as identified by the client or server instrumentation.
All additional attrs passed are included in the recorded value.
ClientOperationDuration.Unit
func (ClientOperationDuration) Unit() string
Unit returns the semantic convention unit of the instrument
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 measures number of input and output tokens used.
NewClientTokenUsage
func NewClientTokenUsage( m metric.Meter, opt ...metric.Int64HistogramOption, ) (ClientTokenUsage, error)
NewClientTokenUsage returns a new ClientTokenUsage instrument.
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.
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.
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.
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.
ClientTokenUsage.Description
func (ClientTokenUsage) Description() string
Description returns the semantic convention description of the instrument
ClientTokenUsage.Inst
func (m ClientTokenUsage) Inst() metric.Int64Histogram
Inst returns the underlying metric instrument.
ClientTokenUsage.Name
func (ClientTokenUsage) Name() string
Name returns the semantic convention name of the instrument.
ClientTokenUsage.Record
func (m ClientTokenUsage) Record( ctx context.Context, val int64, operationName OperationNameAttr, system SystemAttr, tokenType TokenTypeAttr, attrs ...attribute.KeyValue, )
Record records val to the current distribution.
The operationName is the the name of the operation being performed.
The system is the the Generative AI product 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.
ClientTokenUsage.Unit
func (ClientTokenUsage) Unit() string
Unit returns the semantic convention unit of the instrument
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.
ErrorTypeOther
var ErrorTypeOther ErrorTypeAttr = "_OTHER"
ErrorTypeOther is a fallback error value to be used when the instrumentation doesn't define a custom value.
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.
OperationNameChat (7 declarations)
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" )
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.
NewServerRequestDuration
func NewServerRequestDuration( m metric.Meter, opt ...metric.Float64HistogramOption, ) (ServerRequestDuration, error)
NewServerRequestDuration returns a new ServerRequestDuration instrument.
ServerRequestDuration.AttrErrorType
func (ServerRequestDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue
AttrErrorType returns an optional attribute for the "error.type" semantic convention. It represents the describes a class of error the operation ended with.
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.
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.
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.
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.
ServerRequestDuration.Description
func (ServerRequestDuration) Description() string
Description returns the semantic convention description of the instrument
ServerRequestDuration.Inst
func (m ServerRequestDuration) Inst() metric.Float64Histogram
Inst returns the underlying metric instrument.
ServerRequestDuration.Name
func (ServerRequestDuration) Name() string
Name returns the semantic convention name of the instrument.
ServerRequestDuration.Record
func (m ServerRequestDuration) Record( ctx context.Context, val float64, operationName OperationNameAttr, system SystemAttr, attrs ...attribute.KeyValue, )
Record records val to the current distribution.
The operationName is the the name of the operation being performed.
The system is the the Generative AI product as identified by the client or server instrumentation.
All additional attrs passed are included in the recorded value.
ServerRequestDuration.Unit
func (ServerRequestDuration) Unit() string
Unit returns the semantic convention unit of the instrument
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.
NewServerTimePerOutputToken
func NewServerTimePerOutputToken( m metric.Meter, opt ...metric.Float64HistogramOption, ) (ServerTimePerOutputToken, error)
NewServerTimePerOutputToken returns a new ServerTimePerOutputToken instrument.
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.
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.
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.
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.
ServerTimePerOutputToken.Description
func (ServerTimePerOutputToken) Description() string
Description returns the semantic convention description of the instrument
ServerTimePerOutputToken.Inst
func (m ServerTimePerOutputToken) Inst() metric.Float64Histogram
Inst returns the underlying metric instrument.
ServerTimePerOutputToken.Name
func (ServerTimePerOutputToken) Name() string
Name returns the semantic convention name of the instrument.
ServerTimePerOutputToken.Record
func (m ServerTimePerOutputToken) Record( ctx context.Context, val float64, operationName OperationNameAttr, system SystemAttr, attrs ...attribute.KeyValue, )
Record records val to the current distribution.
The operationName is the the name of the operation being performed.
The system is the the Generative AI product as identified by the client or server instrumentation.
All additional attrs passed are included in the recorded value.
ServerTimePerOutputToken.Unit
func (ServerTimePerOutputToken) Unit() string
Unit returns the semantic convention unit of the instrument
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.
NewServerTimeToFirstToken
func NewServerTimeToFirstToken( m metric.Meter, opt ...metric.Float64HistogramOption, ) (ServerTimeToFirstToken, error)
NewServerTimeToFirstToken returns a new ServerTimeToFirstToken instrument.
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.
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.
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.
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.
ServerTimeToFirstToken.Description
func (ServerTimeToFirstToken) Description() string
Description returns the semantic convention description of the instrument
ServerTimeToFirstToken.Inst
func (m ServerTimeToFirstToken) Inst() metric.Float64Histogram
Inst returns the underlying metric instrument.
ServerTimeToFirstToken.Name
func (ServerTimeToFirstToken) Name() string
Name returns the semantic convention name of the instrument.
ServerTimeToFirstToken.Record
func (m ServerTimeToFirstToken) Record( ctx context.Context, val float64, operationName OperationNameAttr, system SystemAttr, attrs ...attribute.KeyValue, )
Record records val to the current distribution.
The operationName is the the name of the operation being performed.
The system is the the Generative AI product as identified by the client or server instrumentation.
All additional attrs passed are included in the recorded value.
ServerTimeToFirstToken.Unit
func (ServerTimeToFirstToken) Unit() string
Unit returns the semantic convention unit of the instrument
SystemAttr
type SystemAttr string
SystemAttr is an attribute conforming to the gen_ai.system semantic conventions. It represents the Generative AI product as identified by the client or server instrumentation.
SystemOpenAI (15 declarations)
var ( // SystemOpenAI is the openAI. SystemOpenAI SystemAttr = "openai" // SystemGCPGenAI is the any Google generative AI endpoint. SystemGCPGenAI SystemAttr = "gcp.gen_ai" // SystemGCPVertexAI is the vertex AI. SystemGCPVertexAI SystemAttr = "gcp.vertex_ai" // SystemGCPGemini is the gemini. SystemGCPGemini SystemAttr = "gcp.gemini" // SystemAnthropic is the anthropic. SystemAnthropic SystemAttr = "anthropic" // SystemCohere is the cohere. SystemCohere SystemAttr = "cohere" // SystemAzAIInference is the azure AI Inference. SystemAzAIInference SystemAttr = "az.ai.inference" // SystemAzAIOpenAI is the azure OpenAI. SystemAzAIOpenAI SystemAttr = "az.ai.openai" // SystemIBMWatsonxAI is the IBM Watsonx AI. SystemIBMWatsonxAI SystemAttr = "ibm.watsonx.ai" // SystemAWSBedrock is the AWS Bedrock. SystemAWSBedrock SystemAttr = "aws.bedrock" // SystemPerplexity is the perplexity. SystemPerplexity SystemAttr = "perplexity" // SystemXai is the xAI. SystemXai SystemAttr = "xai" // SystemDeepseek is the deepSeek. SystemDeepseek SystemAttr = "deepseek" // SystemGroq is the groq. SystemGroq SystemAttr = "groq" // SystemMistralAI is the mistral AI. SystemMistralAI SystemAttr = "mistral_ai" )
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.
TokenTypeInput (2 declarations)
var ( // TokenTypeInput is the input tokens (prompt, input, etc.). TokenTypeInput TokenTypeAttr = "input" // TokenTypeOutput is the output tokens (completion, response, etc.). TokenTypeOutput TokenTypeAttr = "output" )