1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

Revert "Revert "Generate semconv/v1.40.0"" (#7985)

Reverts open-telemetry/opentelemetry-go#7978
This commit is contained in:
Tyler Yahn
2026-03-02 22:32:17 -08:00
committed by GitHub
parent 331043578f
commit 5dee2eb2dc
30 changed files with 59140 additions and 0 deletions
+6
View File
@@ -8,6 +8,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## [Unreleased] ## [Unreleased]
### Added
- Add `go.opentelemetry.io/otel/semconv/v1.40.0` package.
The package contains semantic conventions from the `v1.40.0` version of the OpenTelemetry Semantic Conventions.
See the [migration documentation](./semconv/v1.40.0/MIGRATION.md) for information on how to upgrade from `go.opentelemetry.io/otel/semconv/v1.39.0`. (#7985)
### Removed ### Removed
- Drop support for [Go 1.24]. (#7984) - Drop support for [Go 1.24]. (#7984)
+4
View File
@@ -0,0 +1,4 @@
<!-- Generated. DO NOT MODIFY. -->
# Migration from 1.39.0 to v1.40.0
The `go.opentelemetry.io/otel/semconv/v1.40.0` package should be a drop-in replacement for `go.opentelemetry.io/otel/semconv/1.39.0`.
+3
View File
@@ -0,0 +1,3 @@
# Semconv v1.40.0
[![PkgGoDev](https://pkg.go.dev/badge/go.opentelemetry.io/otel/semconv/v1.40.0)](https://pkg.go.dev/go.opentelemetry.io/otel/semconv/v1.40.0)
File diff suppressed because it is too large Load Diff
+350
View File
@@ -0,0 +1,350 @@
// Code generated from semantic convention specification. DO NOT EDIT.
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Package azureconv provides types and functionality for OpenTelemetry semantic
// conventions in the "azure" namespace.
package azureconv
import (
"context"
"sync"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
)
var (
addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }}
recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }}
)
// CosmosDBConsistencyLevelAttr is an attribute conforming to the
// azure.cosmosdb.consistency.level semantic conventions. It represents the
// account or request [consistency level].
//
// [consistency level]: https://learn.microsoft.com/azure/cosmos-db/consistency-levels
type CosmosDBConsistencyLevelAttr string
var (
// CosmosDBConsistencyLevelStrong is the strong.
CosmosDBConsistencyLevelStrong CosmosDBConsistencyLevelAttr = "Strong"
// CosmosDBConsistencyLevelBoundedStaleness is the bounded Staleness.
CosmosDBConsistencyLevelBoundedStaleness CosmosDBConsistencyLevelAttr = "BoundedStaleness"
// CosmosDBConsistencyLevelSession is the session.
CosmosDBConsistencyLevelSession CosmosDBConsistencyLevelAttr = "Session"
// CosmosDBConsistencyLevelEventual is the eventual.
CosmosDBConsistencyLevelEventual CosmosDBConsistencyLevelAttr = "Eventual"
// CosmosDBConsistencyLevelConsistentPrefix is the consistent Prefix.
CosmosDBConsistencyLevelConsistentPrefix CosmosDBConsistencyLevelAttr = "ConsistentPrefix"
)
// ErrorTypeAttr is an attribute conforming to the error.type semantic
// conventions. It represents the describes a class of error the operation ended
// with.
type ErrorTypeAttr string
var (
// ErrorTypeOther is a fallback error value to be used when the instrumentation
// doesn't define a custom value.
ErrorTypeOther ErrorTypeAttr = "_OTHER"
)
// CosmosDBClientActiveInstanceCount is an instrument used to record metric
// values conforming to the "azure.cosmosdb.client.active_instance.count"
// semantic conventions. It represents the number of active client instances.
type CosmosDBClientActiveInstanceCount struct {
metric.Int64UpDownCounter
}
var newCosmosDBClientActiveInstanceCountOpts = []metric.Int64UpDownCounterOption{
metric.WithDescription("Number of active client instances."),
metric.WithUnit("{instance}"),
}
// NewCosmosDBClientActiveInstanceCount returns a new
// CosmosDBClientActiveInstanceCount instrument.
func NewCosmosDBClientActiveInstanceCount(
m metric.Meter,
opt ...metric.Int64UpDownCounterOption,
) (CosmosDBClientActiveInstanceCount, error) {
// Check if the meter is nil.
if m == nil {
return CosmosDBClientActiveInstanceCount{noop.Int64UpDownCounter{}}, nil
}
if len(opt) == 0 {
opt = newCosmosDBClientActiveInstanceCountOpts
} else {
opt = append(opt, newCosmosDBClientActiveInstanceCountOpts...)
}
i, err := m.Int64UpDownCounter(
"azure.cosmosdb.client.active_instance.count",
opt...,
)
if err != nil {
return CosmosDBClientActiveInstanceCount{noop.Int64UpDownCounter{}}, err
}
return CosmosDBClientActiveInstanceCount{i}, nil
}
// Inst returns the underlying metric instrument.
func (m CosmosDBClientActiveInstanceCount) Inst() metric.Int64UpDownCounter {
return m.Int64UpDownCounter
}
// Name returns the semantic convention name of the instrument.
func (CosmosDBClientActiveInstanceCount) Name() string {
return "azure.cosmosdb.client.active_instance.count"
}
// Unit returns the semantic convention unit of the instrument
func (CosmosDBClientActiveInstanceCount) Unit() string {
return "{instance}"
}
// Description returns the semantic convention description of the instrument
func (CosmosDBClientActiveInstanceCount) Description() string {
return "Number of active client instances."
}
// Add adds incr to the existing count for attrs.
//
// All additional attrs passed are included in the recorded value.
func (m CosmosDBClientActiveInstanceCount) Add(
ctx context.Context,
incr int64,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Int64UpDownCounter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
attrs...,
),
)
m.Int64UpDownCounter.Add(ctx, incr, *o...)
}
// AddSet adds incr to the existing count for set.
func (m CosmosDBClientActiveInstanceCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
if set.Len() == 0 {
m.Int64UpDownCounter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Int64UpDownCounter.Add(ctx, incr, *o...)
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the server port number.
func (CosmosDBClientActiveInstanceCount) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents the name of the database host.
func (CosmosDBClientActiveInstanceCount) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
// CosmosDBClientOperationRequestCharge is an instrument used to record metric
// values conforming to the "azure.cosmosdb.client.operation.request_charge"
// semantic conventions. It represents the [Request units] consumed by the
// operation.
//
// [Request units]: https://learn.microsoft.com/azure/cosmos-db/request-units
type CosmosDBClientOperationRequestCharge struct {
metric.Int64Histogram
}
var newCosmosDBClientOperationRequestChargeOpts = []metric.Int64HistogramOption{
metric.WithDescription("[Request units](https://learn.microsoft.com/azure/cosmos-db/request-units) consumed by the operation."),
metric.WithUnit("{request_unit}"),
}
// NewCosmosDBClientOperationRequestCharge returns a new
// CosmosDBClientOperationRequestCharge instrument.
func NewCosmosDBClientOperationRequestCharge(
m metric.Meter,
opt ...metric.Int64HistogramOption,
) (CosmosDBClientOperationRequestCharge, error) {
// Check if the meter is nil.
if m == nil {
return CosmosDBClientOperationRequestCharge{noop.Int64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newCosmosDBClientOperationRequestChargeOpts
} else {
opt = append(opt, newCosmosDBClientOperationRequestChargeOpts...)
}
i, err := m.Int64Histogram(
"azure.cosmosdb.client.operation.request_charge",
opt...,
)
if err != nil {
return CosmosDBClientOperationRequestCharge{noop.Int64Histogram{}}, err
}
return CosmosDBClientOperationRequestCharge{i}, nil
}
// Inst returns the underlying metric instrument.
func (m CosmosDBClientOperationRequestCharge) Inst() metric.Int64Histogram {
return m.Int64Histogram
}
// Name returns the semantic convention name of the instrument.
func (CosmosDBClientOperationRequestCharge) Name() string {
return "azure.cosmosdb.client.operation.request_charge"
}
// Unit returns the semantic convention unit of the instrument
func (CosmosDBClientOperationRequestCharge) Unit() string {
return "{request_unit}"
}
// Description returns the semantic convention description of the instrument
func (CosmosDBClientOperationRequestCharge) Description() string {
return "[Request units](https://learn.microsoft.com/azure/cosmos-db/request-units) consumed by the operation."
}
// Record records val to the current distribution for attrs.
//
// The dbOperationName is the the name of the operation or command being
// executed.
//
// All additional attrs passed are included in the recorded value.
func (m CosmosDBClientOperationRequestCharge) Record(
ctx context.Context,
val int64,
dbOperationName string,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Int64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("db.operation.name", dbOperationName),
)...,
),
)
m.Int64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
func (m CosmosDBClientOperationRequestCharge) RecordSet(ctx context.Context, val int64, set attribute.Set) {
if set.Len() == 0 {
m.Int64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Int64Histogram.Record(ctx, val, *o...)
}
// AttrCosmosDBConsistencyLevel returns an optional attribute for the
// "azure.cosmosdb.consistency.level" semantic convention. It represents the
// account or request [consistency level].
//
// [consistency level]: https://learn.microsoft.com/azure/cosmos-db/consistency-levels
func (CosmosDBClientOperationRequestCharge) AttrCosmosDBConsistencyLevel(val CosmosDBConsistencyLevelAttr) attribute.KeyValue {
return attribute.String("azure.cosmosdb.consistency.level", string(val))
}
// AttrCosmosDBResponseSubStatusCode returns an optional attribute for the
// "azure.cosmosdb.response.sub_status_code" semantic convention. It represents
// the cosmos DB sub status code.
func (CosmosDBClientOperationRequestCharge) AttrCosmosDBResponseSubStatusCode(val int) attribute.KeyValue {
return attribute.Int("azure.cosmosdb.response.sub_status_code", val)
}
// AttrDBCollectionName returns an optional attribute for the
// "db.collection.name" semantic convention. It represents the cosmos DB
// container name.
func (CosmosDBClientOperationRequestCharge) AttrDBCollectionName(val string) attribute.KeyValue {
return attribute.String("db.collection.name", val)
}
// AttrDBNamespace returns an optional attribute for the "db.namespace" semantic
// convention. It represents the name of the database, fully qualified within the
// server address and port.
func (CosmosDBClientOperationRequestCharge) AttrDBNamespace(val string) attribute.KeyValue {
return attribute.String("db.namespace", val)
}
// AttrDBResponseStatusCode returns an optional attribute for the
// "db.response.status_code" semantic convention. It represents the database
// response status code.
func (CosmosDBClientOperationRequestCharge) AttrDBResponseStatusCode(val string) attribute.KeyValue {
return attribute.String("db.response.status_code", val)
}
// AttrErrorType returns an optional attribute for the "error.type" semantic
// convention. It represents the describes a class of error the operation ended
// with.
func (CosmosDBClientOperationRequestCharge) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the server port number.
func (CosmosDBClientOperationRequestCharge) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
// AttrCosmosDBOperationContactedRegions returns an optional attribute for the
// "azure.cosmosdb.operation.contacted_regions" semantic convention. It
// represents the list of regions contacted during operation in the order that
// they were contacted. If there is more than one region listed, it indicates
// that the operation was performed on multiple regions i.e. cross-regional call.
func (CosmosDBClientOperationRequestCharge) AttrCosmosDBOperationContactedRegions(val ...string) attribute.KeyValue {
return attribute.StringSlice("azure.cosmosdb.operation.contacted_regions", val)
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents the name of the database host.
func (CosmosDBClientOperationRequestCharge) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
+684
View File
@@ -0,0 +1,684 @@
// Code generated from semantic convention specification. DO NOT EDIT.
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Package cicdconv provides types and functionality for OpenTelemetry semantic
// conventions in the "cicd" namespace.
package cicdconv
import (
"context"
"sync"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
)
var (
addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }}
recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }}
)
// PipelineResultAttr is an attribute conforming to the cicd.pipeline.result
// semantic conventions. It represents the result of a pipeline run.
type PipelineResultAttr string
var (
// PipelineResultSuccess is the pipeline run finished successfully.
PipelineResultSuccess PipelineResultAttr = "success"
// PipelineResultFailure is the pipeline run did not finish successfully, eg.
// due to a compile error or a failing test. Such failures are usually detected
// by non-zero exit codes of the tools executed in the pipeline run.
PipelineResultFailure PipelineResultAttr = "failure"
// PipelineResultError is the pipeline run failed due to an error in the CICD
// system, eg. due to the worker being killed.
PipelineResultError PipelineResultAttr = "error"
// PipelineResultTimeout is a timeout caused the pipeline run to be interrupted.
PipelineResultTimeout PipelineResultAttr = "timeout"
// PipelineResultCancellation is the pipeline run was cancelled, eg. by a user
// manually cancelling the pipeline run.
PipelineResultCancellation PipelineResultAttr = "cancellation"
// PipelineResultSkip is the pipeline run was skipped, eg. due to a precondition
// not being met.
PipelineResultSkip PipelineResultAttr = "skip"
)
// PipelineRunStateAttr is an attribute conforming to the cicd.pipeline.run.state
// semantic conventions. It represents the pipeline run goes through these states
// during its lifecycle.
type PipelineRunStateAttr string
var (
// PipelineRunStatePending is the run pending state spans from the event
// triggering the pipeline run until the execution of the run starts (eg. time
// spent in a queue, provisioning agents, creating run resources).
PipelineRunStatePending PipelineRunStateAttr = "pending"
// PipelineRunStateExecuting is the executing state spans the execution of any
// run tasks (eg. build, test).
PipelineRunStateExecuting PipelineRunStateAttr = "executing"
// PipelineRunStateFinalizing is the finalizing state spans from when the run
// has finished executing (eg. cleanup of run resources).
PipelineRunStateFinalizing PipelineRunStateAttr = "finalizing"
)
// WorkerStateAttr is an attribute conforming to the cicd.worker.state semantic
// conventions. It represents the state of a CICD worker / agent.
type WorkerStateAttr string
var (
// WorkerStateAvailable is the worker is not performing work for the CICD
// system. It is available to the CICD system to perform work on (online /
// idle).
WorkerStateAvailable WorkerStateAttr = "available"
// WorkerStateBusy is the worker is performing work for the CICD system.
WorkerStateBusy WorkerStateAttr = "busy"
// WorkerStateOffline is the worker is not available to the CICD system
// (disconnected / down).
WorkerStateOffline WorkerStateAttr = "offline"
)
// ErrorTypeAttr is an attribute conforming to the error.type semantic
// conventions. It represents the describes a class of error the operation ended
// with.
type ErrorTypeAttr string
var (
// ErrorTypeOther is a fallback error value to be used when the instrumentation
// doesn't define a custom value.
ErrorTypeOther ErrorTypeAttr = "_OTHER"
)
// PipelineRunActive is an instrument used to record metric values conforming to
// the "cicd.pipeline.run.active" semantic conventions. It represents the number
// of pipeline runs currently active in the system by state.
type PipelineRunActive struct {
metric.Int64UpDownCounter
}
var newPipelineRunActiveOpts = []metric.Int64UpDownCounterOption{
metric.WithDescription("The number of pipeline runs currently active in the system by state."),
metric.WithUnit("{run}"),
}
// NewPipelineRunActive returns a new PipelineRunActive instrument.
func NewPipelineRunActive(
m metric.Meter,
opt ...metric.Int64UpDownCounterOption,
) (PipelineRunActive, error) {
// Check if the meter is nil.
if m == nil {
return PipelineRunActive{noop.Int64UpDownCounter{}}, nil
}
if len(opt) == 0 {
opt = newPipelineRunActiveOpts
} else {
opt = append(opt, newPipelineRunActiveOpts...)
}
i, err := m.Int64UpDownCounter(
"cicd.pipeline.run.active",
opt...,
)
if err != nil {
return PipelineRunActive{noop.Int64UpDownCounter{}}, err
}
return PipelineRunActive{i}, nil
}
// Inst returns the underlying metric instrument.
func (m PipelineRunActive) Inst() metric.Int64UpDownCounter {
return m.Int64UpDownCounter
}
// Name returns the semantic convention name of the instrument.
func (PipelineRunActive) Name() string {
return "cicd.pipeline.run.active"
}
// Unit returns the semantic convention unit of the instrument
func (PipelineRunActive) Unit() string {
return "{run}"
}
// Description returns the semantic convention description of the instrument
func (PipelineRunActive) Description() string {
return "The number of pipeline runs currently active in the system by state."
}
// Add adds incr to the existing count for attrs.
//
// The pipelineName is the the human readable name of the pipeline within a CI/CD
// system.
//
// The pipelineRunState is the the pipeline run goes through these states during
// its lifecycle.
func (m PipelineRunActive) Add(
ctx context.Context,
incr int64,
pipelineName string,
pipelineRunState PipelineRunStateAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Int64UpDownCounter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("cicd.pipeline.name", pipelineName),
attribute.String("cicd.pipeline.run.state", string(pipelineRunState)),
)...,
),
)
m.Int64UpDownCounter.Add(ctx, incr, *o...)
}
// AddSet adds incr to the existing count for set.
func (m PipelineRunActive) AddSet(ctx context.Context, incr int64, set attribute.Set) {
if set.Len() == 0 {
m.Int64UpDownCounter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Int64UpDownCounter.Add(ctx, incr, *o...)
}
// PipelineRunDuration is an instrument used to record metric values conforming
// to the "cicd.pipeline.run.duration" semantic conventions. It represents the
// duration of a pipeline run grouped by pipeline, state and result.
type PipelineRunDuration struct {
metric.Float64Histogram
}
var newPipelineRunDurationOpts = []metric.Float64HistogramOption{
metric.WithDescription("Duration of a pipeline run grouped by pipeline, state and result."),
metric.WithUnit("s"),
}
// NewPipelineRunDuration returns a new PipelineRunDuration instrument.
func NewPipelineRunDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (PipelineRunDuration, error) {
// Check if the meter is nil.
if m == nil {
return PipelineRunDuration{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newPipelineRunDurationOpts
} else {
opt = append(opt, newPipelineRunDurationOpts...)
}
i, err := m.Float64Histogram(
"cicd.pipeline.run.duration",
opt...,
)
if err != nil {
return PipelineRunDuration{noop.Float64Histogram{}}, err
}
return PipelineRunDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m PipelineRunDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (PipelineRunDuration) Name() string {
return "cicd.pipeline.run.duration"
}
// Unit returns the semantic convention unit of the instrument
func (PipelineRunDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (PipelineRunDuration) Description() string {
return "Duration of a pipeline run grouped by pipeline, state and result."
}
// Record records val to the current distribution for attrs.
//
// The pipelineName is the the human readable name of the pipeline within a CI/CD
// system.
//
// The pipelineRunState is the the pipeline run goes through these states during
// its lifecycle.
//
// All additional attrs passed are included in the recorded value.
func (m PipelineRunDuration) Record(
ctx context.Context,
val float64,
pipelineName string,
pipelineRunState PipelineRunStateAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("cicd.pipeline.name", pipelineName),
attribute.String("cicd.pipeline.run.state", string(pipelineRunState)),
)...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
func (m PipelineRunDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// AttrPipelineResult returns an optional attribute for the
// "cicd.pipeline.result" semantic convention. It represents the result of a
// pipeline run.
func (PipelineRunDuration) AttrPipelineResult(val PipelineResultAttr) attribute.KeyValue {
return attribute.String("cicd.pipeline.result", string(val))
}
// AttrErrorType returns an optional attribute for the "error.type" semantic
// convention. It represents the describes a class of error the operation ended
// with.
func (PipelineRunDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// PipelineRunErrors is an instrument used to record metric values conforming to
// the "cicd.pipeline.run.errors" semantic conventions. It represents the number
// of errors encountered in pipeline runs (eg. compile, test failures).
type PipelineRunErrors struct {
metric.Int64Counter
}
var newPipelineRunErrorsOpts = []metric.Int64CounterOption{
metric.WithDescription("The number of errors encountered in pipeline runs (eg. compile, test failures)."),
metric.WithUnit("{error}"),
}
// NewPipelineRunErrors returns a new PipelineRunErrors instrument.
func NewPipelineRunErrors(
m metric.Meter,
opt ...metric.Int64CounterOption,
) (PipelineRunErrors, error) {
// Check if the meter is nil.
if m == nil {
return PipelineRunErrors{noop.Int64Counter{}}, nil
}
if len(opt) == 0 {
opt = newPipelineRunErrorsOpts
} else {
opt = append(opt, newPipelineRunErrorsOpts...)
}
i, err := m.Int64Counter(
"cicd.pipeline.run.errors",
opt...,
)
if err != nil {
return PipelineRunErrors{noop.Int64Counter{}}, err
}
return PipelineRunErrors{i}, nil
}
// Inst returns the underlying metric instrument.
func (m PipelineRunErrors) Inst() metric.Int64Counter {
return m.Int64Counter
}
// Name returns the semantic convention name of the instrument.
func (PipelineRunErrors) Name() string {
return "cicd.pipeline.run.errors"
}
// Unit returns the semantic convention unit of the instrument
func (PipelineRunErrors) Unit() string {
return "{error}"
}
// Description returns the semantic convention description of the instrument
func (PipelineRunErrors) Description() string {
return "The number of errors encountered in pipeline runs (eg. compile, test failures)."
}
// Add adds incr to the existing count for attrs.
//
// The pipelineName is the the human readable name of the pipeline within a CI/CD
// system.
//
// The errorType is the describes a class of error the operation ended with.
//
// There might be errors in a pipeline run that are non fatal (eg. they are
// suppressed) or in a parallel stage multiple stages could have a fatal error.
// This means that this error count might not be the same as the count of metric
// `cicd.pipeline.run.duration` with run result `failure`.
func (m PipelineRunErrors) Add(
ctx context.Context,
incr int64,
pipelineName string,
errorType ErrorTypeAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Int64Counter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("cicd.pipeline.name", pipelineName),
attribute.String("error.type", string(errorType)),
)...,
),
)
m.Int64Counter.Add(ctx, incr, *o...)
}
// AddSet adds incr to the existing count for set.
//
// There might be errors in a pipeline run that are non fatal (eg. they are
// suppressed) or in a parallel stage multiple stages could have a fatal error.
// This means that this error count might not be the same as the count of metric
// `cicd.pipeline.run.duration` with run result `failure`.
func (m PipelineRunErrors) AddSet(ctx context.Context, incr int64, set attribute.Set) {
if set.Len() == 0 {
m.Int64Counter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Int64Counter.Add(ctx, incr, *o...)
}
// SystemErrors is an instrument used to record metric values conforming to the
// "cicd.system.errors" semantic conventions. It represents the number of errors
// in a component of the CICD system (eg. controller, scheduler, agent).
type SystemErrors struct {
metric.Int64Counter
}
var newSystemErrorsOpts = []metric.Int64CounterOption{
metric.WithDescription("The number of errors in a component of the CICD system (eg. controller, scheduler, agent)."),
metric.WithUnit("{error}"),
}
// NewSystemErrors returns a new SystemErrors instrument.
func NewSystemErrors(
m metric.Meter,
opt ...metric.Int64CounterOption,
) (SystemErrors, error) {
// Check if the meter is nil.
if m == nil {
return SystemErrors{noop.Int64Counter{}}, nil
}
if len(opt) == 0 {
opt = newSystemErrorsOpts
} else {
opt = append(opt, newSystemErrorsOpts...)
}
i, err := m.Int64Counter(
"cicd.system.errors",
opt...,
)
if err != nil {
return SystemErrors{noop.Int64Counter{}}, err
}
return SystemErrors{i}, nil
}
// Inst returns the underlying metric instrument.
func (m SystemErrors) Inst() metric.Int64Counter {
return m.Int64Counter
}
// Name returns the semantic convention name of the instrument.
func (SystemErrors) Name() string {
return "cicd.system.errors"
}
// Unit returns the semantic convention unit of the instrument
func (SystemErrors) Unit() string {
return "{error}"
}
// Description returns the semantic convention description of the instrument
func (SystemErrors) Description() string {
return "The number of errors in a component of the CICD system (eg. controller, scheduler, agent)."
}
// Add adds incr to the existing count for attrs.
//
// The systemComponent is the the name of a component of the CICD system.
//
// The errorType is the describes a class of error the operation ended with.
//
// Errors in pipeline run execution are explicitly excluded. Ie a test failure is
// not counted in this metric.
func (m SystemErrors) Add(
ctx context.Context,
incr int64,
systemComponent string,
errorType ErrorTypeAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Int64Counter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("cicd.system.component", systemComponent),
attribute.String("error.type", string(errorType)),
)...,
),
)
m.Int64Counter.Add(ctx, incr, *o...)
}
// AddSet adds incr to the existing count for set.
//
// Errors in pipeline run execution are explicitly excluded. Ie a test failure is
// not counted in this metric.
func (m SystemErrors) AddSet(ctx context.Context, incr int64, set attribute.Set) {
if set.Len() == 0 {
m.Int64Counter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Int64Counter.Add(ctx, incr, *o...)
}
// WorkerCount is an instrument used to record metric values conforming to the
// "cicd.worker.count" semantic conventions. It represents the number of workers
// on the CICD system by state.
type WorkerCount struct {
metric.Int64UpDownCounter
}
var newWorkerCountOpts = []metric.Int64UpDownCounterOption{
metric.WithDescription("The number of workers on the CICD system by state."),
metric.WithUnit("{count}"),
}
// NewWorkerCount returns a new WorkerCount instrument.
func NewWorkerCount(
m metric.Meter,
opt ...metric.Int64UpDownCounterOption,
) (WorkerCount, error) {
// Check if the meter is nil.
if m == nil {
return WorkerCount{noop.Int64UpDownCounter{}}, nil
}
if len(opt) == 0 {
opt = newWorkerCountOpts
} else {
opt = append(opt, newWorkerCountOpts...)
}
i, err := m.Int64UpDownCounter(
"cicd.worker.count",
opt...,
)
if err != nil {
return WorkerCount{noop.Int64UpDownCounter{}}, err
}
return WorkerCount{i}, nil
}
// Inst returns the underlying metric instrument.
func (m WorkerCount) Inst() metric.Int64UpDownCounter {
return m.Int64UpDownCounter
}
// Name returns the semantic convention name of the instrument.
func (WorkerCount) Name() string {
return "cicd.worker.count"
}
// Unit returns the semantic convention unit of the instrument
func (WorkerCount) Unit() string {
return "{count}"
}
// Description returns the semantic convention description of the instrument
func (WorkerCount) Description() string {
return "The number of workers on the CICD system by state."
}
// Add adds incr to the existing count for attrs.
//
// The workerState is the the state of a CICD worker / agent.
func (m WorkerCount) Add(
ctx context.Context,
incr int64,
workerState WorkerStateAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Int64UpDownCounter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("cicd.worker.state", string(workerState)),
)...,
),
)
m.Int64UpDownCounter.Add(ctx, incr, *o...)
}
// AddSet adds incr to the existing count for set.
func (m WorkerCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
if set.Len() == 0 {
m.Int64UpDownCounter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Int64UpDownCounter.Add(ctx, incr, *o...)
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+148
View File
@@ -0,0 +1,148 @@
// Code generated from semantic convention specification. DO NOT EDIT.
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Package dnsconv provides types and functionality for OpenTelemetry semantic
// conventions in the "dns" namespace.
package dnsconv
import (
"context"
"sync"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
)
var (
addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }}
recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }}
)
// ErrorTypeAttr is an attribute conforming to the error.type semantic
// conventions. It represents the describes the error the DNS lookup failed with.
type ErrorTypeAttr string
var (
// ErrorTypeOther is a fallback error value to be used when the instrumentation
// doesn't define a custom value.
ErrorTypeOther ErrorTypeAttr = "_OTHER"
)
// LookupDuration is an instrument used to record metric values conforming to the
// "dns.lookup.duration" semantic conventions. It represents the measures the
// time taken to perform a DNS lookup.
type LookupDuration struct {
metric.Float64Histogram
}
var newLookupDurationOpts = []metric.Float64HistogramOption{
metric.WithDescription("Measures the time taken to perform a DNS lookup."),
metric.WithUnit("s"),
}
// NewLookupDuration returns a new LookupDuration instrument.
func NewLookupDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (LookupDuration, error) {
// Check if the meter is nil.
if m == nil {
return LookupDuration{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newLookupDurationOpts
} else {
opt = append(opt, newLookupDurationOpts...)
}
i, err := m.Float64Histogram(
"dns.lookup.duration",
opt...,
)
if err != nil {
return LookupDuration{noop.Float64Histogram{}}, err
}
return LookupDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m LookupDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (LookupDuration) Name() string {
return "dns.lookup.duration"
}
// Unit returns the semantic convention unit of the instrument
func (LookupDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (LookupDuration) Description() string {
return "Measures the time taken to perform a DNS lookup."
}
// Record records val to the current distribution for attrs.
//
// The questionName is the the name being queried.
//
// All additional attrs passed are included in the recorded value.
func (m LookupDuration) Record(
ctx context.Context,
val float64,
questionName string,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("dns.question.name", questionName),
)...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
func (m LookupDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// AttrErrorType returns an optional attribute for the "error.type" semantic
// convention. It represents the describes the error the DNS lookup failed with.
func (LookupDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
+9
View File
@@ -0,0 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Package semconv implements OpenTelemetry semantic conventions.
//
// OpenTelemetry semantic conventions are agreed standardized naming
// patterns for OpenTelemetry things. This package represents the v1.40.0
// version of the OpenTelemetry semantic conventions.
package semconv // import "go.opentelemetry.io/otel/semconv/v1.40.0"
+56
View File
@@ -0,0 +1,56 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package semconv // import "go.opentelemetry.io/otel/semconv/v1.40.0"
import (
"reflect"
"go.opentelemetry.io/otel/attribute"
)
// ErrorType returns an [attribute.KeyValue] identifying the error type of err.
//
// If err is nil, the returned attribute has the default value
// [ErrorTypeOther].
//
// If err's type has the method
//
// ErrorType() string
//
// then the returned attribute has the value of err.ErrorType(). Otherwise, the
// returned attribute has a value derived from the concrete type of err.
//
// The key of the returned attribute is [ErrorTypeKey].
func ErrorType(err error) attribute.KeyValue {
if err == nil {
return ErrorTypeOther
}
return ErrorTypeKey.String(errorType(err))
}
func errorType(err error) string {
var s string
if et, ok := err.(interface{ ErrorType() string }); ok {
// Prioritize the ErrorType method if available.
s = et.ErrorType()
}
if s == "" {
// Fallback to reflection if the ErrorType method is not supported or
// returns an empty value.
t := reflect.TypeOf(err)
pkg, name := t.PkgPath(), t.Name()
if pkg != "" && name != "" {
s = pkg + "." + name
} else {
// The type has no package path or name (predeclared, not-defined,
// or alias for a not-defined type).
//
// This is not guaranteed to be unique, but is a best effort.
s = t.String()
}
}
return s
}
+45
View File
@@ -0,0 +1,45 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package semconv // import "go.opentelemetry.io/otel/semconv/v1.40.0"
import (
"errors"
"testing"
)
const pkg = "go.opentelemetry.io/otel/semconv/v1.40.0"
func TestErrorType(t *testing.T) {
check(t, nil, ErrorTypeOther.Value.AsString())
check(t, errors.New("msg"), "*errors.errorString")
check(t, custom("aborted"), "aborted")
check(t, custom(""), pkg+".ErrCustomType") // empty ErrorType, use concrete type.
}
func check(t *testing.T, err error, want string) {
t.Helper()
got := ErrorType(err)
if got.Key != ErrorTypeKey {
t.Errorf("ErrorType(%v) key = %v, want %v", err, got.Key, ErrorTypeKey)
}
if got.Value.AsString() != want {
t.Errorf("ErrorType(%v) value = %v, want %v", err, got.Value.AsString(), want)
}
}
func custom(typ string) error {
return ErrCustomType{Type: typ}
}
type ErrCustomType struct {
Type string
}
func (e ErrCustomType) Error() string {
return "custom: " + e.Type
}
func (e ErrCustomType) ErrorType() string {
return e.Type
}
+9
View File
@@ -0,0 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package semconv // import "go.opentelemetry.io/otel/semconv/v1.40.0"
const (
// ExceptionEventName is the name of the Span event representing an exception.
ExceptionEventName = "exception"
)
File diff suppressed because it is too large Load Diff
+871
View File
@@ -0,0 +1,871 @@
// Code generated from semantic convention specification. DO NOT EDIT.
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Package genaiconv provides types and functionality for OpenTelemetry semantic
// conventions in the "gen_ai" namespace.
package genaiconv
import (
"context"
"sync"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
)
var (
addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }}
recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }}
)
// ErrorTypeAttr is an attribute conforming to the error.type semantic
// conventions. It represents the describes a class of error the operation ended
// with.
type ErrorTypeAttr string
var (
// ErrorTypeOther is a fallback error value to be used when the instrumentation
// doesn't define a custom value.
ErrorTypeOther ErrorTypeAttr = "_OTHER"
)
// OperationNameAttr is an attribute conforming to the gen_ai.operation.name
// semantic conventions. It represents the name of the operation being performed.
type OperationNameAttr string
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"
// OperationNameRetrieval is the retrieval operation such as
// [OpenAI Search Vector Store API].
//
// [OpenAI Search Vector Store API]: https://platform.openai.com/docs/api-reference/vector-stores/search
OperationNameRetrieval OperationNameAttr = "retrieval"
// 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"
)
// 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.
type ProviderNameAttr string
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"
)
// TokenTypeAttr is an attribute conforming to the gen_ai.token.type semantic
// conventions. It represents the type of token being counted.
type TokenTypeAttr string
var (
// TokenTypeInput is the input tokens (prompt, input, etc.).
TokenTypeInput TokenTypeAttr = "input"
// TokenTypeOutput is the output tokens (completion, response, etc.).
TokenTypeOutput TokenTypeAttr = "output"
)
// 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.
type ClientOperationDuration struct {
metric.Float64Histogram
}
var newClientOperationDurationOpts = []metric.Float64HistogramOption{
metric.WithDescription("GenAI operation duration."),
metric.WithUnit("s"),
}
// NewClientOperationDuration returns a new ClientOperationDuration instrument.
func NewClientOperationDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (ClientOperationDuration, error) {
// Check if the meter is nil.
if m == nil {
return ClientOperationDuration{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newClientOperationDurationOpts
} else {
opt = append(opt, newClientOperationDurationOpts...)
}
i, err := m.Float64Histogram(
"gen_ai.client.operation.duration",
opt...,
)
if err != nil {
return ClientOperationDuration{noop.Float64Histogram{}}, err
}
return ClientOperationDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ClientOperationDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ClientOperationDuration) Name() string {
return "gen_ai.client.operation.duration"
}
// Unit returns the semantic convention unit of the instrument
func (ClientOperationDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (ClientOperationDuration) Description() string {
return "GenAI operation duration."
}
// 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 (m ClientOperationDuration) Record(
ctx context.Context,
val float64,
operationName OperationNameAttr,
providerName ProviderNameAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("gen_ai.operation.name", string(operationName)),
attribute.String("gen_ai.provider.name", string(providerName)),
)...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
func (m ClientOperationDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// 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) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// 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) AttrRequestModel(val string) attribute.KeyValue {
return attribute.String("gen_ai.request.model", val)
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the genAI server port.
func (ClientOperationDuration) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
// 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) AttrResponseModel(val string) attribute.KeyValue {
return attribute.String("gen_ai.response.model", val)
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents the genAI server address.
func (ClientOperationDuration) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
// 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.
type ClientTokenUsage struct {
metric.Int64Histogram
}
var newClientTokenUsageOpts = []metric.Int64HistogramOption{
metric.WithDescription("Number of input and output tokens used."),
metric.WithUnit("{token}"),
}
// NewClientTokenUsage returns a new ClientTokenUsage instrument.
func NewClientTokenUsage(
m metric.Meter,
opt ...metric.Int64HistogramOption,
) (ClientTokenUsage, error) {
// Check if the meter is nil.
if m == nil {
return ClientTokenUsage{noop.Int64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newClientTokenUsageOpts
} else {
opt = append(opt, newClientTokenUsageOpts...)
}
i, err := m.Int64Histogram(
"gen_ai.client.token.usage",
opt...,
)
if err != nil {
return ClientTokenUsage{noop.Int64Histogram{}}, err
}
return ClientTokenUsage{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ClientTokenUsage) Inst() metric.Int64Histogram {
return m.Int64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ClientTokenUsage) Name() string {
return "gen_ai.client.token.usage"
}
// Unit returns the semantic convention unit of the instrument
func (ClientTokenUsage) Unit() string {
return "{token}"
}
// Description returns the semantic convention description of the instrument
func (ClientTokenUsage) Description() string {
return "Number of input and output tokens used."
}
// 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 (m ClientTokenUsage) Record(
ctx context.Context,
val int64,
operationName OperationNameAttr,
providerName ProviderNameAttr,
tokenType TokenTypeAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Int64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("gen_ai.operation.name", string(operationName)),
attribute.String("gen_ai.provider.name", string(providerName)),
attribute.String("gen_ai.token.type", string(tokenType)),
)...,
),
)
m.Int64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
func (m ClientTokenUsage) RecordSet(ctx context.Context, val int64, set attribute.Set) {
if set.Len() == 0 {
m.Int64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Int64Histogram.Record(ctx, val, *o...)
}
// 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) AttrRequestModel(val string) attribute.KeyValue {
return attribute.String("gen_ai.request.model", val)
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the genAI server port.
func (ClientTokenUsage) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
// 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) AttrResponseModel(val string) attribute.KeyValue {
return attribute.String("gen_ai.response.model", val)
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents the genAI server address.
func (ClientTokenUsage) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
// 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.
type ServerRequestDuration struct {
metric.Float64Histogram
}
var newServerRequestDurationOpts = []metric.Float64HistogramOption{
metric.WithDescription("Generative AI server request duration such as time-to-last byte or last output token."),
metric.WithUnit("s"),
}
// NewServerRequestDuration returns a new ServerRequestDuration instrument.
func NewServerRequestDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (ServerRequestDuration, error) {
// Check if the meter is nil.
if m == nil {
return ServerRequestDuration{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newServerRequestDurationOpts
} else {
opt = append(opt, newServerRequestDurationOpts...)
}
i, err := m.Float64Histogram(
"gen_ai.server.request.duration",
opt...,
)
if err != nil {
return ServerRequestDuration{noop.Float64Histogram{}}, err
}
return ServerRequestDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ServerRequestDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ServerRequestDuration) Name() string {
return "gen_ai.server.request.duration"
}
// Unit returns the semantic convention unit of the instrument
func (ServerRequestDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (ServerRequestDuration) Description() string {
return "Generative AI server request duration such as time-to-last byte or last output token."
}
// 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 (m ServerRequestDuration) Record(
ctx context.Context,
val float64,
operationName OperationNameAttr,
providerName ProviderNameAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("gen_ai.operation.name", string(operationName)),
attribute.String("gen_ai.provider.name", string(providerName)),
)...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
func (m ServerRequestDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// 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) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// 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) AttrRequestModel(val string) attribute.KeyValue {
return attribute.String("gen_ai.request.model", val)
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the genAI server port.
func (ServerRequestDuration) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
// 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) AttrResponseModel(val string) attribute.KeyValue {
return attribute.String("gen_ai.response.model", val)
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents the genAI server address.
func (ServerRequestDuration) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
// 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.
type ServerTimePerOutputToken struct {
metric.Float64Histogram
}
var newServerTimePerOutputTokenOpts = []metric.Float64HistogramOption{
metric.WithDescription("Time per output token generated after the first token for successful responses."),
metric.WithUnit("s"),
}
// NewServerTimePerOutputToken returns a new ServerTimePerOutputToken instrument.
func NewServerTimePerOutputToken(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (ServerTimePerOutputToken, error) {
// Check if the meter is nil.
if m == nil {
return ServerTimePerOutputToken{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newServerTimePerOutputTokenOpts
} else {
opt = append(opt, newServerTimePerOutputTokenOpts...)
}
i, err := m.Float64Histogram(
"gen_ai.server.time_per_output_token",
opt...,
)
if err != nil {
return ServerTimePerOutputToken{noop.Float64Histogram{}}, err
}
return ServerTimePerOutputToken{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ServerTimePerOutputToken) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ServerTimePerOutputToken) Name() string {
return "gen_ai.server.time_per_output_token"
}
// Unit returns the semantic convention unit of the instrument
func (ServerTimePerOutputToken) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (ServerTimePerOutputToken) Description() string {
return "Time per output token generated after the first token for successful responses."
}
// 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 (m ServerTimePerOutputToken) Record(
ctx context.Context,
val float64,
operationName OperationNameAttr,
providerName ProviderNameAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("gen_ai.operation.name", string(operationName)),
attribute.String("gen_ai.provider.name", string(providerName)),
)...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
func (m ServerTimePerOutputToken) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// 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) AttrRequestModel(val string) attribute.KeyValue {
return attribute.String("gen_ai.request.model", val)
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the genAI server port.
func (ServerTimePerOutputToken) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
// 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) AttrResponseModel(val string) attribute.KeyValue {
return attribute.String("gen_ai.response.model", val)
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents the genAI server address.
func (ServerTimePerOutputToken) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
// 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.
type ServerTimeToFirstToken struct {
metric.Float64Histogram
}
var newServerTimeToFirstTokenOpts = []metric.Float64HistogramOption{
metric.WithDescription("Time to generate first token for successful responses."),
metric.WithUnit("s"),
}
// NewServerTimeToFirstToken returns a new ServerTimeToFirstToken instrument.
func NewServerTimeToFirstToken(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (ServerTimeToFirstToken, error) {
// Check if the meter is nil.
if m == nil {
return ServerTimeToFirstToken{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newServerTimeToFirstTokenOpts
} else {
opt = append(opt, newServerTimeToFirstTokenOpts...)
}
i, err := m.Float64Histogram(
"gen_ai.server.time_to_first_token",
opt...,
)
if err != nil {
return ServerTimeToFirstToken{noop.Float64Histogram{}}, err
}
return ServerTimeToFirstToken{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ServerTimeToFirstToken) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ServerTimeToFirstToken) Name() string {
return "gen_ai.server.time_to_first_token"
}
// Unit returns the semantic convention unit of the instrument
func (ServerTimeToFirstToken) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (ServerTimeToFirstToken) Description() string {
return "Time to generate first token for successful responses."
}
// 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 (m ServerTimeToFirstToken) Record(
ctx context.Context,
val float64,
operationName OperationNameAttr,
providerName ProviderNameAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("gen_ai.operation.name", string(operationName)),
attribute.String("gen_ai.provider.name", string(providerName)),
)...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
func (m ServerTimeToFirstToken) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// 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) AttrRequestModel(val string) attribute.KeyValue {
return attribute.String("gen_ai.request.model", val)
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the genAI server port.
func (ServerTimeToFirstToken) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
// 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) AttrResponseModel(val string) attribute.KeyValue {
return attribute.String("gen_ai.response.model", val)
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents the genAI server address.
func (ServerTimeToFirstToken) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
+604
View File
@@ -0,0 +1,604 @@
// Code generated from semantic convention specification. DO NOT EDIT.
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Package goconv provides types and functionality for OpenTelemetry semantic
// conventions in the "go" namespace.
package goconv
import (
"context"
"sync"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
)
var (
addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }}
recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }}
)
// MemoryTypeAttr is an attribute conforming to the go.memory.type semantic
// conventions. It represents the type of memory.
type MemoryTypeAttr string
var (
// MemoryTypeStack is the memory allocated from the heap that is reserved for
// stack space, whether or not it is currently in-use.
MemoryTypeStack MemoryTypeAttr = "stack"
// MemoryTypeOther is the memory used by the Go runtime, excluding other
// categories of memory usage described in this enumeration.
MemoryTypeOther MemoryTypeAttr = "other"
)
// ConfigGogc is an instrument used to record metric values conforming to the
// "go.config.gogc" semantic conventions. It represents the heap size target
// percentage configured by the user, otherwise 100.
type ConfigGogc struct {
metric.Int64ObservableUpDownCounter
}
var newConfigGogcOpts = []metric.Int64ObservableUpDownCounterOption{
metric.WithDescription("Heap size target percentage configured by the user, otherwise 100."),
metric.WithUnit("%"),
}
// NewConfigGogc returns a new ConfigGogc instrument.
func NewConfigGogc(
m metric.Meter,
opt ...metric.Int64ObservableUpDownCounterOption,
) (ConfigGogc, error) {
// Check if the meter is nil.
if m == nil {
return ConfigGogc{noop.Int64ObservableUpDownCounter{}}, nil
}
if len(opt) == 0 {
opt = newConfigGogcOpts
} else {
opt = append(opt, newConfigGogcOpts...)
}
i, err := m.Int64ObservableUpDownCounter(
"go.config.gogc",
opt...,
)
if err != nil {
return ConfigGogc{noop.Int64ObservableUpDownCounter{}}, err
}
return ConfigGogc{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ConfigGogc) Inst() metric.Int64ObservableUpDownCounter {
return m.Int64ObservableUpDownCounter
}
// Name returns the semantic convention name of the instrument.
func (ConfigGogc) Name() string {
return "go.config.gogc"
}
// Unit returns the semantic convention unit of the instrument
func (ConfigGogc) Unit() string {
return "%"
}
// Description returns the semantic convention description of the instrument
func (ConfigGogc) Description() string {
return "Heap size target percentage configured by the user, otherwise 100."
}
// GoroutineCount is an instrument used to record metric values conforming to the
// "go.goroutine.count" semantic conventions. It represents the count of live
// goroutines.
type GoroutineCount struct {
metric.Int64ObservableUpDownCounter
}
var newGoroutineCountOpts = []metric.Int64ObservableUpDownCounterOption{
metric.WithDescription("Count of live goroutines."),
metric.WithUnit("{goroutine}"),
}
// NewGoroutineCount returns a new GoroutineCount instrument.
func NewGoroutineCount(
m metric.Meter,
opt ...metric.Int64ObservableUpDownCounterOption,
) (GoroutineCount, error) {
// Check if the meter is nil.
if m == nil {
return GoroutineCount{noop.Int64ObservableUpDownCounter{}}, nil
}
if len(opt) == 0 {
opt = newGoroutineCountOpts
} else {
opt = append(opt, newGoroutineCountOpts...)
}
i, err := m.Int64ObservableUpDownCounter(
"go.goroutine.count",
opt...,
)
if err != nil {
return GoroutineCount{noop.Int64ObservableUpDownCounter{}}, err
}
return GoroutineCount{i}, nil
}
// Inst returns the underlying metric instrument.
func (m GoroutineCount) Inst() metric.Int64ObservableUpDownCounter {
return m.Int64ObservableUpDownCounter
}
// Name returns the semantic convention name of the instrument.
func (GoroutineCount) Name() string {
return "go.goroutine.count"
}
// Unit returns the semantic convention unit of the instrument
func (GoroutineCount) Unit() string {
return "{goroutine}"
}
// Description returns the semantic convention description of the instrument
func (GoroutineCount) Description() string {
return "Count of live goroutines."
}
// MemoryAllocated is an instrument used to record metric values conforming to
// the "go.memory.allocated" semantic conventions. It represents the memory
// allocated to the heap by the application.
type MemoryAllocated struct {
metric.Int64ObservableCounter
}
var newMemoryAllocatedOpts = []metric.Int64ObservableCounterOption{
metric.WithDescription("Memory allocated to the heap by the application."),
metric.WithUnit("By"),
}
// NewMemoryAllocated returns a new MemoryAllocated instrument.
func NewMemoryAllocated(
m metric.Meter,
opt ...metric.Int64ObservableCounterOption,
) (MemoryAllocated, error) {
// Check if the meter is nil.
if m == nil {
return MemoryAllocated{noop.Int64ObservableCounter{}}, nil
}
if len(opt) == 0 {
opt = newMemoryAllocatedOpts
} else {
opt = append(opt, newMemoryAllocatedOpts...)
}
i, err := m.Int64ObservableCounter(
"go.memory.allocated",
opt...,
)
if err != nil {
return MemoryAllocated{noop.Int64ObservableCounter{}}, err
}
return MemoryAllocated{i}, nil
}
// Inst returns the underlying metric instrument.
func (m MemoryAllocated) Inst() metric.Int64ObservableCounter {
return m.Int64ObservableCounter
}
// Name returns the semantic convention name of the instrument.
func (MemoryAllocated) Name() string {
return "go.memory.allocated"
}
// Unit returns the semantic convention unit of the instrument
func (MemoryAllocated) Unit() string {
return "By"
}
// Description returns the semantic convention description of the instrument
func (MemoryAllocated) Description() string {
return "Memory allocated to the heap by the application."
}
// MemoryAllocations is an instrument used to record metric values conforming to
// the "go.memory.allocations" semantic conventions. It represents the count of
// allocations to the heap by the application.
type MemoryAllocations struct {
metric.Int64ObservableCounter
}
var newMemoryAllocationsOpts = []metric.Int64ObservableCounterOption{
metric.WithDescription("Count of allocations to the heap by the application."),
metric.WithUnit("{allocation}"),
}
// NewMemoryAllocations returns a new MemoryAllocations instrument.
func NewMemoryAllocations(
m metric.Meter,
opt ...metric.Int64ObservableCounterOption,
) (MemoryAllocations, error) {
// Check if the meter is nil.
if m == nil {
return MemoryAllocations{noop.Int64ObservableCounter{}}, nil
}
if len(opt) == 0 {
opt = newMemoryAllocationsOpts
} else {
opt = append(opt, newMemoryAllocationsOpts...)
}
i, err := m.Int64ObservableCounter(
"go.memory.allocations",
opt...,
)
if err != nil {
return MemoryAllocations{noop.Int64ObservableCounter{}}, err
}
return MemoryAllocations{i}, nil
}
// Inst returns the underlying metric instrument.
func (m MemoryAllocations) Inst() metric.Int64ObservableCounter {
return m.Int64ObservableCounter
}
// Name returns the semantic convention name of the instrument.
func (MemoryAllocations) Name() string {
return "go.memory.allocations"
}
// Unit returns the semantic convention unit of the instrument
func (MemoryAllocations) Unit() string {
return "{allocation}"
}
// Description returns the semantic convention description of the instrument
func (MemoryAllocations) Description() string {
return "Count of allocations to the heap by the application."
}
// MemoryGCGoal is an instrument used to record metric values conforming to the
// "go.memory.gc.goal" semantic conventions. It represents the heap size target
// for the end of the GC cycle.
type MemoryGCGoal struct {
metric.Int64ObservableUpDownCounter
}
var newMemoryGCGoalOpts = []metric.Int64ObservableUpDownCounterOption{
metric.WithDescription("Heap size target for the end of the GC cycle."),
metric.WithUnit("By"),
}
// NewMemoryGCGoal returns a new MemoryGCGoal instrument.
func NewMemoryGCGoal(
m metric.Meter,
opt ...metric.Int64ObservableUpDownCounterOption,
) (MemoryGCGoal, error) {
// Check if the meter is nil.
if m == nil {
return MemoryGCGoal{noop.Int64ObservableUpDownCounter{}}, nil
}
if len(opt) == 0 {
opt = newMemoryGCGoalOpts
} else {
opt = append(opt, newMemoryGCGoalOpts...)
}
i, err := m.Int64ObservableUpDownCounter(
"go.memory.gc.goal",
opt...,
)
if err != nil {
return MemoryGCGoal{noop.Int64ObservableUpDownCounter{}}, err
}
return MemoryGCGoal{i}, nil
}
// Inst returns the underlying metric instrument.
func (m MemoryGCGoal) Inst() metric.Int64ObservableUpDownCounter {
return m.Int64ObservableUpDownCounter
}
// Name returns the semantic convention name of the instrument.
func (MemoryGCGoal) Name() string {
return "go.memory.gc.goal"
}
// Unit returns the semantic convention unit of the instrument
func (MemoryGCGoal) Unit() string {
return "By"
}
// Description returns the semantic convention description of the instrument
func (MemoryGCGoal) Description() string {
return "Heap size target for the end of the GC cycle."
}
// MemoryLimit is an instrument used to record metric values conforming to the
// "go.memory.limit" semantic conventions. It represents the go runtime memory
// limit configured by the user, if a limit exists.
type MemoryLimit struct {
metric.Int64ObservableUpDownCounter
}
var newMemoryLimitOpts = []metric.Int64ObservableUpDownCounterOption{
metric.WithDescription("Go runtime memory limit configured by the user, if a limit exists."),
metric.WithUnit("By"),
}
// NewMemoryLimit returns a new MemoryLimit instrument.
func NewMemoryLimit(
m metric.Meter,
opt ...metric.Int64ObservableUpDownCounterOption,
) (MemoryLimit, error) {
// Check if the meter is nil.
if m == nil {
return MemoryLimit{noop.Int64ObservableUpDownCounter{}}, nil
}
if len(opt) == 0 {
opt = newMemoryLimitOpts
} else {
opt = append(opt, newMemoryLimitOpts...)
}
i, err := m.Int64ObservableUpDownCounter(
"go.memory.limit",
opt...,
)
if err != nil {
return MemoryLimit{noop.Int64ObservableUpDownCounter{}}, err
}
return MemoryLimit{i}, nil
}
// Inst returns the underlying metric instrument.
func (m MemoryLimit) Inst() metric.Int64ObservableUpDownCounter {
return m.Int64ObservableUpDownCounter
}
// Name returns the semantic convention name of the instrument.
func (MemoryLimit) Name() string {
return "go.memory.limit"
}
// Unit returns the semantic convention unit of the instrument
func (MemoryLimit) Unit() string {
return "By"
}
// Description returns the semantic convention description of the instrument
func (MemoryLimit) Description() string {
return "Go runtime memory limit configured by the user, if a limit exists."
}
// MemoryUsed is an instrument used to record metric values conforming to the
// "go.memory.used" semantic conventions. It represents the memory used by the Go
// runtime.
type MemoryUsed struct {
metric.Int64ObservableUpDownCounter
}
var newMemoryUsedOpts = []metric.Int64ObservableUpDownCounterOption{
metric.WithDescription("Memory used by the Go runtime."),
metric.WithUnit("By"),
}
// NewMemoryUsed returns a new MemoryUsed instrument.
func NewMemoryUsed(
m metric.Meter,
opt ...metric.Int64ObservableUpDownCounterOption,
) (MemoryUsed, error) {
// Check if the meter is nil.
if m == nil {
return MemoryUsed{noop.Int64ObservableUpDownCounter{}}, nil
}
if len(opt) == 0 {
opt = newMemoryUsedOpts
} else {
opt = append(opt, newMemoryUsedOpts...)
}
i, err := m.Int64ObservableUpDownCounter(
"go.memory.used",
opt...,
)
if err != nil {
return MemoryUsed{noop.Int64ObservableUpDownCounter{}}, err
}
return MemoryUsed{i}, nil
}
// Inst returns the underlying metric instrument.
func (m MemoryUsed) Inst() metric.Int64ObservableUpDownCounter {
return m.Int64ObservableUpDownCounter
}
// Name returns the semantic convention name of the instrument.
func (MemoryUsed) Name() string {
return "go.memory.used"
}
// Unit returns the semantic convention unit of the instrument
func (MemoryUsed) Unit() string {
return "By"
}
// Description returns the semantic convention description of the instrument
func (MemoryUsed) Description() string {
return "Memory used by the Go runtime."
}
// AttrMemoryType returns an optional attribute for the "go.memory.type" semantic
// convention. It represents the type of memory.
func (MemoryUsed) AttrMemoryType(val MemoryTypeAttr) attribute.KeyValue {
return attribute.String("go.memory.type", string(val))
}
// ProcessorLimit is an instrument used to record metric values conforming to the
// "go.processor.limit" semantic conventions. It represents the number of OS
// threads that can execute user-level Go code simultaneously.
type ProcessorLimit struct {
metric.Int64ObservableUpDownCounter
}
var newProcessorLimitOpts = []metric.Int64ObservableUpDownCounterOption{
metric.WithDescription("The number of OS threads that can execute user-level Go code simultaneously."),
metric.WithUnit("{thread}"),
}
// NewProcessorLimit returns a new ProcessorLimit instrument.
func NewProcessorLimit(
m metric.Meter,
opt ...metric.Int64ObservableUpDownCounterOption,
) (ProcessorLimit, error) {
// Check if the meter is nil.
if m == nil {
return ProcessorLimit{noop.Int64ObservableUpDownCounter{}}, nil
}
if len(opt) == 0 {
opt = newProcessorLimitOpts
} else {
opt = append(opt, newProcessorLimitOpts...)
}
i, err := m.Int64ObservableUpDownCounter(
"go.processor.limit",
opt...,
)
if err != nil {
return ProcessorLimit{noop.Int64ObservableUpDownCounter{}}, err
}
return ProcessorLimit{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ProcessorLimit) Inst() metric.Int64ObservableUpDownCounter {
return m.Int64ObservableUpDownCounter
}
// Name returns the semantic convention name of the instrument.
func (ProcessorLimit) Name() string {
return "go.processor.limit"
}
// Unit returns the semantic convention unit of the instrument
func (ProcessorLimit) Unit() string {
return "{thread}"
}
// Description returns the semantic convention description of the instrument
func (ProcessorLimit) Description() string {
return "The number of OS threads that can execute user-level Go code simultaneously."
}
// ScheduleDuration is an instrument used to record metric values conforming to
// the "go.schedule.duration" semantic conventions. It represents the time
// goroutines have spent in the scheduler in a runnable state before actually
// running.
type ScheduleDuration struct {
metric.Float64Histogram
}
var newScheduleDurationOpts = []metric.Float64HistogramOption{
metric.WithDescription("The time goroutines have spent in the scheduler in a runnable state before actually running."),
metric.WithUnit("s"),
}
// NewScheduleDuration returns a new ScheduleDuration instrument.
func NewScheduleDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (ScheduleDuration, error) {
// Check if the meter is nil.
if m == nil {
return ScheduleDuration{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newScheduleDurationOpts
} else {
opt = append(opt, newScheduleDurationOpts...)
}
i, err := m.Float64Histogram(
"go.schedule.duration",
opt...,
)
if err != nil {
return ScheduleDuration{noop.Float64Histogram{}}, err
}
return ScheduleDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ScheduleDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ScheduleDuration) Name() string {
return "go.schedule.duration"
}
// Unit returns the semantic convention unit of the instrument
func (ScheduleDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (ScheduleDuration) Description() string {
return "The time goroutines have spent in the scheduler in a runnable state before actually running."
}
// Record records val to the current distribution for attrs.
//
// Computed from `/sched/latencies:seconds`. Bucket boundaries are provided by
// the runtime, and are subject to change.
func (m ScheduleDuration) Record(ctx context.Context, val float64, attrs ...attribute.KeyValue) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributes(attrs...))
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
//
// Computed from `/sched/latencies:seconds`. Bucket boundaries are provided by
// the runtime, and are subject to change.
func (m ScheduleDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+869
View File
@@ -0,0 +1,869 @@
// Code generated from semantic convention specification. DO NOT EDIT.
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Package mcpconv provides types and functionality for OpenTelemetry semantic
// conventions in the "mcp" namespace.
package mcpconv
import (
"context"
"sync"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
)
var (
addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }}
recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }}
)
// ErrorTypeAttr is an attribute conforming to the error.type semantic
// conventions. It represents the describes a class of error the operation ended
// with.
type ErrorTypeAttr string
var (
// ErrorTypeOther is a fallback error value to be used when the instrumentation
// doesn't define a custom value.
ErrorTypeOther ErrorTypeAttr = "_OTHER"
)
// GenAIOperationNameAttr is an attribute conforming to the gen_ai.operation.name
// semantic conventions. It represents the name of the GenAI operation being
// performed.
type GenAIOperationNameAttr string
var (
// GenAIOperationNameChat is the chat completion operation such as
// [OpenAI Chat API].
//
// [OpenAI Chat API]: https://platform.openai.com/docs/api-reference/chat
GenAIOperationNameChat GenAIOperationNameAttr = "chat"
// GenAIOperationNameGenerateContent is the multimodal content generation
// operation such as [Gemini Generate Content].
//
// [Gemini Generate Content]: https://ai.google.dev/api/generate-content
GenAIOperationNameGenerateContent GenAIOperationNameAttr = "generate_content"
// GenAIOperationNameTextCompletion is the text completions operation such as
// [OpenAI Completions API (Legacy)].
//
// [OpenAI Completions API (Legacy)]: https://platform.openai.com/docs/api-reference/completions
GenAIOperationNameTextCompletion GenAIOperationNameAttr = "text_completion"
// GenAIOperationNameEmbeddings is the embeddings operation such as
// [OpenAI Create embeddings API].
//
// [OpenAI Create embeddings API]: https://platform.openai.com/docs/api-reference/embeddings/create
GenAIOperationNameEmbeddings GenAIOperationNameAttr = "embeddings"
// GenAIOperationNameRetrieval is the retrieval operation such as
// [OpenAI Search Vector Store API].
//
// [OpenAI Search Vector Store API]: https://platform.openai.com/docs/api-reference/vector-stores/search
GenAIOperationNameRetrieval GenAIOperationNameAttr = "retrieval"
// GenAIOperationNameCreateAgent is the create GenAI agent.
GenAIOperationNameCreateAgent GenAIOperationNameAttr = "create_agent"
// GenAIOperationNameInvokeAgent is the invoke GenAI agent.
GenAIOperationNameInvokeAgent GenAIOperationNameAttr = "invoke_agent"
// GenAIOperationNameExecuteTool is the execute a tool.
GenAIOperationNameExecuteTool GenAIOperationNameAttr = "execute_tool"
)
// MethodNameAttr is an attribute conforming to the mcp.method.name semantic
// conventions. It represents the name of the request or notification method.
type MethodNameAttr string
var (
// MethodNameNotificationsCancelled is the notification cancelling a
// previously-issued request.
MethodNameNotificationsCancelled MethodNameAttr = "notifications/cancelled"
// MethodNameInitialize is the request to initialize the MCP client.
MethodNameInitialize MethodNameAttr = "initialize"
// MethodNameNotificationsInitialized is the notification indicating that the
// MCP client has been initialized.
MethodNameNotificationsInitialized MethodNameAttr = "notifications/initialized"
// MethodNameNotificationsProgress is the notification indicating the progress
// for a long-running operation.
MethodNameNotificationsProgress MethodNameAttr = "notifications/progress"
// MethodNamePing is the request to check that the other party is still alive.
MethodNamePing MethodNameAttr = "ping"
// MethodNameResourcesList is the request to list resources available on server.
MethodNameResourcesList MethodNameAttr = "resources/list"
// MethodNameResourcesTemplatesList is the request to list resource templates
// available on server.
MethodNameResourcesTemplatesList MethodNameAttr = "resources/templates/list"
// MethodNameResourcesRead is the request to read a resource.
MethodNameResourcesRead MethodNameAttr = "resources/read"
// MethodNameNotificationsResourcesListChanged is the notification indicating
// that the list of resources has changed.
MethodNameNotificationsResourcesListChanged MethodNameAttr = "notifications/resources/list_changed"
// MethodNameResourcesSubscribe is the request to subscribe to a resource.
MethodNameResourcesSubscribe MethodNameAttr = "resources/subscribe"
// MethodNameResourcesUnsubscribe is the request to unsubscribe from resource
// updates.
MethodNameResourcesUnsubscribe MethodNameAttr = "resources/unsubscribe"
// MethodNameNotificationsResourcesUpdated is the notification indicating that a
// resource has been updated.
MethodNameNotificationsResourcesUpdated MethodNameAttr = "notifications/resources/updated"
// MethodNamePromptsList is the request to list prompts available on server.
MethodNamePromptsList MethodNameAttr = "prompts/list"
// MethodNamePromptsGet is the request to get a prompt.
MethodNamePromptsGet MethodNameAttr = "prompts/get"
// MethodNameNotificationsPromptsListChanged is the notification indicating that
// the list of prompts has changed.
MethodNameNotificationsPromptsListChanged MethodNameAttr = "notifications/prompts/list_changed"
// MethodNameToolsList is the request to list tools available on server.
MethodNameToolsList MethodNameAttr = "tools/list"
// MethodNameToolsCall is the request to call a tool.
MethodNameToolsCall MethodNameAttr = "tools/call"
// MethodNameNotificationsToolsListChanged is the notification indicating that
// the list of tools has changed.
MethodNameNotificationsToolsListChanged MethodNameAttr = "notifications/tools/list_changed"
// MethodNameLoggingSetLevel is the request to set the logging level.
MethodNameLoggingSetLevel MethodNameAttr = "logging/setLevel"
// MethodNameNotificationsMessage is the notification indicating that a message
// has been received.
MethodNameNotificationsMessage MethodNameAttr = "notifications/message"
// MethodNameSamplingCreateMessage is the request to create a sampling message.
MethodNameSamplingCreateMessage MethodNameAttr = "sampling/createMessage"
// MethodNameCompletionComplete is the request to complete a prompt.
MethodNameCompletionComplete MethodNameAttr = "completion/complete"
// MethodNameRootsList is the request to list roots available on server.
MethodNameRootsList MethodNameAttr = "roots/list"
// MethodNameNotificationsRootsListChanged is the notification indicating that
// the list of roots has changed.
MethodNameNotificationsRootsListChanged MethodNameAttr = "notifications/roots/list_changed"
// MethodNameElicitationCreate is the request from the server to elicit
// additional information from the user via the client.
MethodNameElicitationCreate MethodNameAttr = "elicitation/create"
)
// NetworkTransportAttr is an attribute conforming to the network.transport
// semantic conventions. It represents the transport protocol used for the MCP
// session.
type NetworkTransportAttr string
var (
// NetworkTransportTCP is the TCP.
NetworkTransportTCP NetworkTransportAttr = "tcp"
// NetworkTransportUDP is the UDP.
NetworkTransportUDP NetworkTransportAttr = "udp"
// NetworkTransportPipe is the named or anonymous pipe.
NetworkTransportPipe NetworkTransportAttr = "pipe"
// NetworkTransportUnix is the unix domain socket.
NetworkTransportUnix NetworkTransportAttr = "unix"
// NetworkTransportQUIC is the QUIC.
NetworkTransportQUIC NetworkTransportAttr = "quic"
)
// ClientOperationDuration is an instrument used to record metric values
// conforming to the "mcp.client.operation.duration" semantic conventions. It
// represents the duration of the MCP request or notification as observed on the
// sender from the time it was sent until the response or ack is received.
type ClientOperationDuration struct {
metric.Float64Histogram
}
var newClientOperationDurationOpts = []metric.Float64HistogramOption{
metric.WithDescription("The duration of the MCP request or notification as observed on the sender from the time it was sent until the response or ack is received."),
metric.WithUnit("s"),
}
// NewClientOperationDuration returns a new ClientOperationDuration instrument.
func NewClientOperationDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (ClientOperationDuration, error) {
// Check if the meter is nil.
if m == nil {
return ClientOperationDuration{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newClientOperationDurationOpts
} else {
opt = append(opt, newClientOperationDurationOpts...)
}
i, err := m.Float64Histogram(
"mcp.client.operation.duration",
opt...,
)
if err != nil {
return ClientOperationDuration{noop.Float64Histogram{}}, err
}
return ClientOperationDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ClientOperationDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ClientOperationDuration) Name() string {
return "mcp.client.operation.duration"
}
// Unit returns the semantic convention unit of the instrument
func (ClientOperationDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (ClientOperationDuration) Description() string {
return "The duration of the MCP request or notification as observed on the sender from the time it was sent until the response or ack is received."
}
// Record records val to the current distribution for attrs.
//
// The methodName is the the name of the request or notification method.
//
// All additional attrs passed are included in the recorded value.
func (m ClientOperationDuration) Record(
ctx context.Context,
val float64,
methodName MethodNameAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("mcp.method.name", string(methodName)),
)...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
func (m ClientOperationDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// 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) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// AttrGenAIPromptName returns an optional attribute for the "gen_ai.prompt.name"
// semantic convention. It represents the name of the prompt or prompt template
// provided in the request or response.
func (ClientOperationDuration) AttrGenAIPromptName(val string) attribute.KeyValue {
return attribute.String("gen_ai.prompt.name", val)
}
// AttrGenAIToolName returns an optional attribute for the "gen_ai.tool.name"
// semantic convention. It represents the name of the tool utilized by the agent.
func (ClientOperationDuration) AttrGenAIToolName(val string) attribute.KeyValue {
return attribute.String("gen_ai.tool.name", val)
}
// AttrRPCResponseStatusCode returns an optional attribute for the
// "rpc.response.status_code" semantic convention. It represents the error code
// from the JSON-RPC response.
func (ClientOperationDuration) AttrRPCResponseStatusCode(val string) attribute.KeyValue {
return attribute.String("rpc.response.status_code", val)
}
// AttrGenAIOperationName returns an optional attribute for the
// "gen_ai.operation.name" semantic convention. It represents the name of the
// GenAI operation being performed.
func (ClientOperationDuration) AttrGenAIOperationName(val GenAIOperationNameAttr) attribute.KeyValue {
return attribute.String("gen_ai.operation.name", string(val))
}
// AttrJSONRPCProtocolVersion returns an optional attribute for the
// "jsonrpc.protocol.version" semantic convention. It represents the protocol
// version, as specified in the `jsonrpc` property of the request and its
// corresponding response.
func (ClientOperationDuration) AttrJSONRPCProtocolVersion(val string) attribute.KeyValue {
return attribute.String("jsonrpc.protocol.version", val)
}
// AttrProtocolVersion returns an optional attribute for the
// "mcp.protocol.version" semantic convention. It represents the [version] of the
// Model Context Protocol used.
//
// [version]: https://modelcontextprotocol.io/specification/versioning
func (ClientOperationDuration) AttrProtocolVersion(val string) attribute.KeyValue {
return attribute.String("mcp.protocol.version", val)
}
// AttrNetworkProtocolName returns an optional attribute for the
// "network.protocol.name" semantic convention. It represents the
// [OSI application layer] or non-OSI equivalent.
//
// [OSI application layer]: https://wikipedia.org/wiki/Application_layer
func (ClientOperationDuration) AttrNetworkProtocolName(val string) attribute.KeyValue {
return attribute.String("network.protocol.name", val)
}
// AttrNetworkProtocolVersion returns an optional attribute for the
// "network.protocol.version" semantic convention. It represents the actual
// version of the protocol used for network communication.
func (ClientOperationDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
return attribute.String("network.protocol.version", val)
}
// AttrNetworkTransport returns an optional attribute for the "network.transport"
// semantic convention. It represents the transport protocol used for the MCP
// session.
func (ClientOperationDuration) AttrNetworkTransport(val NetworkTransportAttr) attribute.KeyValue {
return attribute.String("network.transport", string(val))
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents the server domain name if available without
// reverse DNS lookup; otherwise, IP address or Unix domain socket name.
func (ClientOperationDuration) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the server port number.
func (ClientOperationDuration) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
// AttrResourceURI returns an optional attribute for the "mcp.resource.uri"
// semantic convention. It represents the value of the resource uri.
func (ClientOperationDuration) AttrResourceURI(val string) attribute.KeyValue {
return attribute.String("mcp.resource.uri", val)
}
// ClientSessionDuration is an instrument used to record metric values conforming
// to the "mcp.client.session.duration" semantic conventions. It represents the
// duration of the MCP session as observed on the MCP client.
type ClientSessionDuration struct {
metric.Float64Histogram
}
var newClientSessionDurationOpts = []metric.Float64HistogramOption{
metric.WithDescription("The duration of the MCP session as observed on the MCP client."),
metric.WithUnit("s"),
}
// NewClientSessionDuration returns a new ClientSessionDuration instrument.
func NewClientSessionDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (ClientSessionDuration, error) {
// Check if the meter is nil.
if m == nil {
return ClientSessionDuration{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newClientSessionDurationOpts
} else {
opt = append(opt, newClientSessionDurationOpts...)
}
i, err := m.Float64Histogram(
"mcp.client.session.duration",
opt...,
)
if err != nil {
return ClientSessionDuration{noop.Float64Histogram{}}, err
}
return ClientSessionDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ClientSessionDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ClientSessionDuration) Name() string {
return "mcp.client.session.duration"
}
// Unit returns the semantic convention unit of the instrument
func (ClientSessionDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (ClientSessionDuration) Description() string {
return "The duration of the MCP session as observed on the MCP client."
}
// Record records val to the current distribution for attrs.
//
// All additional attrs passed are included in the recorded value.
func (m ClientSessionDuration) Record(
ctx context.Context,
val float64,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
attrs...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
func (m ClientSessionDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// AttrErrorType returns an optional attribute for the "error.type" semantic
// convention. It represents the describes a class of error the operation ended
// with.
func (ClientSessionDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// AttrJSONRPCProtocolVersion returns an optional attribute for the
// "jsonrpc.protocol.version" semantic convention. It represents the protocol
// version, as specified in the `jsonrpc` property of the request and its
// corresponding response.
func (ClientSessionDuration) AttrJSONRPCProtocolVersion(val string) attribute.KeyValue {
return attribute.String("jsonrpc.protocol.version", val)
}
// AttrProtocolVersion returns an optional attribute for the
// "mcp.protocol.version" semantic convention. It represents the [version] of the
// Model Context Protocol used.
//
// [version]: https://modelcontextprotocol.io/specification/versioning
func (ClientSessionDuration) AttrProtocolVersion(val string) attribute.KeyValue {
return attribute.String("mcp.protocol.version", val)
}
// AttrNetworkProtocolName returns an optional attribute for the
// "network.protocol.name" semantic convention. It represents the
// [OSI application layer] or non-OSI equivalent.
//
// [OSI application layer]: https://wikipedia.org/wiki/Application_layer
func (ClientSessionDuration) AttrNetworkProtocolName(val string) attribute.KeyValue {
return attribute.String("network.protocol.name", val)
}
// AttrNetworkProtocolVersion returns an optional attribute for the
// "network.protocol.version" semantic convention. It represents the actual
// version of the protocol used for network communication.
func (ClientSessionDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
return attribute.String("network.protocol.version", val)
}
// AttrNetworkTransport returns an optional attribute for the "network.transport"
// semantic convention. It represents the transport protocol used for the MCP
// session.
func (ClientSessionDuration) AttrNetworkTransport(val NetworkTransportAttr) attribute.KeyValue {
return attribute.String("network.transport", string(val))
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents the server domain name if available without
// reverse DNS lookup; otherwise, IP address or Unix domain socket name.
func (ClientSessionDuration) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the server port number.
func (ClientSessionDuration) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
// ServerOperationDuration is an instrument used to record metric values
// conforming to the "mcp.server.operation.duration" semantic conventions. It
// represents the MCP request or notification duration as observed on the
// receiver from the time it was received until the result or ack is sent.
type ServerOperationDuration struct {
metric.Float64Histogram
}
var newServerOperationDurationOpts = []metric.Float64HistogramOption{
metric.WithDescription("MCP request or notification duration as observed on the receiver from the time it was received until the result or ack is sent."),
metric.WithUnit("s"),
}
// NewServerOperationDuration returns a new ServerOperationDuration instrument.
func NewServerOperationDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (ServerOperationDuration, error) {
// Check if the meter is nil.
if m == nil {
return ServerOperationDuration{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newServerOperationDurationOpts
} else {
opt = append(opt, newServerOperationDurationOpts...)
}
i, err := m.Float64Histogram(
"mcp.server.operation.duration",
opt...,
)
if err != nil {
return ServerOperationDuration{noop.Float64Histogram{}}, err
}
return ServerOperationDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ServerOperationDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ServerOperationDuration) Name() string {
return "mcp.server.operation.duration"
}
// Unit returns the semantic convention unit of the instrument
func (ServerOperationDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (ServerOperationDuration) Description() string {
return "MCP request or notification duration as observed on the receiver from the time it was received until the result or ack is sent."
}
// Record records val to the current distribution for attrs.
//
// The methodName is the the name of the request or notification method.
//
// All additional attrs passed are included in the recorded value.
func (m ServerOperationDuration) Record(
ctx context.Context,
val float64,
methodName MethodNameAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("mcp.method.name", string(methodName)),
)...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
func (m ServerOperationDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// AttrErrorType returns an optional attribute for the "error.type" semantic
// convention. It represents the describes a class of error the operation ended
// with.
func (ServerOperationDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// AttrGenAIPromptName returns an optional attribute for the "gen_ai.prompt.name"
// semantic convention. It represents the name of the prompt or prompt template
// provided in the request or response.
func (ServerOperationDuration) AttrGenAIPromptName(val string) attribute.KeyValue {
return attribute.String("gen_ai.prompt.name", val)
}
// AttrGenAIToolName returns an optional attribute for the "gen_ai.tool.name"
// semantic convention. It represents the name of the tool utilized by the agent.
func (ServerOperationDuration) AttrGenAIToolName(val string) attribute.KeyValue {
return attribute.String("gen_ai.tool.name", val)
}
// AttrRPCResponseStatusCode returns an optional attribute for the
// "rpc.response.status_code" semantic convention. It represents the error code
// from the JSON-RPC response.
func (ServerOperationDuration) AttrRPCResponseStatusCode(val string) attribute.KeyValue {
return attribute.String("rpc.response.status_code", val)
}
// AttrGenAIOperationName returns an optional attribute for the
// "gen_ai.operation.name" semantic convention. It represents the name of the
// GenAI operation being performed.
func (ServerOperationDuration) AttrGenAIOperationName(val GenAIOperationNameAttr) attribute.KeyValue {
return attribute.String("gen_ai.operation.name", string(val))
}
// AttrJSONRPCProtocolVersion returns an optional attribute for the
// "jsonrpc.protocol.version" semantic convention. It represents the protocol
// version, as specified in the `jsonrpc` property of the request and its
// corresponding response.
func (ServerOperationDuration) AttrJSONRPCProtocolVersion(val string) attribute.KeyValue {
return attribute.String("jsonrpc.protocol.version", val)
}
// AttrProtocolVersion returns an optional attribute for the
// "mcp.protocol.version" semantic convention. It represents the [version] of the
// Model Context Protocol used.
//
// [version]: https://modelcontextprotocol.io/specification/versioning
func (ServerOperationDuration) AttrProtocolVersion(val string) attribute.KeyValue {
return attribute.String("mcp.protocol.version", val)
}
// AttrNetworkProtocolName returns an optional attribute for the
// "network.protocol.name" semantic convention. It represents the
// [OSI application layer] or non-OSI equivalent.
//
// [OSI application layer]: https://wikipedia.org/wiki/Application_layer
func (ServerOperationDuration) AttrNetworkProtocolName(val string) attribute.KeyValue {
return attribute.String("network.protocol.name", val)
}
// AttrNetworkProtocolVersion returns an optional attribute for the
// "network.protocol.version" semantic convention. It represents the actual
// version of the protocol used for network communication.
func (ServerOperationDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
return attribute.String("network.protocol.version", val)
}
// AttrNetworkTransport returns an optional attribute for the "network.transport"
// semantic convention. It represents the transport protocol used for the MCP
// session.
func (ServerOperationDuration) AttrNetworkTransport(val NetworkTransportAttr) attribute.KeyValue {
return attribute.String("network.transport", string(val))
}
// AttrResourceURI returns an optional attribute for the "mcp.resource.uri"
// semantic convention. It represents the value of the resource uri.
func (ServerOperationDuration) AttrResourceURI(val string) attribute.KeyValue {
return attribute.String("mcp.resource.uri", val)
}
// ServerSessionDuration is an instrument used to record metric values conforming
// to the "mcp.server.session.duration" semantic conventions. It represents the
// duration of the MCP session as observed on the MCP server.
type ServerSessionDuration struct {
metric.Float64Histogram
}
var newServerSessionDurationOpts = []metric.Float64HistogramOption{
metric.WithDescription("The duration of the MCP session as observed on the MCP server."),
metric.WithUnit("s"),
}
// NewServerSessionDuration returns a new ServerSessionDuration instrument.
func NewServerSessionDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (ServerSessionDuration, error) {
// Check if the meter is nil.
if m == nil {
return ServerSessionDuration{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newServerSessionDurationOpts
} else {
opt = append(opt, newServerSessionDurationOpts...)
}
i, err := m.Float64Histogram(
"mcp.server.session.duration",
opt...,
)
if err != nil {
return ServerSessionDuration{noop.Float64Histogram{}}, err
}
return ServerSessionDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ServerSessionDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ServerSessionDuration) Name() string {
return "mcp.server.session.duration"
}
// Unit returns the semantic convention unit of the instrument
func (ServerSessionDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (ServerSessionDuration) Description() string {
return "The duration of the MCP session as observed on the MCP server."
}
// Record records val to the current distribution for attrs.
//
// All additional attrs passed are included in the recorded value.
func (m ServerSessionDuration) Record(
ctx context.Context,
val float64,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
attrs...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
func (m ServerSessionDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// AttrErrorType returns an optional attribute for the "error.type" semantic
// convention. It represents the describes a class of error the operation ended
// with.
func (ServerSessionDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// AttrJSONRPCProtocolVersion returns an optional attribute for the
// "jsonrpc.protocol.version" semantic convention. It represents the protocol
// version, as specified in the `jsonrpc` property of the request and its
// corresponding response.
func (ServerSessionDuration) AttrJSONRPCProtocolVersion(val string) attribute.KeyValue {
return attribute.String("jsonrpc.protocol.version", val)
}
// AttrProtocolVersion returns an optional attribute for the
// "mcp.protocol.version" semantic convention. It represents the [version] of the
// Model Context Protocol used.
//
// [version]: https://modelcontextprotocol.io/specification/versioning
func (ServerSessionDuration) AttrProtocolVersion(val string) attribute.KeyValue {
return attribute.String("mcp.protocol.version", val)
}
// AttrNetworkProtocolName returns an optional attribute for the
// "network.protocol.name" semantic convention. It represents the
// [OSI application layer] or non-OSI equivalent.
//
// [OSI application layer]: https://wikipedia.org/wiki/Application_layer
func (ServerSessionDuration) AttrNetworkProtocolName(val string) attribute.KeyValue {
return attribute.String("network.protocol.name", val)
}
// AttrNetworkProtocolVersion returns an optional attribute for the
// "network.protocol.version" semantic convention. It represents the actual
// version of the protocol used for network communication.
func (ServerSessionDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
return attribute.String("network.protocol.version", val)
}
// AttrNetworkTransport returns an optional attribute for the "network.transport"
// semantic convention. It represents the transport protocol used for the MCP
// session.
func (ServerSessionDuration) AttrNetworkTransport(val NetworkTransportAttr) attribute.KeyValue {
return attribute.String("network.transport", string(val))
}
+799
View File
@@ -0,0 +1,799 @@
// Code generated from semantic convention specification. DO NOT EDIT.
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Package messagingconv provides types and functionality for OpenTelemetry semantic
// conventions in the "messaging" namespace.
package messagingconv
import (
"context"
"sync"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
)
var (
addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }}
recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }}
)
// ErrorTypeAttr is an attribute conforming to the error.type semantic
// conventions. It represents the describes a class of error the operation ended
// with.
type ErrorTypeAttr string
var (
// ErrorTypeOther is a fallback error value to be used when the instrumentation
// doesn't define a custom value.
ErrorTypeOther ErrorTypeAttr = "_OTHER"
)
// OperationTypeAttr is an attribute conforming to the messaging.operation.type
// semantic conventions. It represents a string identifying the type of the
// messaging operation.
type OperationTypeAttr string
var (
// OperationTypeCreate is a message is created. "Create" spans always refer to a
// single message and are used to provide a unique creation context for messages
// in batch sending scenarios.
OperationTypeCreate OperationTypeAttr = "create"
// OperationTypeSend is the one or more messages are provided for sending to an
// intermediary. If a single message is sent, the context of the "Send" span can
// be used as the creation context and no "Create" span needs to be created.
OperationTypeSend OperationTypeAttr = "send"
// OperationTypeReceive is the one or more messages are requested by a consumer.
// This operation refers to pull-based scenarios, where consumers explicitly
// call methods of messaging SDKs to receive messages.
OperationTypeReceive OperationTypeAttr = "receive"
// OperationTypeProcess is the one or more messages are processed by a consumer.
OperationTypeProcess OperationTypeAttr = "process"
// OperationTypeSettle is the one or more messages are settled.
OperationTypeSettle OperationTypeAttr = "settle"
)
// SystemAttr is an attribute conforming to the messaging.system semantic
// conventions. It represents the messaging system as identified by the client
// instrumentation.
type SystemAttr string
var (
// SystemActiveMQ is the apache ActiveMQ.
SystemActiveMQ SystemAttr = "activemq"
// SystemAWSSNS is the amazon Simple Notification Service (SNS).
SystemAWSSNS SystemAttr = "aws.sns"
// SystemAWSSQS is the amazon Simple Queue Service (SQS).
SystemAWSSQS SystemAttr = "aws_sqs"
// SystemEventGrid is the azure Event Grid.
SystemEventGrid SystemAttr = "eventgrid"
// SystemEventHubs is the azure Event Hubs.
SystemEventHubs SystemAttr = "eventhubs"
// SystemServiceBus is the azure Service Bus.
SystemServiceBus SystemAttr = "servicebus"
// SystemGCPPubSub is the google Cloud Pub/Sub.
SystemGCPPubSub SystemAttr = "gcp_pubsub"
// SystemJMS is the java Message Service.
SystemJMS SystemAttr = "jms"
// SystemKafka is the apache Kafka.
SystemKafka SystemAttr = "kafka"
// SystemRabbitMQ is the rabbitMQ.
SystemRabbitMQ SystemAttr = "rabbitmq"
// SystemRocketMQ is the apache RocketMQ.
SystemRocketMQ SystemAttr = "rocketmq"
// SystemPulsar is the apache Pulsar.
SystemPulsar SystemAttr = "pulsar"
)
// ClientConsumedMessages is an instrument used to record metric values
// conforming to the "messaging.client.consumed.messages" semantic conventions.
// It represents the number of messages that were delivered to the application.
type ClientConsumedMessages struct {
metric.Int64Counter
}
var newClientConsumedMessagesOpts = []metric.Int64CounterOption{
metric.WithDescription("Number of messages that were delivered to the application."),
metric.WithUnit("{message}"),
}
// NewClientConsumedMessages returns a new ClientConsumedMessages instrument.
func NewClientConsumedMessages(
m metric.Meter,
opt ...metric.Int64CounterOption,
) (ClientConsumedMessages, error) {
// Check if the meter is nil.
if m == nil {
return ClientConsumedMessages{noop.Int64Counter{}}, nil
}
if len(opt) == 0 {
opt = newClientConsumedMessagesOpts
} else {
opt = append(opt, newClientConsumedMessagesOpts...)
}
i, err := m.Int64Counter(
"messaging.client.consumed.messages",
opt...,
)
if err != nil {
return ClientConsumedMessages{noop.Int64Counter{}}, err
}
return ClientConsumedMessages{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ClientConsumedMessages) Inst() metric.Int64Counter {
return m.Int64Counter
}
// Name returns the semantic convention name of the instrument.
func (ClientConsumedMessages) Name() string {
return "messaging.client.consumed.messages"
}
// Unit returns the semantic convention unit of the instrument
func (ClientConsumedMessages) Unit() string {
return "{message}"
}
// Description returns the semantic convention description of the instrument
func (ClientConsumedMessages) Description() string {
return "Number of messages that were delivered to the application."
}
// Add adds incr to the existing count for attrs.
//
// The operationName is the the system-specific name of the messaging operation.
//
// The system is the the messaging system as identified by the client
// instrumentation.
//
// All additional attrs passed are included in the recorded value.
//
// Records the number of messages pulled from the broker or number of messages
// dispatched to the application in push-based scenarios.
// The metric SHOULD be reported once per message delivery. For example, if
// receiving and processing operations are both instrumented for a single message
// delivery, this counter is incremented when the message is received and not
// reported when it is processed.
func (m ClientConsumedMessages) Add(
ctx context.Context,
incr int64,
operationName string,
system SystemAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Int64Counter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("messaging.operation.name", operationName),
attribute.String("messaging.system", string(system)),
)...,
),
)
m.Int64Counter.Add(ctx, incr, *o...)
}
// AddSet adds incr to the existing count for set.
//
// Records the number of messages pulled from the broker or number of messages
// dispatched to the application in push-based scenarios.
// The metric SHOULD be reported once per message delivery. For example, if
// receiving and processing operations are both instrumented for a single message
// delivery, this counter is incremented when the message is received and not
// reported when it is processed.
func (m ClientConsumedMessages) AddSet(ctx context.Context, incr int64, set attribute.Set) {
if set.Len() == 0 {
m.Int64Counter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Int64Counter.Add(ctx, incr, *o...)
}
// AttrErrorType returns an optional attribute for the "error.type" semantic
// convention. It represents the describes a class of error the operation ended
// with.
func (ClientConsumedMessages) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// AttrConsumerGroupName returns an optional attribute for the
// "messaging.consumer.group.name" semantic convention. It represents the name of
// the consumer group with which a consumer is associated.
func (ClientConsumedMessages) AttrConsumerGroupName(val string) attribute.KeyValue {
return attribute.String("messaging.consumer.group.name", val)
}
// AttrDestinationName returns an optional attribute for the
// "messaging.destination.name" semantic convention. It represents the message
// destination name.
func (ClientConsumedMessages) AttrDestinationName(val string) attribute.KeyValue {
return attribute.String("messaging.destination.name", val)
}
// AttrDestinationSubscriptionName returns an optional attribute for the
// "messaging.destination.subscription.name" semantic convention. It represents
// the name of the destination subscription from which a message is consumed.
func (ClientConsumedMessages) AttrDestinationSubscriptionName(val string) attribute.KeyValue {
return attribute.String("messaging.destination.subscription.name", val)
}
// AttrDestinationTemplate returns an optional attribute for the
// "messaging.destination.template" semantic convention. It represents the low
// cardinality representation of the messaging destination name.
func (ClientConsumedMessages) AttrDestinationTemplate(val string) attribute.KeyValue {
return attribute.String("messaging.destination.template", val)
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents the server domain name if available without
// reverse DNS lookup; otherwise, IP address or Unix domain socket name.
func (ClientConsumedMessages) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
// AttrDestinationPartitionID returns an optional attribute for the
// "messaging.destination.partition.id" semantic convention. It represents the
// identifier of the partition messages are sent to or received from, unique
// within the `messaging.destination.name`.
func (ClientConsumedMessages) AttrDestinationPartitionID(val string) attribute.KeyValue {
return attribute.String("messaging.destination.partition.id", val)
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the server port number.
func (ClientConsumedMessages) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
// ClientOperationDuration is an instrument used to record metric values
// conforming to the "messaging.client.operation.duration" semantic conventions.
// It represents the duration of messaging operation initiated by a producer or
// consumer client.
type ClientOperationDuration struct {
metric.Float64Histogram
}
var newClientOperationDurationOpts = []metric.Float64HistogramOption{
metric.WithDescription("Duration of messaging operation initiated by a producer or consumer client."),
metric.WithUnit("s"),
}
// NewClientOperationDuration returns a new ClientOperationDuration instrument.
func NewClientOperationDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (ClientOperationDuration, error) {
// Check if the meter is nil.
if m == nil {
return ClientOperationDuration{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newClientOperationDurationOpts
} else {
opt = append(opt, newClientOperationDurationOpts...)
}
i, err := m.Float64Histogram(
"messaging.client.operation.duration",
opt...,
)
if err != nil {
return ClientOperationDuration{noop.Float64Histogram{}}, err
}
return ClientOperationDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ClientOperationDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ClientOperationDuration) Name() string {
return "messaging.client.operation.duration"
}
// Unit returns the semantic convention unit of the instrument
func (ClientOperationDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (ClientOperationDuration) Description() string {
return "Duration of messaging operation initiated by a producer or consumer client."
}
// Record records val to the current distribution for attrs.
//
// The operationName is the the system-specific name of the messaging operation.
//
// The system is the the messaging system as identified by the client
// instrumentation.
//
// All additional attrs passed are included in the recorded value.
//
// This metric SHOULD NOT be used to report processing duration - processing
// duration is reported in `messaging.process.duration` metric.
func (m ClientOperationDuration) Record(
ctx context.Context,
val float64,
operationName string,
system SystemAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("messaging.operation.name", operationName),
attribute.String("messaging.system", string(system)),
)...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
//
// This metric SHOULD NOT be used to report processing duration - processing
// duration is reported in `messaging.process.duration` metric.
func (m ClientOperationDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// 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) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// AttrConsumerGroupName returns an optional attribute for the
// "messaging.consumer.group.name" semantic convention. It represents the name of
// the consumer group with which a consumer is associated.
func (ClientOperationDuration) AttrConsumerGroupName(val string) attribute.KeyValue {
return attribute.String("messaging.consumer.group.name", val)
}
// AttrDestinationName returns an optional attribute for the
// "messaging.destination.name" semantic convention. It represents the message
// destination name.
func (ClientOperationDuration) AttrDestinationName(val string) attribute.KeyValue {
return attribute.String("messaging.destination.name", val)
}
// AttrDestinationSubscriptionName returns an optional attribute for the
// "messaging.destination.subscription.name" semantic convention. It represents
// the name of the destination subscription from which a message is consumed.
func (ClientOperationDuration) AttrDestinationSubscriptionName(val string) attribute.KeyValue {
return attribute.String("messaging.destination.subscription.name", val)
}
// AttrDestinationTemplate returns an optional attribute for the
// "messaging.destination.template" semantic convention. It represents the low
// cardinality representation of the messaging destination name.
func (ClientOperationDuration) AttrDestinationTemplate(val string) attribute.KeyValue {
return attribute.String("messaging.destination.template", val)
}
// AttrOperationType returns an optional attribute for the
// "messaging.operation.type" semantic convention. It represents a string
// identifying the type of the messaging operation.
func (ClientOperationDuration) AttrOperationType(val OperationTypeAttr) attribute.KeyValue {
return attribute.String("messaging.operation.type", string(val))
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents the server domain name if available without
// reverse DNS lookup; otherwise, IP address or Unix domain socket name.
func (ClientOperationDuration) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
// AttrDestinationPartitionID returns an optional attribute for the
// "messaging.destination.partition.id" semantic convention. It represents the
// identifier of the partition messages are sent to or received from, unique
// within the `messaging.destination.name`.
func (ClientOperationDuration) AttrDestinationPartitionID(val string) attribute.KeyValue {
return attribute.String("messaging.destination.partition.id", val)
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the server port number.
func (ClientOperationDuration) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
// ClientSentMessages is an instrument used to record metric values conforming to
// the "messaging.client.sent.messages" semantic conventions. It represents the
// number of messages producer attempted to send to the broker.
type ClientSentMessages struct {
metric.Int64Counter
}
var newClientSentMessagesOpts = []metric.Int64CounterOption{
metric.WithDescription("Number of messages producer attempted to send to the broker."),
metric.WithUnit("{message}"),
}
// NewClientSentMessages returns a new ClientSentMessages instrument.
func NewClientSentMessages(
m metric.Meter,
opt ...metric.Int64CounterOption,
) (ClientSentMessages, error) {
// Check if the meter is nil.
if m == nil {
return ClientSentMessages{noop.Int64Counter{}}, nil
}
if len(opt) == 0 {
opt = newClientSentMessagesOpts
} else {
opt = append(opt, newClientSentMessagesOpts...)
}
i, err := m.Int64Counter(
"messaging.client.sent.messages",
opt...,
)
if err != nil {
return ClientSentMessages{noop.Int64Counter{}}, err
}
return ClientSentMessages{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ClientSentMessages) Inst() metric.Int64Counter {
return m.Int64Counter
}
// Name returns the semantic convention name of the instrument.
func (ClientSentMessages) Name() string {
return "messaging.client.sent.messages"
}
// Unit returns the semantic convention unit of the instrument
func (ClientSentMessages) Unit() string {
return "{message}"
}
// Description returns the semantic convention description of the instrument
func (ClientSentMessages) Description() string {
return "Number of messages producer attempted to send to the broker."
}
// Add adds incr to the existing count for attrs.
//
// The operationName is the the system-specific name of the messaging operation.
//
// The system is the the messaging system as identified by the client
// instrumentation.
//
// All additional attrs passed are included in the recorded value.
//
// This metric MUST NOT count messages that were created but haven't yet been
// sent.
func (m ClientSentMessages) Add(
ctx context.Context,
incr int64,
operationName string,
system SystemAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Int64Counter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("messaging.operation.name", operationName),
attribute.String("messaging.system", string(system)),
)...,
),
)
m.Int64Counter.Add(ctx, incr, *o...)
}
// AddSet adds incr to the existing count for set.
//
// This metric MUST NOT count messages that were created but haven't yet been
// sent.
func (m ClientSentMessages) AddSet(ctx context.Context, incr int64, set attribute.Set) {
if set.Len() == 0 {
m.Int64Counter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Int64Counter.Add(ctx, incr, *o...)
}
// AttrErrorType returns an optional attribute for the "error.type" semantic
// convention. It represents the describes a class of error the operation ended
// with.
func (ClientSentMessages) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// AttrDestinationName returns an optional attribute for the
// "messaging.destination.name" semantic convention. It represents the message
// destination name.
func (ClientSentMessages) AttrDestinationName(val string) attribute.KeyValue {
return attribute.String("messaging.destination.name", val)
}
// AttrDestinationTemplate returns an optional attribute for the
// "messaging.destination.template" semantic convention. It represents the low
// cardinality representation of the messaging destination name.
func (ClientSentMessages) AttrDestinationTemplate(val string) attribute.KeyValue {
return attribute.String("messaging.destination.template", val)
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents the server domain name if available without
// reverse DNS lookup; otherwise, IP address or Unix domain socket name.
func (ClientSentMessages) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
// AttrDestinationPartitionID returns an optional attribute for the
// "messaging.destination.partition.id" semantic convention. It represents the
// identifier of the partition messages are sent to or received from, unique
// within the `messaging.destination.name`.
func (ClientSentMessages) AttrDestinationPartitionID(val string) attribute.KeyValue {
return attribute.String("messaging.destination.partition.id", val)
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the server port number.
func (ClientSentMessages) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
// ProcessDuration is an instrument used to record metric values conforming to
// the "messaging.process.duration" semantic conventions. It represents the
// duration of processing operation.
type ProcessDuration struct {
metric.Float64Histogram
}
var newProcessDurationOpts = []metric.Float64HistogramOption{
metric.WithDescription("Duration of processing operation."),
metric.WithUnit("s"),
}
// NewProcessDuration returns a new ProcessDuration instrument.
func NewProcessDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (ProcessDuration, error) {
// Check if the meter is nil.
if m == nil {
return ProcessDuration{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newProcessDurationOpts
} else {
opt = append(opt, newProcessDurationOpts...)
}
i, err := m.Float64Histogram(
"messaging.process.duration",
opt...,
)
if err != nil {
return ProcessDuration{noop.Float64Histogram{}}, err
}
return ProcessDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ProcessDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ProcessDuration) Name() string {
return "messaging.process.duration"
}
// Unit returns the semantic convention unit of the instrument
func (ProcessDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (ProcessDuration) Description() string {
return "Duration of processing operation."
}
// Record records val to the current distribution for attrs.
//
// The operationName is the the system-specific name of the messaging operation.
//
// The system is the the messaging system as identified by the client
// instrumentation.
//
// All additional attrs passed are included in the recorded value.
//
// This metric MUST be reported for operations with `messaging.operation.type`
// that matches `process`.
func (m ProcessDuration) Record(
ctx context.Context,
val float64,
operationName string,
system SystemAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("messaging.operation.name", operationName),
attribute.String("messaging.system", string(system)),
)...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
//
// This metric MUST be reported for operations with `messaging.operation.type`
// that matches `process`.
func (m ProcessDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// AttrErrorType returns an optional attribute for the "error.type" semantic
// convention. It represents the describes a class of error the operation ended
// with.
func (ProcessDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// AttrConsumerGroupName returns an optional attribute for the
// "messaging.consumer.group.name" semantic convention. It represents the name of
// the consumer group with which a consumer is associated.
func (ProcessDuration) AttrConsumerGroupName(val string) attribute.KeyValue {
return attribute.String("messaging.consumer.group.name", val)
}
// AttrDestinationName returns an optional attribute for the
// "messaging.destination.name" semantic convention. It represents the message
// destination name.
func (ProcessDuration) AttrDestinationName(val string) attribute.KeyValue {
return attribute.String("messaging.destination.name", val)
}
// AttrDestinationSubscriptionName returns an optional attribute for the
// "messaging.destination.subscription.name" semantic convention. It represents
// the name of the destination subscription from which a message is consumed.
func (ProcessDuration) AttrDestinationSubscriptionName(val string) attribute.KeyValue {
return attribute.String("messaging.destination.subscription.name", val)
}
// AttrDestinationTemplate returns an optional attribute for the
// "messaging.destination.template" semantic convention. It represents the low
// cardinality representation of the messaging destination name.
func (ProcessDuration) AttrDestinationTemplate(val string) attribute.KeyValue {
return attribute.String("messaging.destination.template", val)
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents the server domain name if available without
// reverse DNS lookup; otherwise, IP address or Unix domain socket name.
func (ProcessDuration) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
// AttrDestinationPartitionID returns an optional attribute for the
// "messaging.destination.partition.id" semantic convention. It represents the
// identifier of the partition messages are sent to or received from, unique
// within the `messaging.destination.name`.
func (ProcessDuration) AttrDestinationPartitionID(val string) attribute.KeyValue {
return attribute.String("messaging.destination.partition.id", val)
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the server port number.
func (ProcessDuration) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+356
View File
@@ -0,0 +1,356 @@
// Code generated from semantic convention specification. DO NOT EDIT.
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Package rpcconv provides types and functionality for OpenTelemetry semantic
// conventions in the "rpc" namespace.
package rpcconv
import (
"context"
"sync"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
)
var (
addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }}
recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }}
)
// ErrorTypeAttr is an attribute conforming to the error.type semantic
// conventions. It represents the describes a class of error the operation ended
// with.
type ErrorTypeAttr string
var (
// ErrorTypeOther is a fallback error value to be used when the instrumentation
// doesn't define a custom value.
ErrorTypeOther ErrorTypeAttr = "_OTHER"
)
// SystemNameAttr is an attribute conforming to the rpc.system.name semantic
// conventions. It represents the Remote Procedure Call (RPC) system.
type SystemNameAttr string
var (
// SystemNameGRPC is the [gRPC].
//
// [gRPC]: https://grpc.io/
SystemNameGRPC SystemNameAttr = "grpc"
// SystemNameDubbo is the [Apache Dubbo].
//
// [Apache Dubbo]: https://dubbo.apache.org/
SystemNameDubbo SystemNameAttr = "dubbo"
// SystemNameConnectrpc is the [Connect RPC].
//
// [Connect RPC]: https://connectrpc.com/
SystemNameConnectrpc SystemNameAttr = "connectrpc"
// SystemNameJSONRPC is the [JSON-RPC].
//
// [JSON-RPC]: https://www.jsonrpc.org/
SystemNameJSONRPC SystemNameAttr = "jsonrpc"
)
// ClientCallDuration is an instrument used to record metric values conforming to
// the "rpc.client.call.duration" semantic conventions. It represents the
// measures the duration of an outgoing Remote Procedure Call (RPC).
type ClientCallDuration struct {
metric.Float64Histogram
}
var newClientCallDurationOpts = []metric.Float64HistogramOption{
metric.WithDescription("Measures the duration of an outgoing Remote Procedure Call (RPC)."),
metric.WithUnit("s"),
}
// NewClientCallDuration returns a new ClientCallDuration instrument.
func NewClientCallDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (ClientCallDuration, error) {
// Check if the meter is nil.
if m == nil {
return ClientCallDuration{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newClientCallDurationOpts
} else {
opt = append(opt, newClientCallDurationOpts...)
}
i, err := m.Float64Histogram(
"rpc.client.call.duration",
opt...,
)
if err != nil {
return ClientCallDuration{noop.Float64Histogram{}}, err
}
return ClientCallDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ClientCallDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ClientCallDuration) Name() string {
return "rpc.client.call.duration"
}
// Unit returns the semantic convention unit of the instrument
func (ClientCallDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (ClientCallDuration) Description() string {
return "Measures the duration of an outgoing Remote Procedure Call (RPC)."
}
// Record records val to the current distribution for attrs.
//
// The systemName is the the Remote Procedure Call (RPC) system.
//
// All additional attrs passed are included in the recorded value.
//
// When this metric is reported alongside an RPC client span, the metric value
// SHOULD be the same as the RPC client span duration.
func (m ClientCallDuration) Record(
ctx context.Context,
val float64,
systemName SystemNameAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("rpc.system.name", string(systemName)),
)...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
//
// When this metric is reported alongside an RPC client span, the metric value
// SHOULD be the same as the RPC client span duration.
func (m ClientCallDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// AttrErrorType returns an optional attribute for the "error.type" semantic
// convention. It represents the describes a class of error the operation ended
// with.
func (ClientCallDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// AttrMethod returns an optional attribute for the "rpc.method" semantic
// convention. It represents the fully-qualified logical name of the method from
// the RPC interface perspective.
func (ClientCallDuration) AttrMethod(val string) attribute.KeyValue {
return attribute.String("rpc.method", val)
}
// AttrResponseStatusCode returns an optional attribute for the
// "rpc.response.status_code" semantic convention. It represents the status code
// of the RPC returned by the RPC server or generated by the client.
func (ClientCallDuration) AttrResponseStatusCode(val string) attribute.KeyValue {
return attribute.String("rpc.response.status_code", val)
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents a string identifying a group of RPC server
// instances request is sent to.
func (ClientCallDuration) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the server port number.
func (ClientCallDuration) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
// ServerCallDuration is an instrument used to record metric values conforming to
// the "rpc.server.call.duration" semantic conventions. It represents the
// measures the duration of an incoming Remote Procedure Call (RPC).
type ServerCallDuration struct {
metric.Float64Histogram
}
var newServerCallDurationOpts = []metric.Float64HistogramOption{
metric.WithDescription("Measures the duration of an incoming Remote Procedure Call (RPC)."),
metric.WithUnit("s"),
}
// NewServerCallDuration returns a new ServerCallDuration instrument.
func NewServerCallDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (ServerCallDuration, error) {
// Check if the meter is nil.
if m == nil {
return ServerCallDuration{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newServerCallDurationOpts
} else {
opt = append(opt, newServerCallDurationOpts...)
}
i, err := m.Float64Histogram(
"rpc.server.call.duration",
opt...,
)
if err != nil {
return ServerCallDuration{noop.Float64Histogram{}}, err
}
return ServerCallDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ServerCallDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ServerCallDuration) Name() string {
return "rpc.server.call.duration"
}
// Unit returns the semantic convention unit of the instrument
func (ServerCallDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (ServerCallDuration) Description() string {
return "Measures the duration of an incoming Remote Procedure Call (RPC)."
}
// Record records val to the current distribution for attrs.
//
// The systemName is the the Remote Procedure Call (RPC) system.
//
// All additional attrs passed are included in the recorded value.
//
// When this metric is reported alongside an RPC server span, the metric value
// SHOULD be the same as the RPC server span duration.
func (m ServerCallDuration) Record(
ctx context.Context,
val float64,
systemName SystemNameAttr,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("rpc.system.name", string(systemName)),
)...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
//
// When this metric is reported alongside an RPC server span, the metric value
// SHOULD be the same as the RPC server span duration.
func (m ServerCallDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// AttrErrorType returns an optional attribute for the "error.type" semantic
// convention. It represents the describes a class of error the operation ended
// with.
func (ServerCallDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// AttrMethod returns an optional attribute for the "rpc.method" semantic
// convention. It represents the fully-qualified logical name of the method from
// the RPC interface perspective.
func (ServerCallDuration) AttrMethod(val string) attribute.KeyValue {
return attribute.String("rpc.method", val)
}
// AttrResponseStatusCode returns an optional attribute for the
// "rpc.response.status_code" semantic convention. It represents the status code
// of the RPC returned by the RPC server or generated by the client.
func (ServerCallDuration) AttrResponseStatusCode(val string) attribute.KeyValue {
return attribute.String("rpc.response.status_code", val)
}
// AttrServerAddress returns an optional attribute for the "server.address"
// semantic convention. It represents a string identifying a group of RPC server
// instances request is sent to.
func (ServerCallDuration) AttrServerAddress(val string) attribute.KeyValue {
return attribute.String("server.address", val)
}
// AttrServerPort returns an optional attribute for the "server.port" semantic
// convention. It represents the server port number.
func (ServerCallDuration) AttrServerPort(val int) attribute.KeyValue {
return attribute.Int("server.port", val)
}
+9
View File
@@ -0,0 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package semconv // import "go.opentelemetry.io/otel/semconv/v1.40.0"
// SchemaURL is the schema URL that matches the version of the semantic conventions
// that this package defines. Semconv packages starting from v1.4.0 must declare
// non-empty schema URL in the form https://opentelemetry.io/schemas/<version>
const SchemaURL = "https://opentelemetry.io/schemas/1.40.0"
+302
View File
@@ -0,0 +1,302 @@
// Code generated from semantic convention specification. DO NOT EDIT.
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Package signalrconv provides types and functionality for OpenTelemetry semantic
// conventions in the "signalr" namespace.
package signalrconv
import (
"context"
"sync"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
)
var (
addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }}
recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }}
)
// ConnectionStatusAttr is an attribute conforming to the
// signalr.connection.status semantic conventions. It represents the signalR HTTP
// connection closure status.
type ConnectionStatusAttr string
var (
// ConnectionStatusNormalClosure is the connection was closed normally.
ConnectionStatusNormalClosure ConnectionStatusAttr = "normal_closure"
// ConnectionStatusTimeout is the connection was closed due to a timeout.
ConnectionStatusTimeout ConnectionStatusAttr = "timeout"
// ConnectionStatusAppShutdown is the connection was closed because the app is
// shutting down.
ConnectionStatusAppShutdown ConnectionStatusAttr = "app_shutdown"
)
// TransportAttr is an attribute conforming to the signalr.transport semantic
// conventions. It represents the [SignalR transport type].
//
// [SignalR transport type]: https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/docs/specs/TransportProtocols.md
type TransportAttr string
var (
// TransportServerSentEvents is the serverSentEvents protocol.
TransportServerSentEvents TransportAttr = "server_sent_events"
// TransportLongPolling is the longPolling protocol.
TransportLongPolling TransportAttr = "long_polling"
// TransportWebSockets is the webSockets protocol.
TransportWebSockets TransportAttr = "web_sockets"
)
// ServerActiveConnections is an instrument used to record metric values
// conforming to the "signalr.server.active_connections" semantic conventions. It
// represents the number of connections that are currently active on the server.
type ServerActiveConnections struct {
metric.Int64UpDownCounter
}
var newServerActiveConnectionsOpts = []metric.Int64UpDownCounterOption{
metric.WithDescription("Number of connections that are currently active on the server."),
metric.WithUnit("{connection}"),
}
// NewServerActiveConnections returns a new ServerActiveConnections instrument.
func NewServerActiveConnections(
m metric.Meter,
opt ...metric.Int64UpDownCounterOption,
) (ServerActiveConnections, error) {
// Check if the meter is nil.
if m == nil {
return ServerActiveConnections{noop.Int64UpDownCounter{}}, nil
}
if len(opt) == 0 {
opt = newServerActiveConnectionsOpts
} else {
opt = append(opt, newServerActiveConnectionsOpts...)
}
i, err := m.Int64UpDownCounter(
"signalr.server.active_connections",
opt...,
)
if err != nil {
return ServerActiveConnections{noop.Int64UpDownCounter{}}, err
}
return ServerActiveConnections{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ServerActiveConnections) Inst() metric.Int64UpDownCounter {
return m.Int64UpDownCounter
}
// Name returns the semantic convention name of the instrument.
func (ServerActiveConnections) Name() string {
return "signalr.server.active_connections"
}
// Unit returns the semantic convention unit of the instrument
func (ServerActiveConnections) Unit() string {
return "{connection}"
}
// Description returns the semantic convention description of the instrument
func (ServerActiveConnections) Description() string {
return "Number of connections that are currently active on the server."
}
// Add adds incr to the existing count for attrs.
//
// All additional attrs passed are included in the recorded value.
//
// Meter name: `Microsoft.AspNetCore.Http.Connections`; Added in: ASP.NET Core
// 8.0
func (m ServerActiveConnections) Add(
ctx context.Context,
incr int64,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Int64UpDownCounter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
attrs...,
),
)
m.Int64UpDownCounter.Add(ctx, incr, *o...)
}
// AddSet adds incr to the existing count for set.
//
// Meter name: `Microsoft.AspNetCore.Http.Connections`; Added in: ASP.NET Core
// 8.0
func (m ServerActiveConnections) AddSet(ctx context.Context, incr int64, set attribute.Set) {
if set.Len() == 0 {
m.Int64UpDownCounter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Int64UpDownCounter.Add(ctx, incr, *o...)
}
// AttrConnectionStatus returns an optional attribute for the
// "signalr.connection.status" semantic convention. It represents the signalR
// HTTP connection closure status.
func (ServerActiveConnections) AttrConnectionStatus(val ConnectionStatusAttr) attribute.KeyValue {
return attribute.String("signalr.connection.status", string(val))
}
// AttrTransport returns an optional attribute for the "signalr.transport"
// semantic convention. It represents the [SignalR transport type].
//
// [SignalR transport type]: https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/docs/specs/TransportProtocols.md
func (ServerActiveConnections) AttrTransport(val TransportAttr) attribute.KeyValue {
return attribute.String("signalr.transport", string(val))
}
// ServerConnectionDuration is an instrument used to record metric values
// conforming to the "signalr.server.connection.duration" semantic conventions.
// It represents the duration of connections on the server.
type ServerConnectionDuration struct {
metric.Float64Histogram
}
var newServerConnectionDurationOpts = []metric.Float64HistogramOption{
metric.WithDescription("The duration of connections on the server."),
metric.WithUnit("s"),
}
// NewServerConnectionDuration returns a new ServerConnectionDuration instrument.
func NewServerConnectionDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (ServerConnectionDuration, error) {
// Check if the meter is nil.
if m == nil {
return ServerConnectionDuration{noop.Float64Histogram{}}, nil
}
if len(opt) == 0 {
opt = newServerConnectionDurationOpts
} else {
opt = append(opt, newServerConnectionDurationOpts...)
}
i, err := m.Float64Histogram(
"signalr.server.connection.duration",
opt...,
)
if err != nil {
return ServerConnectionDuration{noop.Float64Histogram{}}, err
}
return ServerConnectionDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m ServerConnectionDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (ServerConnectionDuration) Name() string {
return "signalr.server.connection.duration"
}
// Unit returns the semantic convention unit of the instrument
func (ServerConnectionDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (ServerConnectionDuration) Description() string {
return "The duration of connections on the server."
}
// Record records val to the current distribution for attrs.
//
// All additional attrs passed are included in the recorded value.
//
// Meter name: `Microsoft.AspNetCore.Http.Connections`; Added in: ASP.NET Core
// 8.0
func (m ServerConnectionDuration) Record(
ctx context.Context,
val float64,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
attrs...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// RecordSet records val to the current distribution for set.
//
// Meter name: `Microsoft.AspNetCore.Http.Connections`; Added in: ASP.NET Core
// 8.0
func (m ServerConnectionDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
if set.Len() == 0 {
m.Float64Histogram.Record(ctx, val)
return
}
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(*o, metric.WithAttributeSet(set))
m.Float64Histogram.Record(ctx, val, *o...)
}
// AttrConnectionStatus returns an optional attribute for the
// "signalr.connection.status" semantic convention. It represents the signalR
// HTTP connection closure status.
func (ServerConnectionDuration) AttrConnectionStatus(val ConnectionStatusAttr) attribute.KeyValue {
return attribute.String("signalr.connection.status", string(val))
}
// AttrTransport returns an optional attribute for the "signalr.transport"
// semantic convention. It represents the [SignalR transport type].
//
// [SignalR transport type]: https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/docs/specs/TransportProtocols.md
func (ServerConnectionDuration) AttrTransport(val TransportAttr) attribute.KeyValue {
return attribute.String("signalr.transport", string(val))
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff