You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
0b47699705
The current design of the packages is for ergonomics, and it works well at this. However, it is not the most performant. When a user passes a slice of attributes it will use [`metric.WithAttributes`](https://github.com/open-telemetry/opentelemetry-go/blob/cf787f3e3ad0093985b0834eaf63ceb679705545/metric/instrument.go#L372-L376): ```go func WithAttributes(attributes ...attribute.KeyValue) MeasurementOption { cp := make([]attribute.KeyValue, len(attributes)) copy(cp, attributes) return attrOpt{set: attribute.NewSet(cp...)} } ``` This will copy the passed attributes and then pass that copy to `attribute.NewSet` which adds its own allocation. If a user is performance conscious and already have a set, allow them to pass it directly and reduce the required allocations for the measurement call. ## Alternatives Considered ### Why not allow users to just use `Inst()` method? With the current design a user can still just call: ```go counter.Inst().Add(ctx, val, metric.WithAttributeSet(set)) ``` However, the option slice (in this case `[]metric.AddOption`) is allocated on the call. Meaning a user will also need to recreate the pooling that our semconv generated packages already handle. Providing the `*Set` methods is convenient, but it also helps the application performance as one larger pool will be less strain on the GC than many smaller ones. ### Why not just call `WithAttributeSet` in the existing methods? Instead of appending a `WithAttributes` option internal to all the measurement methods, we could also just create a `Set` and pass that with `WithAttributeSet`. This will avoid the additional slice copy that `WithAttributes` does on top of calling `attribute.NewSet`. However, this copy that `WithAttributes` does is important as calling `attribute.NewSet` will sort the original slice. Bypassing that will mean all the passed attribute slices will be modified when used. This is not great as it is likely going to be unexpected behavior by the user, and is the reason we copy the slice in `WithAttributes` in the first place. ### Why not just copy user attributes to an amortized slice pool to create a new `attribute.Set`? The additional creation of an `[]attribute.KeyValue` that user attributes are copied to in order to prevent modification can be amortized with a pool. For example, #7249. There shouldn't be any difference than between calling a `*Set` method introduced here vs the non-`Set` method. This is true, and motivates this type of change. However, also providing these additional methods allows the user additional performance gains if the set is used for more than one measurement. For example: ```go set := attributes.NewSet(attrs) counter1.AddSet(ctx, 1, set) counter2.AddSet(ctx, 2, set) // No additional set is created here. ``` Without these methods: ```go counter1.Add(ctx, 1, attrs...) // A set is created for attrs counter2.Add(ctx, 2, attrs...) // Another set is created for attrs ``` Each `attribute.Set` created will require an allocation (i.e. the internal `any` field needs to be allocated to the heap). Meaning without these methods a user will still not be able to write the most performant code. The attribute pool approach has merit, and should be pursued. However, it does not invalidate the value of these changes.
696 lines
18 KiB
Go
696 lines
18 KiB
Go
// Code generated from semantic convention specification. DO NOT EDIT.
|
|
|
|
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Package httpconv provides types and functionality for OpenTelemetry semantic
|
|
// conventions in the "container" namespace.
|
|
package containerconv
|
|
|
|
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{} }}
|
|
)
|
|
|
|
// CPUModeAttr is an attribute conforming to the cpu.mode semantic conventions.
|
|
// It represents the CPU mode for this data point. A container's CPU metric
|
|
// SHOULD be characterized *either* by data points with no `mode` labels,
|
|
// *or only* data points with `mode` labels.
|
|
type CPUModeAttr string
|
|
|
|
var (
|
|
// CPUModeUser is the standardized value "user" of CPUModeAttr.
|
|
CPUModeUser CPUModeAttr = "user"
|
|
// CPUModeSystem is the standardized value "system" of CPUModeAttr.
|
|
CPUModeSystem CPUModeAttr = "system"
|
|
// CPUModeNice is the standardized value "nice" of CPUModeAttr.
|
|
CPUModeNice CPUModeAttr = "nice"
|
|
// CPUModeIdle is the standardized value "idle" of CPUModeAttr.
|
|
CPUModeIdle CPUModeAttr = "idle"
|
|
// CPUModeIOWait is the standardized value "iowait" of CPUModeAttr.
|
|
CPUModeIOWait CPUModeAttr = "iowait"
|
|
// CPUModeInterrupt is the standardized value "interrupt" of CPUModeAttr.
|
|
CPUModeInterrupt CPUModeAttr = "interrupt"
|
|
// CPUModeSteal is the standardized value "steal" of CPUModeAttr.
|
|
CPUModeSteal CPUModeAttr = "steal"
|
|
// CPUModeKernel is the standardized value "kernel" of CPUModeAttr.
|
|
CPUModeKernel CPUModeAttr = "kernel"
|
|
)
|
|
|
|
// DiskIODirectionAttr is an attribute conforming to the disk.io.direction
|
|
// semantic conventions. It represents the disk IO operation direction.
|
|
type DiskIODirectionAttr string
|
|
|
|
var (
|
|
// DiskIODirectionRead is the standardized value "read" of DiskIODirectionAttr.
|
|
DiskIODirectionRead DiskIODirectionAttr = "read"
|
|
// DiskIODirectionWrite is the standardized value "write" of
|
|
// DiskIODirectionAttr.
|
|
DiskIODirectionWrite DiskIODirectionAttr = "write"
|
|
)
|
|
|
|
// NetworkIODirectionAttr is an attribute conforming to the network.io.direction
|
|
// semantic conventions. It represents the network IO operation direction.
|
|
type NetworkIODirectionAttr string
|
|
|
|
var (
|
|
// NetworkIODirectionTransmit is the standardized value "transmit" of
|
|
// NetworkIODirectionAttr.
|
|
NetworkIODirectionTransmit NetworkIODirectionAttr = "transmit"
|
|
// NetworkIODirectionReceive is the standardized value "receive" of
|
|
// NetworkIODirectionAttr.
|
|
NetworkIODirectionReceive NetworkIODirectionAttr = "receive"
|
|
)
|
|
|
|
// CPUTime is an instrument used to record metric values conforming to the
|
|
// "container.cpu.time" semantic conventions. It represents the total CPU time
|
|
// consumed.
|
|
type CPUTime struct {
|
|
metric.Float64Counter
|
|
}
|
|
|
|
// NewCPUTime returns a new CPUTime instrument.
|
|
func NewCPUTime(
|
|
m metric.Meter,
|
|
opt ...metric.Float64CounterOption,
|
|
) (CPUTime, error) {
|
|
// Check if the meter is nil.
|
|
if m == nil {
|
|
return CPUTime{noop.Float64Counter{}}, nil
|
|
}
|
|
|
|
i, err := m.Float64Counter(
|
|
"container.cpu.time",
|
|
append([]metric.Float64CounterOption{
|
|
metric.WithDescription("Total CPU time consumed"),
|
|
metric.WithUnit("s"),
|
|
}, opt...)...,
|
|
)
|
|
if err != nil {
|
|
return CPUTime{noop.Float64Counter{}}, err
|
|
}
|
|
return CPUTime{i}, nil
|
|
}
|
|
|
|
// Inst returns the underlying metric instrument.
|
|
func (m CPUTime) Inst() metric.Float64Counter {
|
|
return m.Float64Counter
|
|
}
|
|
|
|
// Name returns the semantic convention name of the instrument.
|
|
func (CPUTime) Name() string {
|
|
return "container.cpu.time"
|
|
}
|
|
|
|
// Unit returns the semantic convention unit of the instrument
|
|
func (CPUTime) Unit() string {
|
|
return "s"
|
|
}
|
|
|
|
// Description returns the semantic convention description of the instrument
|
|
func (CPUTime) Description() string {
|
|
return "Total CPU time consumed"
|
|
}
|
|
|
|
// Add adds incr to the existing count for attrs.
|
|
//
|
|
// All additional attrs passed are included in the recorded value.
|
|
//
|
|
// Total CPU time consumed by the specific container on all available CPU cores
|
|
func (m CPUTime) Add(
|
|
ctx context.Context,
|
|
incr float64,
|
|
attrs ...attribute.KeyValue,
|
|
) {
|
|
if len(attrs) == 0 {
|
|
m.Float64Counter.Add(ctx, incr)
|
|
return
|
|
}
|
|
|
|
o := addOptPool.Get().(*[]metric.AddOption)
|
|
defer func() {
|
|
*o = (*o)[:0]
|
|
addOptPool.Put(o)
|
|
}()
|
|
|
|
*o = append(
|
|
*o,
|
|
metric.WithAttributes(
|
|
attrs...,
|
|
),
|
|
)
|
|
|
|
m.Float64Counter.Add(ctx, incr, *o...)
|
|
}
|
|
|
|
// AddSet adds incr to the existing count for set.
|
|
//
|
|
// Total CPU time consumed by the specific container on all available CPU cores
|
|
func (m CPUTime) AddSet(ctx context.Context, incr float64, set attribute.Set) {
|
|
if set.Len() == 0 {
|
|
m.Float64Counter.Add(ctx, incr)
|
|
return
|
|
}
|
|
|
|
o := addOptPool.Get().(*[]metric.AddOption)
|
|
defer func() {
|
|
*o = (*o)[:0]
|
|
addOptPool.Put(o)
|
|
}()
|
|
|
|
*o = append(*o, metric.WithAttributeSet(set))
|
|
m.Float64Counter.Add(ctx, incr, *o...)
|
|
}
|
|
|
|
// AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
|
|
// convention. It represents the CPU mode for this data point. A container's CPU
|
|
// metric SHOULD be characterized *either* by data points with no `mode` labels,
|
|
// *or only* data points with `mode` labels.
|
|
func (CPUTime) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
|
|
return attribute.String("cpu.mode", string(val))
|
|
}
|
|
|
|
// CPUUsage is an instrument used to record metric values conforming to the
|
|
// "container.cpu.usage" semantic conventions. It represents the container's CPU
|
|
// usage, measured in cpus. Range from 0 to the number of allocatable CPUs.
|
|
type CPUUsage struct {
|
|
metric.Int64Gauge
|
|
}
|
|
|
|
// NewCPUUsage returns a new CPUUsage instrument.
|
|
func NewCPUUsage(
|
|
m metric.Meter,
|
|
opt ...metric.Int64GaugeOption,
|
|
) (CPUUsage, error) {
|
|
// Check if the meter is nil.
|
|
if m == nil {
|
|
return CPUUsage{noop.Int64Gauge{}}, nil
|
|
}
|
|
|
|
i, err := m.Int64Gauge(
|
|
"container.cpu.usage",
|
|
append([]metric.Int64GaugeOption{
|
|
metric.WithDescription("Container's CPU usage, measured in cpus. Range from 0 to the number of allocatable CPUs"),
|
|
metric.WithUnit("{cpu}"),
|
|
}, opt...)...,
|
|
)
|
|
if err != nil {
|
|
return CPUUsage{noop.Int64Gauge{}}, err
|
|
}
|
|
return CPUUsage{i}, nil
|
|
}
|
|
|
|
// Inst returns the underlying metric instrument.
|
|
func (m CPUUsage) Inst() metric.Int64Gauge {
|
|
return m.Int64Gauge
|
|
}
|
|
|
|
// Name returns the semantic convention name of the instrument.
|
|
func (CPUUsage) Name() string {
|
|
return "container.cpu.usage"
|
|
}
|
|
|
|
// Unit returns the semantic convention unit of the instrument
|
|
func (CPUUsage) Unit() string {
|
|
return "{cpu}"
|
|
}
|
|
|
|
// Description returns the semantic convention description of the instrument
|
|
func (CPUUsage) Description() string {
|
|
return "Container's CPU usage, measured in cpus. Range from 0 to the number of allocatable CPUs"
|
|
}
|
|
|
|
// Record records val to the current distribution for attrs.
|
|
//
|
|
// All additional attrs passed are included in the recorded value.
|
|
//
|
|
// CPU usage of the specific container on all available CPU cores, averaged over
|
|
// the sample window
|
|
func (m CPUUsage) Record(
|
|
ctx context.Context,
|
|
val int64,
|
|
attrs ...attribute.KeyValue,
|
|
) {
|
|
if len(attrs) == 0 {
|
|
m.Int64Gauge.Record(ctx, val)
|
|
return
|
|
}
|
|
|
|
o := recOptPool.Get().(*[]metric.RecordOption)
|
|
defer func() {
|
|
*o = (*o)[:0]
|
|
recOptPool.Put(o)
|
|
}()
|
|
|
|
*o = append(
|
|
*o,
|
|
metric.WithAttributes(
|
|
attrs...,
|
|
),
|
|
)
|
|
|
|
m.Int64Gauge.Record(ctx, val, *o...)
|
|
}
|
|
|
|
// RecordSet records val to the current distribution for set.
|
|
//
|
|
// CPU usage of the specific container on all available CPU cores, averaged over
|
|
// the sample window
|
|
func (m CPUUsage) RecordSet(ctx context.Context, val int64, set attribute.Set) {
|
|
if set.Len() == 0 {
|
|
m.Int64Gauge.Record(ctx, val)
|
|
}
|
|
|
|
o := recOptPool.Get().(*[]metric.RecordOption)
|
|
defer func() {
|
|
*o = (*o)[:0]
|
|
recOptPool.Put(o)
|
|
}()
|
|
|
|
*o = append(*o, metric.WithAttributeSet(set))
|
|
m.Int64Gauge.Record(ctx, val, *o...)
|
|
}
|
|
|
|
// AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
|
|
// convention. It represents the CPU mode for this data point. A container's CPU
|
|
// metric SHOULD be characterized *either* by data points with no `mode` labels,
|
|
// *or only* data points with `mode` labels.
|
|
func (CPUUsage) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
|
|
return attribute.String("cpu.mode", string(val))
|
|
}
|
|
|
|
// DiskIO is an instrument used to record metric values conforming to the
|
|
// "container.disk.io" semantic conventions. It represents the disk bytes for the
|
|
// container.
|
|
type DiskIO struct {
|
|
metric.Int64Counter
|
|
}
|
|
|
|
// NewDiskIO returns a new DiskIO instrument.
|
|
func NewDiskIO(
|
|
m metric.Meter,
|
|
opt ...metric.Int64CounterOption,
|
|
) (DiskIO, error) {
|
|
// Check if the meter is nil.
|
|
if m == nil {
|
|
return DiskIO{noop.Int64Counter{}}, nil
|
|
}
|
|
|
|
i, err := m.Int64Counter(
|
|
"container.disk.io",
|
|
append([]metric.Int64CounterOption{
|
|
metric.WithDescription("Disk bytes for the container."),
|
|
metric.WithUnit("By"),
|
|
}, opt...)...,
|
|
)
|
|
if err != nil {
|
|
return DiskIO{noop.Int64Counter{}}, err
|
|
}
|
|
return DiskIO{i}, nil
|
|
}
|
|
|
|
// Inst returns the underlying metric instrument.
|
|
func (m DiskIO) Inst() metric.Int64Counter {
|
|
return m.Int64Counter
|
|
}
|
|
|
|
// Name returns the semantic convention name of the instrument.
|
|
func (DiskIO) Name() string {
|
|
return "container.disk.io"
|
|
}
|
|
|
|
// Unit returns the semantic convention unit of the instrument
|
|
func (DiskIO) Unit() string {
|
|
return "By"
|
|
}
|
|
|
|
// Description returns the semantic convention description of the instrument
|
|
func (DiskIO) Description() string {
|
|
return "Disk bytes for the container."
|
|
}
|
|
|
|
// Add adds incr to the existing count for attrs.
|
|
//
|
|
// All additional attrs passed are included in the recorded value.
|
|
//
|
|
// The total number of bytes read/written successfully (aggregated from all
|
|
// disks).
|
|
func (m DiskIO) Add(
|
|
ctx context.Context,
|
|
incr int64,
|
|
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(
|
|
attrs...,
|
|
),
|
|
)
|
|
|
|
m.Int64Counter.Add(ctx, incr, *o...)
|
|
}
|
|
|
|
// AddSet adds incr to the existing count for set.
|
|
//
|
|
// The total number of bytes read/written successfully (aggregated from all
|
|
// disks).
|
|
func (m DiskIO) 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...)
|
|
}
|
|
|
|
// AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
|
|
// semantic convention. It represents the disk IO operation direction.
|
|
func (DiskIO) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
|
|
return attribute.String("disk.io.direction", string(val))
|
|
}
|
|
|
|
// AttrSystemDevice returns an optional attribute for the "system.device"
|
|
// semantic convention. It represents the device identifier.
|
|
func (DiskIO) AttrSystemDevice(val string) attribute.KeyValue {
|
|
return attribute.String("system.device", val)
|
|
}
|
|
|
|
// MemoryUsage is an instrument used to record metric values conforming to the
|
|
// "container.memory.usage" semantic conventions. It represents the memory usage
|
|
// of the container.
|
|
type MemoryUsage struct {
|
|
metric.Int64Counter
|
|
}
|
|
|
|
// NewMemoryUsage returns a new MemoryUsage instrument.
|
|
func NewMemoryUsage(
|
|
m metric.Meter,
|
|
opt ...metric.Int64CounterOption,
|
|
) (MemoryUsage, error) {
|
|
// Check if the meter is nil.
|
|
if m == nil {
|
|
return MemoryUsage{noop.Int64Counter{}}, nil
|
|
}
|
|
|
|
i, err := m.Int64Counter(
|
|
"container.memory.usage",
|
|
append([]metric.Int64CounterOption{
|
|
metric.WithDescription("Memory usage of the container."),
|
|
metric.WithUnit("By"),
|
|
}, opt...)...,
|
|
)
|
|
if err != nil {
|
|
return MemoryUsage{noop.Int64Counter{}}, err
|
|
}
|
|
return MemoryUsage{i}, nil
|
|
}
|
|
|
|
// Inst returns the underlying metric instrument.
|
|
func (m MemoryUsage) Inst() metric.Int64Counter {
|
|
return m.Int64Counter
|
|
}
|
|
|
|
// Name returns the semantic convention name of the instrument.
|
|
func (MemoryUsage) Name() string {
|
|
return "container.memory.usage"
|
|
}
|
|
|
|
// Unit returns the semantic convention unit of the instrument
|
|
func (MemoryUsage) Unit() string {
|
|
return "By"
|
|
}
|
|
|
|
// Description returns the semantic convention description of the instrument
|
|
func (MemoryUsage) Description() string {
|
|
return "Memory usage of the container."
|
|
}
|
|
|
|
// Add adds incr to the existing count for attrs.
|
|
//
|
|
// Memory usage of the container.
|
|
func (m MemoryUsage) Add(ctx context.Context, incr int64, 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(attrs...))
|
|
m.Int64Counter.Add(ctx, incr, *o...)
|
|
}
|
|
|
|
// AddSet adds incr to the existing count for set.
|
|
//
|
|
// Memory usage of the container.
|
|
func (m MemoryUsage) 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...)
|
|
}
|
|
|
|
// NetworkIO is an instrument used to record metric values conforming to the
|
|
// "container.network.io" semantic conventions. It represents the network bytes
|
|
// for the container.
|
|
type NetworkIO struct {
|
|
metric.Int64Counter
|
|
}
|
|
|
|
// NewNetworkIO returns a new NetworkIO instrument.
|
|
func NewNetworkIO(
|
|
m metric.Meter,
|
|
opt ...metric.Int64CounterOption,
|
|
) (NetworkIO, error) {
|
|
// Check if the meter is nil.
|
|
if m == nil {
|
|
return NetworkIO{noop.Int64Counter{}}, nil
|
|
}
|
|
|
|
i, err := m.Int64Counter(
|
|
"container.network.io",
|
|
append([]metric.Int64CounterOption{
|
|
metric.WithDescription("Network bytes for the container."),
|
|
metric.WithUnit("By"),
|
|
}, opt...)...,
|
|
)
|
|
if err != nil {
|
|
return NetworkIO{noop.Int64Counter{}}, err
|
|
}
|
|
return NetworkIO{i}, nil
|
|
}
|
|
|
|
// Inst returns the underlying metric instrument.
|
|
func (m NetworkIO) Inst() metric.Int64Counter {
|
|
return m.Int64Counter
|
|
}
|
|
|
|
// Name returns the semantic convention name of the instrument.
|
|
func (NetworkIO) Name() string {
|
|
return "container.network.io"
|
|
}
|
|
|
|
// Unit returns the semantic convention unit of the instrument
|
|
func (NetworkIO) Unit() string {
|
|
return "By"
|
|
}
|
|
|
|
// Description returns the semantic convention description of the instrument
|
|
func (NetworkIO) Description() string {
|
|
return "Network bytes for the container."
|
|
}
|
|
|
|
// Add adds incr to the existing count for attrs.
|
|
//
|
|
// All additional attrs passed are included in the recorded value.
|
|
//
|
|
// The number of bytes sent/received on all network interfaces by the container.
|
|
func (m NetworkIO) Add(
|
|
ctx context.Context,
|
|
incr int64,
|
|
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(
|
|
attrs...,
|
|
),
|
|
)
|
|
|
|
m.Int64Counter.Add(ctx, incr, *o...)
|
|
}
|
|
|
|
// AddSet adds incr to the existing count for set.
|
|
//
|
|
// The number of bytes sent/received on all network interfaces by the container.
|
|
func (m NetworkIO) 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...)
|
|
}
|
|
|
|
// AttrNetworkInterfaceName returns an optional attribute for the
|
|
// "network.interface.name" semantic convention. It represents the network
|
|
// interface name.
|
|
func (NetworkIO) AttrNetworkInterfaceName(val string) attribute.KeyValue {
|
|
return attribute.String("network.interface.name", val)
|
|
}
|
|
|
|
// AttrNetworkIODirection returns an optional attribute for the
|
|
// "network.io.direction" semantic convention. It represents the network IO
|
|
// operation direction.
|
|
func (NetworkIO) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
|
|
return attribute.String("network.io.direction", string(val))
|
|
}
|
|
|
|
// Uptime is an instrument used to record metric values conforming to the
|
|
// "container.uptime" semantic conventions. It represents the time the container
|
|
// has been running.
|
|
type Uptime struct {
|
|
metric.Float64Gauge
|
|
}
|
|
|
|
// NewUptime returns a new Uptime instrument.
|
|
func NewUptime(
|
|
m metric.Meter,
|
|
opt ...metric.Float64GaugeOption,
|
|
) (Uptime, error) {
|
|
// Check if the meter is nil.
|
|
if m == nil {
|
|
return Uptime{noop.Float64Gauge{}}, nil
|
|
}
|
|
|
|
i, err := m.Float64Gauge(
|
|
"container.uptime",
|
|
append([]metric.Float64GaugeOption{
|
|
metric.WithDescription("The time the container has been running"),
|
|
metric.WithUnit("s"),
|
|
}, opt...)...,
|
|
)
|
|
if err != nil {
|
|
return Uptime{noop.Float64Gauge{}}, err
|
|
}
|
|
return Uptime{i}, nil
|
|
}
|
|
|
|
// Inst returns the underlying metric instrument.
|
|
func (m Uptime) Inst() metric.Float64Gauge {
|
|
return m.Float64Gauge
|
|
}
|
|
|
|
// Name returns the semantic convention name of the instrument.
|
|
func (Uptime) Name() string {
|
|
return "container.uptime"
|
|
}
|
|
|
|
// Unit returns the semantic convention unit of the instrument
|
|
func (Uptime) Unit() string {
|
|
return "s"
|
|
}
|
|
|
|
// Description returns the semantic convention description of the instrument
|
|
func (Uptime) Description() string {
|
|
return "The time the container has been running"
|
|
}
|
|
|
|
// Record records val to the current distribution for attrs.
|
|
//
|
|
// Instrumentations SHOULD use a gauge with type `double` and measure uptime in
|
|
// seconds as a floating point number with the highest precision available.
|
|
// The actual accuracy would depend on the instrumentation and operating system.
|
|
func (m Uptime) Record(ctx context.Context, val float64, attrs ...attribute.KeyValue) {
|
|
if len(attrs) == 0 {
|
|
m.Float64Gauge.Record(ctx, val)
|
|
return
|
|
}
|
|
|
|
o := recOptPool.Get().(*[]metric.RecordOption)
|
|
defer func() {
|
|
*o = (*o)[:0]
|
|
recOptPool.Put(o)
|
|
}()
|
|
|
|
*o = append(*o, metric.WithAttributes(attrs...))
|
|
m.Float64Gauge.Record(ctx, val, *o...)
|
|
}
|
|
|
|
// RecordSet records val to the current distribution for set.
|
|
//
|
|
// Instrumentations SHOULD use a gauge with type `double` and measure uptime in
|
|
// seconds as a floating point number with the highest precision available.
|
|
// The actual accuracy would depend on the instrumentation and operating system.
|
|
func (m Uptime) RecordSet(ctx context.Context, val float64, set attribute.Set) {
|
|
if set.Len() == 0 {
|
|
m.Float64Gauge.Record(ctx, val)
|
|
}
|
|
|
|
o := recOptPool.Get().(*[]metric.RecordOption)
|
|
defer func() {
|
|
*o = (*o)[:0]
|
|
recOptPool.Put(o)
|
|
}()
|
|
|
|
*o = append(*o, metric.WithAttributeSet(set))
|
|
m.Float64Gauge.Record(ctx, val, *o...)
|
|
} |