| 1 |
// Code generated from semantic convention specification. DO NOT EDIT. |
| 2 |
|
| 3 |
// Copyright The OpenTelemetry Authors |
| 4 |
// SPDX-License-Identifier: Apache-2.0 |
| 5 |
|
| 6 |
// Package processconv provides types and functionality for OpenTelemetry semantic |
| 7 |
// conventions in the "process" namespace. |
| 8 |
package processconv |
| 9 |
|
| 10 |
import ( |
| 11 |
"context" |
| 12 |
"sync" |
| 13 |
|
| 14 |
"go.opentelemetry.io/otel/attribute" |
| 15 |
"go.opentelemetry.io/otel/metric" |
| 16 |
"go.opentelemetry.io/otel/metric/noop" |
| 17 |
) |
| 18 |
|
| 19 |
var ( |
| 20 |
addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }} |
| 21 |
recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }} |
| 22 |
) |
| 23 |
|
| 24 |
// CPUModeAttr is an attribute conforming to the cpu.mode semantic conventions. |
| 25 |
// It represents a process SHOULD be characterized *either* by data points with |
| 26 |
// no `mode` labels, *or only* data points with `mode` labels. |
| 27 |
type CPUModeAttr string |
| 28 |
|
| 29 |
var ( |
| 30 |
// CPUModeUser is the user. |
| 31 |
CPUModeUser CPUModeAttr = "user" |
| 32 |
// CPUModeSystem is the system. |
| 33 |
CPUModeSystem CPUModeAttr = "system" |
| 34 |
// CPUModeNice is the nice. |
| 35 |
CPUModeNice CPUModeAttr = "nice" |
| 36 |
// CPUModeIdle is the idle. |
| 37 |
CPUModeIdle CPUModeAttr = "idle" |
| 38 |
// CPUModeIOWait is the IO Wait. |
| 39 |
CPUModeIOWait CPUModeAttr = "iowait" |
| 40 |
// CPUModeInterrupt is the interrupt. |
| 41 |
CPUModeInterrupt CPUModeAttr = "interrupt" |
| 42 |
// CPUModeSteal is the steal. |
| 43 |
CPUModeSteal CPUModeAttr = "steal" |
| 44 |
// CPUModeKernel is the kernel. |
| 45 |
CPUModeKernel CPUModeAttr = "kernel" |
| 46 |
) |
| 47 |
|
| 48 |
// DiskIODirectionAttr is an attribute conforming to the disk.io.direction |
| 49 |
// semantic conventions. It represents the disk IO operation direction. |
| 50 |
type DiskIODirectionAttr string |
| 51 |
|
| 52 |
var ( |
| 53 |
// DiskIODirectionRead is the standardized value "read" of DiskIODirectionAttr. |
| 54 |
DiskIODirectionRead DiskIODirectionAttr = "read" |
| 55 |
// DiskIODirectionWrite is the standardized value "write" of |
| 56 |
// DiskIODirectionAttr. |
| 57 |
DiskIODirectionWrite DiskIODirectionAttr = "write" |
| 58 |
) |
| 59 |
|
| 60 |
// NetworkIODirectionAttr is an attribute conforming to the network.io.direction |
| 61 |
// semantic conventions. It represents the network IO operation direction. |
| 62 |
type NetworkIODirectionAttr string |
| 63 |
|
| 64 |
var ( |
| 65 |
// NetworkIODirectionTransmit is the standardized value "transmit" of |
| 66 |
// NetworkIODirectionAttr. |
| 67 |
NetworkIODirectionTransmit NetworkIODirectionAttr = "transmit" |
| 68 |
// NetworkIODirectionReceive is the standardized value "receive" of |
| 69 |
// NetworkIODirectionAttr. |
| 70 |
NetworkIODirectionReceive NetworkIODirectionAttr = "receive" |
| 71 |
) |
| 72 |
|
| 73 |
// ContextSwitchTypeAttr is an attribute conforming to the |
| 74 |
// process.context_switch.type semantic conventions. It represents the specifies |
| 75 |
// whether the context switches for this data point were voluntary or |
| 76 |
// involuntary. |
| 77 |
type ContextSwitchTypeAttr string |
| 78 |
|
| 79 |
var ( |
| 80 |
// ContextSwitchTypeVoluntary is the standardized value "voluntary" of |
| 81 |
// ContextSwitchTypeAttr. |
| 82 |
ContextSwitchTypeVoluntary ContextSwitchTypeAttr = "voluntary" |
| 83 |
// ContextSwitchTypeInvoluntary is the standardized value "involuntary" of |
| 84 |
// ContextSwitchTypeAttr. |
| 85 |
ContextSwitchTypeInvoluntary ContextSwitchTypeAttr = "involuntary" |
| 86 |
) |
| 87 |
|
| 88 |
// SystemPagingFaultTypeAttr is an attribute conforming to the |
| 89 |
// system.paging.fault.type semantic conventions. It represents the paging fault |
| 90 |
// type. |
| 91 |
type SystemPagingFaultTypeAttr string |
| 92 |
|
| 93 |
var ( |
| 94 |
// SystemPagingFaultTypeMajor is the standardized value "major" of |
| 95 |
// SystemPagingFaultTypeAttr. |
| 96 |
SystemPagingFaultTypeMajor SystemPagingFaultTypeAttr = "major" |
| 97 |
// SystemPagingFaultTypeMinor is the standardized value "minor" of |
| 98 |
// SystemPagingFaultTypeAttr. |
| 99 |
SystemPagingFaultTypeMinor SystemPagingFaultTypeAttr = "minor" |
| 100 |
) |
| 101 |
|
| 102 |
// ContextSwitches is an instrument used to record metric values conforming to |
| 103 |
// the "process.context_switches" semantic conventions. It represents the number |
| 104 |
// of times the process has been context switched. |
| 105 |
type ContextSwitches struct { |
| 106 |
metric.Int64Counter |
| 107 |
} |
| 108 |
|
| 109 |
var newContextSwitchesOpts = []metric.Int64CounterOption{ |
| 110 |
metric.WithDescription("Number of times the process has been context switched."), |
| 111 |
metric.WithUnit("{context_switch}"), |
| 112 |
} |
| 113 |
|
| 114 |
// NewContextSwitches returns a new ContextSwitches instrument. |
| 115 |
func NewContextSwitches( |
| 116 |
m metric.Meter, |
| 117 |
opt ...metric.Int64CounterOption, |
| 118 |
) (ContextSwitches, error) { |
| 119 |
// Check if the meter is nil. |
| 120 |
if m == nil { |
| 121 |
return ContextSwitches{noop.Int64Counter{}}, nil |
| 122 |
} |
| 123 |
|
| 124 |
if len(opt) == 0 { |
| 125 |
opt = newContextSwitchesOpts |
| 126 |
} else { |
| 127 |
opt = append(opt, newContextSwitchesOpts...) |
| 128 |
} |
| 129 |
|
| 130 |
i, err := m.Int64Counter( |
| 131 |
"process.context_switches", |
| 132 |
opt..., |
| 133 |
) |
| 134 |
if err != nil { |
| 135 |
return ContextSwitches{noop.Int64Counter{}}, err |
| 136 |
} |
| 137 |
return ContextSwitches{i}, nil |
| 138 |
} |
| 139 |
|
| 140 |
// Inst returns the underlying metric instrument. |
| 141 |
func (m ContextSwitches) Inst() metric.Int64Counter { |
| 142 |
return m.Int64Counter |
| 143 |
} |
| 144 |
|
| 145 |
// Name returns the semantic convention name of the instrument. |
| 146 |
func (ContextSwitches) Name() string { |
| 147 |
return "process.context_switches" |
| 148 |
} |
| 149 |
|
| 150 |
// Unit returns the semantic convention unit of the instrument |
| 151 |
func (ContextSwitches) Unit() string { |
| 152 |
return "{context_switch}" |
| 153 |
} |
| 154 |
|
| 155 |
// Description returns the semantic convention description of the instrument |
| 156 |
func (ContextSwitches) Description() string { |
| 157 |
return "Number of times the process has been context switched." |
| 158 |
} |
| 159 |
|
| 160 |
// Add adds incr to the existing count for attrs. |
| 161 |
// |
| 162 |
// All additional attrs passed are included in the recorded value. |
| 163 |
func (m ContextSwitches) Add( |
| 164 |
ctx context.Context, |
| 165 |
incr int64, |
| 166 |
attrs ...attribute.KeyValue, |
| 167 |
) { |
| 168 |
if len(attrs) == 0 { |
| 169 |
m.Int64Counter.Add(ctx, incr) |
| 170 |
return |
| 171 |
} |
| 172 |
|
| 173 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 174 |
defer func() { |
| 175 |
*o = (*o)[:0] |
| 176 |
addOptPool.Put(o) |
| 177 |
}() |
| 178 |
|
| 179 |
*o = append( |
| 180 |
*o, |
| 181 |
metric.WithAttributes( |
| 182 |
attrs..., |
| 183 |
), |
| 184 |
) |
| 185 |
|
| 186 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 187 |
} |
| 188 |
|
| 189 |
// AddSet adds incr to the existing count for set. |
| 190 |
func (m ContextSwitches) AddSet(ctx context.Context, incr int64, set attribute.Set) { |
| 191 |
if set.Len() == 0 { |
| 192 |
m.Int64Counter.Add(ctx, incr) |
| 193 |
return |
| 194 |
} |
| 195 |
|
| 196 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 197 |
defer func() { |
| 198 |
*o = (*o)[:0] |
| 199 |
addOptPool.Put(o) |
| 200 |
}() |
| 201 |
|
| 202 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 203 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 204 |
} |
| 205 |
|
| 206 |
// AttrContextSwitchType returns an optional attribute for the |
| 207 |
// "process.context_switch.type" semantic convention. It represents the specifies |
| 208 |
// whether the context switches for this data point were voluntary or |
| 209 |
// involuntary. |
| 210 |
func (ContextSwitches) AttrContextSwitchType(val ContextSwitchTypeAttr) attribute.KeyValue { |
| 211 |
return attribute.String("process.context_switch.type", string(val)) |
| 212 |
} |
| 213 |
|
| 214 |
// CPUTime is an instrument used to record metric values conforming to the |
| 215 |
// "process.cpu.time" semantic conventions. It represents the total CPU seconds |
| 216 |
// broken down by different states. |
| 217 |
type CPUTime struct { |
| 218 |
metric.Float64ObservableCounter |
| 219 |
} |
| 220 |
|
| 221 |
var newCPUTimeOpts = []metric.Float64ObservableCounterOption{ |
| 222 |
metric.WithDescription("Total CPU seconds broken down by different states."), |
| 223 |
metric.WithUnit("s"), |
| 224 |
} |
| 225 |
|
| 226 |
// NewCPUTime returns a new CPUTime instrument. |
| 227 |
func NewCPUTime( |
| 228 |
m metric.Meter, |
| 229 |
opt ...metric.Float64ObservableCounterOption, |
| 230 |
) (CPUTime, error) { |
| 231 |
// Check if the meter is nil. |
| 232 |
if m == nil { |
| 233 |
return CPUTime{noop.Float64ObservableCounter{}}, nil |
| 234 |
} |
| 235 |
|
| 236 |
if len(opt) == 0 { |
| 237 |
opt = newCPUTimeOpts |
| 238 |
} else { |
| 239 |
opt = append(opt, newCPUTimeOpts...) |
| 240 |
} |
| 241 |
|
| 242 |
i, err := m.Float64ObservableCounter( |
| 243 |
"process.cpu.time", |
| 244 |
opt..., |
| 245 |
) |
| 246 |
if err != nil { |
| 247 |
return CPUTime{noop.Float64ObservableCounter{}}, err |
| 248 |
} |
| 249 |
return CPUTime{i}, nil |
| 250 |
} |
| 251 |
|
| 252 |
// Inst returns the underlying metric instrument. |
| 253 |
func (m CPUTime) Inst() metric.Float64ObservableCounter { |
| 254 |
return m.Float64ObservableCounter |
| 255 |
} |
| 256 |
|
| 257 |
// Name returns the semantic convention name of the instrument. |
| 258 |
func (CPUTime) Name() string { |
| 259 |
return "process.cpu.time" |
| 260 |
} |
| 261 |
|
| 262 |
// Unit returns the semantic convention unit of the instrument |
| 263 |
func (CPUTime) Unit() string { |
| 264 |
return "s" |
| 265 |
} |
| 266 |
|
| 267 |
// Description returns the semantic convention description of the instrument |
| 268 |
func (CPUTime) Description() string { |
| 269 |
return "Total CPU seconds broken down by different states." |
| 270 |
} |
| 271 |
|
| 272 |
// AttrCPUMode returns an optional attribute for the "cpu.mode" semantic |
| 273 |
// convention. It represents a process SHOULD be characterized *either* by data |
| 274 |
// points with no `mode` labels, *or only* data points with `mode` labels. |
| 275 |
func (CPUTime) AttrCPUMode(val CPUModeAttr) attribute.KeyValue { |
| 276 |
return attribute.String("cpu.mode", string(val)) |
| 277 |
} |
| 278 |
|
| 279 |
// CPUUtilization is an instrument used to record metric values conforming to the |
| 280 |
// "process.cpu.utilization" semantic conventions. It represents the difference |
| 281 |
// in process.cpu.time since the last measurement, divided by the elapsed time |
| 282 |
// and number of CPUs available to the process. |
| 283 |
type CPUUtilization struct { |
| 284 |
metric.Int64Gauge |
| 285 |
} |
| 286 |
|
| 287 |
var newCPUUtilizationOpts = []metric.Int64GaugeOption{ |
| 288 |
metric.WithDescription("Difference in process.cpu.time since the last measurement, divided by the elapsed time and number of CPUs available to the process."), |
| 289 |
metric.WithUnit("1"), |
| 290 |
} |
| 291 |
|
| 292 |
// NewCPUUtilization returns a new CPUUtilization instrument. |
| 293 |
func NewCPUUtilization( |
| 294 |
m metric.Meter, |
| 295 |
opt ...metric.Int64GaugeOption, |
| 296 |
) (CPUUtilization, error) { |
| 297 |
// Check if the meter is nil. |
| 298 |
if m == nil { |
| 299 |
return CPUUtilization{noop.Int64Gauge{}}, nil |
| 300 |
} |
| 301 |
|
| 302 |
if len(opt) == 0 { |
| 303 |
opt = newCPUUtilizationOpts |
| 304 |
} else { |
| 305 |
opt = append(opt, newCPUUtilizationOpts...) |
| 306 |
} |
| 307 |
|
| 308 |
i, err := m.Int64Gauge( |
| 309 |
"process.cpu.utilization", |
| 310 |
opt..., |
| 311 |
) |
| 312 |
if err != nil { |
| 313 |
return CPUUtilization{noop.Int64Gauge{}}, err |
| 314 |
} |
| 315 |
return CPUUtilization{i}, nil |
| 316 |
} |
| 317 |
|
| 318 |
// Inst returns the underlying metric instrument. |
| 319 |
func (m CPUUtilization) Inst() metric.Int64Gauge { |
| 320 |
return m.Int64Gauge |
| 321 |
} |
| 322 |
|
| 323 |
// Name returns the semantic convention name of the instrument. |
| 324 |
func (CPUUtilization) Name() string { |
| 325 |
return "process.cpu.utilization" |
| 326 |
} |
| 327 |
|
| 328 |
// Unit returns the semantic convention unit of the instrument |
| 329 |
func (CPUUtilization) Unit() string { |
| 330 |
return "1" |
| 331 |
} |
| 332 |
|
| 333 |
// Description returns the semantic convention description of the instrument |
| 334 |
func (CPUUtilization) Description() string { |
| 335 |
return "Difference in process.cpu.time since the last measurement, divided by the elapsed time and number of CPUs available to the process." |
| 336 |
} |
| 337 |
|
| 338 |
// Record records val to the current distribution for attrs. |
| 339 |
// |
| 340 |
// All additional attrs passed are included in the recorded value. |
| 341 |
func (m CPUUtilization) Record( |
| 342 |
ctx context.Context, |
| 343 |
val int64, |
| 344 |
attrs ...attribute.KeyValue, |
| 345 |
) { |
| 346 |
if len(attrs) == 0 { |
| 347 |
m.Int64Gauge.Record(ctx, val) |
| 348 |
return |
| 349 |
} |
| 350 |
|
| 351 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 352 |
defer func() { |
| 353 |
*o = (*o)[:0] |
| 354 |
recOptPool.Put(o) |
| 355 |
}() |
| 356 |
|
| 357 |
*o = append( |
| 358 |
*o, |
| 359 |
metric.WithAttributes( |
| 360 |
attrs..., |
| 361 |
), |
| 362 |
) |
| 363 |
|
| 364 |
m.Int64Gauge.Record(ctx, val, *o...) |
| 365 |
} |
| 366 |
|
| 367 |
// RecordSet records val to the current distribution for set. |
| 368 |
func (m CPUUtilization) RecordSet(ctx context.Context, val int64, set attribute.Set) { |
| 369 |
if set.Len() == 0 { |
| 370 |
m.Int64Gauge.Record(ctx, val) |
| 371 |
return |
| 372 |
} |
| 373 |
|
| 374 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 375 |
defer func() { |
| 376 |
*o = (*o)[:0] |
| 377 |
recOptPool.Put(o) |
| 378 |
}() |
| 379 |
|
| 380 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 381 |
m.Int64Gauge.Record(ctx, val, *o...) |
| 382 |
} |
| 383 |
|
| 384 |
// AttrCPUMode returns an optional attribute for the "cpu.mode" semantic |
| 385 |
// convention. It represents a process SHOULD be characterized *either* by data |
| 386 |
// points with no `mode` labels, *or only* data points with `mode` labels. |
| 387 |
func (CPUUtilization) AttrCPUMode(val CPUModeAttr) attribute.KeyValue { |
| 388 |
return attribute.String("cpu.mode", string(val)) |
| 389 |
} |
| 390 |
|
| 391 |
// DiskIO is an instrument used to record metric values conforming to the |
| 392 |
// "process.disk.io" semantic conventions. It represents the disk bytes |
| 393 |
// transferred. |
| 394 |
type DiskIO struct { |
| 395 |
metric.Int64Counter |
| 396 |
} |
| 397 |
|
| 398 |
var newDiskIOOpts = []metric.Int64CounterOption{ |
| 399 |
metric.WithDescription("Disk bytes transferred."), |
| 400 |
metric.WithUnit("By"), |
| 401 |
} |
| 402 |
|
| 403 |
// NewDiskIO returns a new DiskIO instrument. |
| 404 |
func NewDiskIO( |
| 405 |
m metric.Meter, |
| 406 |
opt ...metric.Int64CounterOption, |
| 407 |
) (DiskIO, error) { |
| 408 |
// Check if the meter is nil. |
| 409 |
if m == nil { |
| 410 |
return DiskIO{noop.Int64Counter{}}, nil |
| 411 |
} |
| 412 |
|
| 413 |
if len(opt) == 0 { |
| 414 |
opt = newDiskIOOpts |
| 415 |
} else { |
| 416 |
opt = append(opt, newDiskIOOpts...) |
| 417 |
} |
| 418 |
|
| 419 |
i, err := m.Int64Counter( |
| 420 |
"process.disk.io", |
| 421 |
opt..., |
| 422 |
) |
| 423 |
if err != nil { |
| 424 |
return DiskIO{noop.Int64Counter{}}, err |
| 425 |
} |
| 426 |
return DiskIO{i}, nil |
| 427 |
} |
| 428 |
|
| 429 |
// Inst returns the underlying metric instrument. |
| 430 |
func (m DiskIO) Inst() metric.Int64Counter { |
| 431 |
return m.Int64Counter |
| 432 |
} |
| 433 |
|
| 434 |
// Name returns the semantic convention name of the instrument. |
| 435 |
func (DiskIO) Name() string { |
| 436 |
return "process.disk.io" |
| 437 |
} |
| 438 |
|
| 439 |
// Unit returns the semantic convention unit of the instrument |
| 440 |
func (DiskIO) Unit() string { |
| 441 |
return "By" |
| 442 |
} |
| 443 |
|
| 444 |
// Description returns the semantic convention description of the instrument |
| 445 |
func (DiskIO) Description() string { |
| 446 |
return "Disk bytes transferred." |
| 447 |
} |
| 448 |
|
| 449 |
// Add adds incr to the existing count for attrs. |
| 450 |
// |
| 451 |
// All additional attrs passed are included in the recorded value. |
| 452 |
func (m DiskIO) Add( |
| 453 |
ctx context.Context, |
| 454 |
incr int64, |
| 455 |
attrs ...attribute.KeyValue, |
| 456 |
) { |
| 457 |
if len(attrs) == 0 { |
| 458 |
m.Int64Counter.Add(ctx, incr) |
| 459 |
return |
| 460 |
} |
| 461 |
|
| 462 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 463 |
defer func() { |
| 464 |
*o = (*o)[:0] |
| 465 |
addOptPool.Put(o) |
| 466 |
}() |
| 467 |
|
| 468 |
*o = append( |
| 469 |
*o, |
| 470 |
metric.WithAttributes( |
| 471 |
attrs..., |
| 472 |
), |
| 473 |
) |
| 474 |
|
| 475 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 476 |
} |
| 477 |
|
| 478 |
// AddSet adds incr to the existing count for set. |
| 479 |
func (m DiskIO) AddSet(ctx context.Context, incr int64, set attribute.Set) { |
| 480 |
if set.Len() == 0 { |
| 481 |
m.Int64Counter.Add(ctx, incr) |
| 482 |
return |
| 483 |
} |
| 484 |
|
| 485 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 486 |
defer func() { |
| 487 |
*o = (*o)[:0] |
| 488 |
addOptPool.Put(o) |
| 489 |
}() |
| 490 |
|
| 491 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 492 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 493 |
} |
| 494 |
|
| 495 |
// AttrDiskIODirection returns an optional attribute for the "disk.io.direction" |
| 496 |
// semantic convention. It represents the disk IO operation direction. |
| 497 |
func (DiskIO) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue { |
| 498 |
return attribute.String("disk.io.direction", string(val)) |
| 499 |
} |
| 500 |
|
| 501 |
// MemoryUsage is an instrument used to record metric values conforming to the |
| 502 |
// "process.memory.usage" semantic conventions. It represents the amount of |
| 503 |
// physical memory in use. |
| 504 |
type MemoryUsage struct { |
| 505 |
metric.Int64UpDownCounter |
| 506 |
} |
| 507 |
|
| 508 |
var newMemoryUsageOpts = []metric.Int64UpDownCounterOption{ |
| 509 |
metric.WithDescription("The amount of physical memory in use."), |
| 510 |
metric.WithUnit("By"), |
| 511 |
} |
| 512 |
|
| 513 |
// NewMemoryUsage returns a new MemoryUsage instrument. |
| 514 |
func NewMemoryUsage( |
| 515 |
m metric.Meter, |
| 516 |
opt ...metric.Int64UpDownCounterOption, |
| 517 |
) (MemoryUsage, error) { |
| 518 |
// Check if the meter is nil. |
| 519 |
if m == nil { |
| 520 |
return MemoryUsage{noop.Int64UpDownCounter{}}, nil |
| 521 |
} |
| 522 |
|
| 523 |
if len(opt) == 0 { |
| 524 |
opt = newMemoryUsageOpts |
| 525 |
} else { |
| 526 |
opt = append(opt, newMemoryUsageOpts...) |
| 527 |
} |
| 528 |
|
| 529 |
i, err := m.Int64UpDownCounter( |
| 530 |
"process.memory.usage", |
| 531 |
opt..., |
| 532 |
) |
| 533 |
if err != nil { |
| 534 |
return MemoryUsage{noop.Int64UpDownCounter{}}, err |
| 535 |
} |
| 536 |
return MemoryUsage{i}, nil |
| 537 |
} |
| 538 |
|
| 539 |
// Inst returns the underlying metric instrument. |
| 540 |
func (m MemoryUsage) Inst() metric.Int64UpDownCounter { |
| 541 |
return m.Int64UpDownCounter |
| 542 |
} |
| 543 |
|
| 544 |
// Name returns the semantic convention name of the instrument. |
| 545 |
func (MemoryUsage) Name() string { |
| 546 |
return "process.memory.usage" |
| 547 |
} |
| 548 |
|
| 549 |
// Unit returns the semantic convention unit of the instrument |
| 550 |
func (MemoryUsage) Unit() string { |
| 551 |
return "By" |
| 552 |
} |
| 553 |
|
| 554 |
// Description returns the semantic convention description of the instrument |
| 555 |
func (MemoryUsage) Description() string { |
| 556 |
return "The amount of physical memory in use." |
| 557 |
} |
| 558 |
|
| 559 |
// Add adds incr to the existing count for attrs. |
| 560 |
func (m MemoryUsage) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) { |
| 561 |
if len(attrs) == 0 { |
| 562 |
m.Int64UpDownCounter.Add(ctx, incr) |
| 563 |
return |
| 564 |
} |
| 565 |
|
| 566 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 567 |
defer func() { |
| 568 |
*o = (*o)[:0] |
| 569 |
addOptPool.Put(o) |
| 570 |
}() |
| 571 |
|
| 572 |
*o = append(*o, metric.WithAttributes(attrs...)) |
| 573 |
m.Int64UpDownCounter.Add(ctx, incr, *o...) |
| 574 |
} |
| 575 |
|
| 576 |
// AddSet adds incr to the existing count for set. |
| 577 |
func (m MemoryUsage) AddSet(ctx context.Context, incr int64, set attribute.Set) { |
| 578 |
if set.Len() == 0 { |
| 579 |
m.Int64UpDownCounter.Add(ctx, incr) |
| 580 |
return |
| 581 |
} |
| 582 |
|
| 583 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 584 |
defer func() { |
| 585 |
*o = (*o)[:0] |
| 586 |
addOptPool.Put(o) |
| 587 |
}() |
| 588 |
|
| 589 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 590 |
m.Int64UpDownCounter.Add(ctx, incr, *o...) |
| 591 |
} |
| 592 |
|
| 593 |
// MemoryVirtual is an instrument used to record metric values conforming to the |
| 594 |
// "process.memory.virtual" semantic conventions. It represents the amount of |
| 595 |
// committed virtual memory. |
| 596 |
type MemoryVirtual struct { |
| 597 |
metric.Int64UpDownCounter |
| 598 |
} |
| 599 |
|
| 600 |
var newMemoryVirtualOpts = []metric.Int64UpDownCounterOption{ |
| 601 |
metric.WithDescription("The amount of committed virtual memory."), |
| 602 |
metric.WithUnit("By"), |
| 603 |
} |
| 604 |
|
| 605 |
// NewMemoryVirtual returns a new MemoryVirtual instrument. |
| 606 |
func NewMemoryVirtual( |
| 607 |
m metric.Meter, |
| 608 |
opt ...metric.Int64UpDownCounterOption, |
| 609 |
) (MemoryVirtual, error) { |
| 610 |
// Check if the meter is nil. |
| 611 |
if m == nil { |
| 612 |
return MemoryVirtual{noop.Int64UpDownCounter{}}, nil |
| 613 |
} |
| 614 |
|
| 615 |
if len(opt) == 0 { |
| 616 |
opt = newMemoryVirtualOpts |
| 617 |
} else { |
| 618 |
opt = append(opt, newMemoryVirtualOpts...) |
| 619 |
} |
| 620 |
|
| 621 |
i, err := m.Int64UpDownCounter( |
| 622 |
"process.memory.virtual", |
| 623 |
opt..., |
| 624 |
) |
| 625 |
if err != nil { |
| 626 |
return MemoryVirtual{noop.Int64UpDownCounter{}}, err |
| 627 |
} |
| 628 |
return MemoryVirtual{i}, nil |
| 629 |
} |
| 630 |
|
| 631 |
// Inst returns the underlying metric instrument. |
| 632 |
func (m MemoryVirtual) Inst() metric.Int64UpDownCounter { |
| 633 |
return m.Int64UpDownCounter |
| 634 |
} |
| 635 |
|
| 636 |
// Name returns the semantic convention name of the instrument. |
| 637 |
func (MemoryVirtual) Name() string { |
| 638 |
return "process.memory.virtual" |
| 639 |
} |
| 640 |
|
| 641 |
// Unit returns the semantic convention unit of the instrument |
| 642 |
func (MemoryVirtual) Unit() string { |
| 643 |
return "By" |
| 644 |
} |
| 645 |
|
| 646 |
// Description returns the semantic convention description of the instrument |
| 647 |
func (MemoryVirtual) Description() string { |
| 648 |
return "The amount of committed virtual memory." |
| 649 |
} |
| 650 |
|
| 651 |
// Add adds incr to the existing count for attrs. |
| 652 |
func (m MemoryVirtual) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) { |
| 653 |
if len(attrs) == 0 { |
| 654 |
m.Int64UpDownCounter.Add(ctx, incr) |
| 655 |
return |
| 656 |
} |
| 657 |
|
| 658 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 659 |
defer func() { |
| 660 |
*o = (*o)[:0] |
| 661 |
addOptPool.Put(o) |
| 662 |
}() |
| 663 |
|
| 664 |
*o = append(*o, metric.WithAttributes(attrs...)) |
| 665 |
m.Int64UpDownCounter.Add(ctx, incr, *o...) |
| 666 |
} |
| 667 |
|
| 668 |
// AddSet adds incr to the existing count for set. |
| 669 |
func (m MemoryVirtual) AddSet(ctx context.Context, incr int64, set attribute.Set) { |
| 670 |
if set.Len() == 0 { |
| 671 |
m.Int64UpDownCounter.Add(ctx, incr) |
| 672 |
return |
| 673 |
} |
| 674 |
|
| 675 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 676 |
defer func() { |
| 677 |
*o = (*o)[:0] |
| 678 |
addOptPool.Put(o) |
| 679 |
}() |
| 680 |
|
| 681 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 682 |
m.Int64UpDownCounter.Add(ctx, incr, *o...) |
| 683 |
} |
| 684 |
|
| 685 |
// NetworkIO is an instrument used to record metric values conforming to the |
| 686 |
// "process.network.io" semantic conventions. It represents the network bytes |
| 687 |
// transferred. |
| 688 |
type NetworkIO struct { |
| 689 |
metric.Int64Counter |
| 690 |
} |
| 691 |
|
| 692 |
var newNetworkIOOpts = []metric.Int64CounterOption{ |
| 693 |
metric.WithDescription("Network bytes transferred."), |
| 694 |
metric.WithUnit("By"), |
| 695 |
} |
| 696 |
|
| 697 |
// NewNetworkIO returns a new NetworkIO instrument. |
| 698 |
func NewNetworkIO( |
| 699 |
m metric.Meter, |
| 700 |
opt ...metric.Int64CounterOption, |
| 701 |
) (NetworkIO, error) { |
| 702 |
// Check if the meter is nil. |
| 703 |
if m == nil { |
| 704 |
return NetworkIO{noop.Int64Counter{}}, nil |
| 705 |
} |
| 706 |
|
| 707 |
if len(opt) == 0 { |
| 708 |
opt = newNetworkIOOpts |
| 709 |
} else { |
| 710 |
opt = append(opt, newNetworkIOOpts...) |
| 711 |
} |
| 712 |
|
| 713 |
i, err := m.Int64Counter( |
| 714 |
"process.network.io", |
| 715 |
opt..., |
| 716 |
) |
| 717 |
if err != nil { |
| 718 |
return NetworkIO{noop.Int64Counter{}}, err |
| 719 |
} |
| 720 |
return NetworkIO{i}, nil |
| 721 |
} |
| 722 |
|
| 723 |
// Inst returns the underlying metric instrument. |
| 724 |
func (m NetworkIO) Inst() metric.Int64Counter { |
| 725 |
return m.Int64Counter |
| 726 |
} |
| 727 |
|
| 728 |
// Name returns the semantic convention name of the instrument. |
| 729 |
func (NetworkIO) Name() string { |
| 730 |
return "process.network.io" |
| 731 |
} |
| 732 |
|
| 733 |
// Unit returns the semantic convention unit of the instrument |
| 734 |
func (NetworkIO) Unit() string { |
| 735 |
return "By" |
| 736 |
} |
| 737 |
|
| 738 |
// Description returns the semantic convention description of the instrument |
| 739 |
func (NetworkIO) Description() string { |
| 740 |
return "Network bytes transferred." |
| 741 |
} |
| 742 |
|
| 743 |
// Add adds incr to the existing count for attrs. |
| 744 |
// |
| 745 |
// All additional attrs passed are included in the recorded value. |
| 746 |
func (m NetworkIO) Add( |
| 747 |
ctx context.Context, |
| 748 |
incr int64, |
| 749 |
attrs ...attribute.KeyValue, |
| 750 |
) { |
| 751 |
if len(attrs) == 0 { |
| 752 |
m.Int64Counter.Add(ctx, incr) |
| 753 |
return |
| 754 |
} |
| 755 |
|
| 756 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 757 |
defer func() { |
| 758 |
*o = (*o)[:0] |
| 759 |
addOptPool.Put(o) |
| 760 |
}() |
| 761 |
|
| 762 |
*o = append( |
| 763 |
*o, |
| 764 |
metric.WithAttributes( |
| 765 |
attrs..., |
| 766 |
), |
| 767 |
) |
| 768 |
|
| 769 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 770 |
} |
| 771 |
|
| 772 |
// AddSet adds incr to the existing count for set. |
| 773 |
func (m NetworkIO) AddSet(ctx context.Context, incr int64, set attribute.Set) { |
| 774 |
if set.Len() == 0 { |
| 775 |
m.Int64Counter.Add(ctx, incr) |
| 776 |
return |
| 777 |
} |
| 778 |
|
| 779 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 780 |
defer func() { |
| 781 |
*o = (*o)[:0] |
| 782 |
addOptPool.Put(o) |
| 783 |
}() |
| 784 |
|
| 785 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 786 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 787 |
} |
| 788 |
|
| 789 |
// AttrNetworkIODirection returns an optional attribute for the |
| 790 |
// "network.io.direction" semantic convention. It represents the network IO |
| 791 |
// operation direction. |
| 792 |
func (NetworkIO) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue { |
| 793 |
return attribute.String("network.io.direction", string(val)) |
| 794 |
} |
| 795 |
|
| 796 |
// OpenFileDescriptorCount is an instrument used to record metric values |
| 797 |
// conforming to the "process.open_file_descriptor.count" semantic conventions. |
| 798 |
// It represents the number of file descriptors in use by the process. |
| 799 |
type OpenFileDescriptorCount struct { |
| 800 |
metric.Int64UpDownCounter |
| 801 |
} |
| 802 |
|
| 803 |
var newOpenFileDescriptorCountOpts = []metric.Int64UpDownCounterOption{ |
| 804 |
metric.WithDescription("Number of file descriptors in use by the process."), |
| 805 |
metric.WithUnit("{file_descriptor}"), |
| 806 |
} |
| 807 |
|
| 808 |
// NewOpenFileDescriptorCount returns a new OpenFileDescriptorCount instrument. |
| 809 |
func NewOpenFileDescriptorCount( |
| 810 |
m metric.Meter, |
| 811 |
opt ...metric.Int64UpDownCounterOption, |
| 812 |
) (OpenFileDescriptorCount, error) { |
| 813 |
// Check if the meter is nil. |
| 814 |
if m == nil { |
| 815 |
return OpenFileDescriptorCount{noop.Int64UpDownCounter{}}, nil |
| 816 |
} |
| 817 |
|
| 818 |
if len(opt) == 0 { |
| 819 |
opt = newOpenFileDescriptorCountOpts |
| 820 |
} else { |
| 821 |
opt = append(opt, newOpenFileDescriptorCountOpts...) |
| 822 |
} |
| 823 |
|
| 824 |
i, err := m.Int64UpDownCounter( |
| 825 |
"process.open_file_descriptor.count", |
| 826 |
opt..., |
| 827 |
) |
| 828 |
if err != nil { |
| 829 |
return OpenFileDescriptorCount{noop.Int64UpDownCounter{}}, err |
| 830 |
} |
| 831 |
return OpenFileDescriptorCount{i}, nil |
| 832 |
} |
| 833 |
|
| 834 |
// Inst returns the underlying metric instrument. |
| 835 |
func (m OpenFileDescriptorCount) Inst() metric.Int64UpDownCounter { |
| 836 |
return m.Int64UpDownCounter |
| 837 |
} |
| 838 |
|
| 839 |
// Name returns the semantic convention name of the instrument. |
| 840 |
func (OpenFileDescriptorCount) Name() string { |
| 841 |
return "process.open_file_descriptor.count" |
| 842 |
} |
| 843 |
|
| 844 |
// Unit returns the semantic convention unit of the instrument |
| 845 |
func (OpenFileDescriptorCount) Unit() string { |
| 846 |
return "{file_descriptor}" |
| 847 |
} |
| 848 |
|
| 849 |
// Description returns the semantic convention description of the instrument |
| 850 |
func (OpenFileDescriptorCount) Description() string { |
| 851 |
return "Number of file descriptors in use by the process." |
| 852 |
} |
| 853 |
|
| 854 |
// Add adds incr to the existing count for attrs. |
| 855 |
func (m OpenFileDescriptorCount) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) { |
| 856 |
if len(attrs) == 0 { |
| 857 |
m.Int64UpDownCounter.Add(ctx, incr) |
| 858 |
return |
| 859 |
} |
| 860 |
|
| 861 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 862 |
defer func() { |
| 863 |
*o = (*o)[:0] |
| 864 |
addOptPool.Put(o) |
| 865 |
}() |
| 866 |
|
| 867 |
*o = append(*o, metric.WithAttributes(attrs...)) |
| 868 |
m.Int64UpDownCounter.Add(ctx, incr, *o...) |
| 869 |
} |
| 870 |
|
| 871 |
// AddSet adds incr to the existing count for set. |
| 872 |
func (m OpenFileDescriptorCount) AddSet(ctx context.Context, incr int64, set attribute.Set) { |
| 873 |
if set.Len() == 0 { |
| 874 |
m.Int64UpDownCounter.Add(ctx, incr) |
| 875 |
return |
| 876 |
} |
| 877 |
|
| 878 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 879 |
defer func() { |
| 880 |
*o = (*o)[:0] |
| 881 |
addOptPool.Put(o) |
| 882 |
}() |
| 883 |
|
| 884 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 885 |
m.Int64UpDownCounter.Add(ctx, incr, *o...) |
| 886 |
} |
| 887 |
|
| 888 |
// PagingFaults is an instrument used to record metric values conforming to the |
| 889 |
// "process.paging.faults" semantic conventions. It represents the number of page |
| 890 |
// faults the process has made. |
| 891 |
type PagingFaults struct { |
| 892 |
metric.Int64Counter |
| 893 |
} |
| 894 |
|
| 895 |
var newPagingFaultsOpts = []metric.Int64CounterOption{ |
| 896 |
metric.WithDescription("Number of page faults the process has made."), |
| 897 |
metric.WithUnit("{fault}"), |
| 898 |
} |
| 899 |
|
| 900 |
// NewPagingFaults returns a new PagingFaults instrument. |
| 901 |
func NewPagingFaults( |
| 902 |
m metric.Meter, |
| 903 |
opt ...metric.Int64CounterOption, |
| 904 |
) (PagingFaults, error) { |
| 905 |
// Check if the meter is nil. |
| 906 |
if m == nil { |
| 907 |
return PagingFaults{noop.Int64Counter{}}, nil |
| 908 |
} |
| 909 |
|
| 910 |
if len(opt) == 0 { |
| 911 |
opt = newPagingFaultsOpts |
| 912 |
} else { |
| 913 |
opt = append(opt, newPagingFaultsOpts...) |
| 914 |
} |
| 915 |
|
| 916 |
i, err := m.Int64Counter( |
| 917 |
"process.paging.faults", |
| 918 |
opt..., |
| 919 |
) |
| 920 |
if err != nil { |
| 921 |
return PagingFaults{noop.Int64Counter{}}, err |
| 922 |
} |
| 923 |
return PagingFaults{i}, nil |
| 924 |
} |
| 925 |
|
| 926 |
// Inst returns the underlying metric instrument. |
| 927 |
func (m PagingFaults) Inst() metric.Int64Counter { |
| 928 |
return m.Int64Counter |
| 929 |
} |
| 930 |
|
| 931 |
// Name returns the semantic convention name of the instrument. |
| 932 |
func (PagingFaults) Name() string { |
| 933 |
return "process.paging.faults" |
| 934 |
} |
| 935 |
|
| 936 |
// Unit returns the semantic convention unit of the instrument |
| 937 |
func (PagingFaults) Unit() string { |
| 938 |
return "{fault}" |
| 939 |
} |
| 940 |
|
| 941 |
// Description returns the semantic convention description of the instrument |
| 942 |
func (PagingFaults) Description() string { |
| 943 |
return "Number of page faults the process has made." |
| 944 |
} |
| 945 |
|
| 946 |
// Add adds incr to the existing count for attrs. |
| 947 |
// |
| 948 |
// All additional attrs passed are included in the recorded value. |
| 949 |
func (m PagingFaults) Add( |
| 950 |
ctx context.Context, |
| 951 |
incr int64, |
| 952 |
attrs ...attribute.KeyValue, |
| 953 |
) { |
| 954 |
if len(attrs) == 0 { |
| 955 |
m.Int64Counter.Add(ctx, incr) |
| 956 |
return |
| 957 |
} |
| 958 |
|
| 959 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 960 |
defer func() { |
| 961 |
*o = (*o)[:0] |
| 962 |
addOptPool.Put(o) |
| 963 |
}() |
| 964 |
|
| 965 |
*o = append( |
| 966 |
*o, |
| 967 |
metric.WithAttributes( |
| 968 |
attrs..., |
| 969 |
), |
| 970 |
) |
| 971 |
|
| 972 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 973 |
} |
| 974 |
|
| 975 |
// AddSet adds incr to the existing count for set. |
| 976 |
func (m PagingFaults) AddSet(ctx context.Context, incr int64, set attribute.Set) { |
| 977 |
if set.Len() == 0 { |
| 978 |
m.Int64Counter.Add(ctx, incr) |
| 979 |
return |
| 980 |
} |
| 981 |
|
| 982 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 983 |
defer func() { |
| 984 |
*o = (*o)[:0] |
| 985 |
addOptPool.Put(o) |
| 986 |
}() |
| 987 |
|
| 988 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 989 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 990 |
} |
| 991 |
|
| 992 |
// AttrSystemPagingFaultType returns an optional attribute for the |
| 993 |
// "system.paging.fault.type" semantic convention. It represents the paging fault |
| 994 |
// type. |
| 995 |
func (PagingFaults) AttrSystemPagingFaultType(val SystemPagingFaultTypeAttr) attribute.KeyValue { |
| 996 |
return attribute.String("system.paging.fault.type", string(val)) |
| 997 |
} |
| 998 |
|
| 999 |
// ThreadCount is an instrument used to record metric values conforming to the |
| 1000 |
// "process.thread.count" semantic conventions. It represents the process threads |
| 1001 |
// count. |
| 1002 |
type ThreadCount struct { |
| 1003 |
metric.Int64UpDownCounter |
| 1004 |
} |
| 1005 |
|
| 1006 |
var newThreadCountOpts = []metric.Int64UpDownCounterOption{ |
| 1007 |
metric.WithDescription("Process threads count."), |
| 1008 |
metric.WithUnit("{thread}"), |
| 1009 |
} |
| 1010 |
|
| 1011 |
// NewThreadCount returns a new ThreadCount instrument. |
| 1012 |
func NewThreadCount( |
| 1013 |
m metric.Meter, |
| 1014 |
opt ...metric.Int64UpDownCounterOption, |
| 1015 |
) (ThreadCount, error) { |
| 1016 |
// Check if the meter is nil. |
| 1017 |
if m == nil { |
| 1018 |
return ThreadCount{noop.Int64UpDownCounter{}}, nil |
| 1019 |
} |
| 1020 |
|
| 1021 |
if len(opt) == 0 { |
| 1022 |
opt = newThreadCountOpts |
| 1023 |
} else { |
| 1024 |
opt = append(opt, newThreadCountOpts...) |
| 1025 |
} |
| 1026 |
|
| 1027 |
i, err := m.Int64UpDownCounter( |
| 1028 |
"process.thread.count", |
| 1029 |
opt..., |
| 1030 |
) |
| 1031 |
if err != nil { |
| 1032 |
return ThreadCount{noop.Int64UpDownCounter{}}, err |
| 1033 |
} |
| 1034 |
return ThreadCount{i}, nil |
| 1035 |
} |
| 1036 |
|
| 1037 |
// Inst returns the underlying metric instrument. |
| 1038 |
func (m ThreadCount) Inst() metric.Int64UpDownCounter { |
| 1039 |
return m.Int64UpDownCounter |
| 1040 |
} |
| 1041 |
|
| 1042 |
// Name returns the semantic convention name of the instrument. |
| 1043 |
func (ThreadCount) Name() string { |
| 1044 |
return "process.thread.count" |
| 1045 |
} |
| 1046 |
|
| 1047 |
// Unit returns the semantic convention unit of the instrument |
| 1048 |
func (ThreadCount) Unit() string { |
| 1049 |
return "{thread}" |
| 1050 |
} |
| 1051 |
|
| 1052 |
// Description returns the semantic convention description of the instrument |
| 1053 |
func (ThreadCount) Description() string { |
| 1054 |
return "Process threads count." |
| 1055 |
} |
| 1056 |
|
| 1057 |
// Add adds incr to the existing count for attrs. |
| 1058 |
func (m ThreadCount) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) { |
| 1059 |
if len(attrs) == 0 { |
| 1060 |
m.Int64UpDownCounter.Add(ctx, incr) |
| 1061 |
return |
| 1062 |
} |
| 1063 |
|
| 1064 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 1065 |
defer func() { |
| 1066 |
*o = (*o)[:0] |
| 1067 |
addOptPool.Put(o) |
| 1068 |
}() |
| 1069 |
|
| 1070 |
*o = append(*o, metric.WithAttributes(attrs...)) |
| 1071 |
m.Int64UpDownCounter.Add(ctx, incr, *o...) |
| 1072 |
} |
| 1073 |
|
| 1074 |
// AddSet adds incr to the existing count for set. |
| 1075 |
func (m ThreadCount) AddSet(ctx context.Context, incr int64, set attribute.Set) { |
| 1076 |
if set.Len() == 0 { |
| 1077 |
m.Int64UpDownCounter.Add(ctx, incr) |
| 1078 |
return |
| 1079 |
} |
| 1080 |
|
| 1081 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 1082 |
defer func() { |
| 1083 |
*o = (*o)[:0] |
| 1084 |
addOptPool.Put(o) |
| 1085 |
}() |
| 1086 |
|
| 1087 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 1088 |
m.Int64UpDownCounter.Add(ctx, incr, *o...) |
| 1089 |
} |
| 1090 |
|
| 1091 |
// Uptime is an instrument used to record metric values conforming to the |
| 1092 |
// "process.uptime" semantic conventions. It represents the time the process has |
| 1093 |
// been running. |
| 1094 |
type Uptime struct { |
| 1095 |
metric.Float64Gauge |
| 1096 |
} |
| 1097 |
|
| 1098 |
var newUptimeOpts = []metric.Float64GaugeOption{ |
| 1099 |
metric.WithDescription("The time the process has been running."), |
| 1100 |
metric.WithUnit("s"), |
| 1101 |
} |
| 1102 |
|
| 1103 |
// NewUptime returns a new Uptime instrument. |
| 1104 |
func NewUptime( |
| 1105 |
m metric.Meter, |
| 1106 |
opt ...metric.Float64GaugeOption, |
| 1107 |
) (Uptime, error) { |
| 1108 |
// Check if the meter is nil. |
| 1109 |
if m == nil { |
| 1110 |
return Uptime{noop.Float64Gauge{}}, nil |
| 1111 |
} |
| 1112 |
|
| 1113 |
if len(opt) == 0 { |
| 1114 |
opt = newUptimeOpts |
| 1115 |
} else { |
| 1116 |
opt = append(opt, newUptimeOpts...) |
| 1117 |
} |
| 1118 |
|
| 1119 |
i, err := m.Float64Gauge( |
| 1120 |
"process.uptime", |
| 1121 |
opt..., |
| 1122 |
) |
| 1123 |
if err != nil { |
| 1124 |
return Uptime{noop.Float64Gauge{}}, err |
| 1125 |
} |
| 1126 |
return Uptime{i}, nil |
| 1127 |
} |
| 1128 |
|
| 1129 |
// Inst returns the underlying metric instrument. |
| 1130 |
func (m Uptime) Inst() metric.Float64Gauge { |
| 1131 |
return m.Float64Gauge |
| 1132 |
} |
| 1133 |
|
| 1134 |
// Name returns the semantic convention name of the instrument. |
| 1135 |
func (Uptime) Name() string { |
| 1136 |
return "process.uptime" |
| 1137 |
} |
| 1138 |
|
| 1139 |
// Unit returns the semantic convention unit of the instrument |
| 1140 |
func (Uptime) Unit() string { |
| 1141 |
return "s" |
| 1142 |
} |
| 1143 |
|
| 1144 |
// Description returns the semantic convention description of the instrument |
| 1145 |
func (Uptime) Description() string { |
| 1146 |
return "The time the process has been running." |
| 1147 |
} |
| 1148 |
|
| 1149 |
// Record records val to the current distribution for attrs. |
| 1150 |
// |
| 1151 |
// Instrumentations SHOULD use a gauge with type `double` and measure uptime in |
| 1152 |
// seconds as a floating point number with the highest precision available. |
| 1153 |
// The actual accuracy would depend on the instrumentation and operating system. |
| 1154 |
func (m Uptime) Record(ctx context.Context, val float64, attrs ...attribute.KeyValue) { |
| 1155 |
if len(attrs) == 0 { |
| 1156 |
m.Float64Gauge.Record(ctx, val) |
| 1157 |
return |
| 1158 |
} |
| 1159 |
|
| 1160 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 1161 |
defer func() { |
| 1162 |
*o = (*o)[:0] |
| 1163 |
recOptPool.Put(o) |
| 1164 |
}() |
| 1165 |
|
| 1166 |
*o = append(*o, metric.WithAttributes(attrs...)) |
| 1167 |
m.Float64Gauge.Record(ctx, val, *o...) |
| 1168 |
} |
| 1169 |
|
| 1170 |
// RecordSet records val to the current distribution for set. |
| 1171 |
// |
| 1172 |
// Instrumentations SHOULD use a gauge with type `double` and measure uptime in |
| 1173 |
// seconds as a floating point number with the highest precision available. |
| 1174 |
// The actual accuracy would depend on the instrumentation and operating system. |
| 1175 |
func (m Uptime) RecordSet(ctx context.Context, val float64, set attribute.Set) { |
| 1176 |
if set.Len() == 0 { |
| 1177 |
m.Float64Gauge.Record(ctx, val) |
| 1178 |
return |
| 1179 |
} |
| 1180 |
|
| 1181 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 1182 |
defer func() { |
| 1183 |
*o = (*o)[:0] |
| 1184 |
recOptPool.Put(o) |
| 1185 |
}() |
| 1186 |
|
| 1187 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 1188 |
m.Float64Gauge.Record(ctx, val, *o...) |
| 1189 |
} |