| 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 faasconv provides types and functionality for OpenTelemetry semantic |
| 7 |
// conventions in the "faas" namespace. |
| 8 |
package faasconv |
| 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 |
// TriggerAttr is an attribute conforming to the faas.trigger semantic |
| 25 |
// conventions. It represents the type of the trigger which caused this function |
| 26 |
// invocation. |
| 27 |
type TriggerAttr string |
| 28 |
|
| 29 |
var ( |
| 30 |
// TriggerDatasource is a response to some data source operation such as a |
| 31 |
// database or filesystem read/write. |
| 32 |
TriggerDatasource TriggerAttr = "datasource" |
| 33 |
// TriggerHTTP is the to provide an answer to an inbound HTTP request. |
| 34 |
TriggerHTTP TriggerAttr = "http" |
| 35 |
// TriggerPubSub is a function is set to be executed when messages are sent to a |
| 36 |
// messaging system. |
| 37 |
TriggerPubSub TriggerAttr = "pubsub" |
| 38 |
// TriggerTimer is a function is scheduled to be executed regularly. |
| 39 |
TriggerTimer TriggerAttr = "timer" |
| 40 |
// TriggerOther is the if none of the others apply. |
| 41 |
TriggerOther TriggerAttr = "other" |
| 42 |
) |
| 43 |
|
| 44 |
// Coldstarts is an instrument used to record metric values conforming to the |
| 45 |
// "faas.coldstarts" semantic conventions. It represents the number of invocation |
| 46 |
// cold starts. |
| 47 |
type Coldstarts struct { |
| 48 |
metric.Int64Counter |
| 49 |
} |
| 50 |
|
| 51 |
var newColdstartsOpts = []metric.Int64CounterOption{ |
| 52 |
metric.WithDescription("Number of invocation cold starts."), |
| 53 |
metric.WithUnit("{coldstart}"), |
| 54 |
} |
| 55 |
|
| 56 |
// NewColdstarts returns a new Coldstarts instrument. |
| 57 |
func NewColdstarts( |
| 58 |
m metric.Meter, |
| 59 |
opt ...metric.Int64CounterOption, |
| 60 |
) (Coldstarts, error) { |
| 61 |
// Check if the meter is nil. |
| 62 |
if m == nil { |
| 63 |
return Coldstarts{noop.Int64Counter{}}, nil |
| 64 |
} |
| 65 |
|
| 66 |
if len(opt) == 0 { |
| 67 |
opt = newColdstartsOpts |
| 68 |
} else { |
| 69 |
opt = append(opt, newColdstartsOpts...) |
| 70 |
} |
| 71 |
|
| 72 |
i, err := m.Int64Counter( |
| 73 |
"faas.coldstarts", |
| 74 |
opt..., |
| 75 |
) |
| 76 |
if err != nil { |
| 77 |
return Coldstarts{noop.Int64Counter{}}, err |
| 78 |
} |
| 79 |
return Coldstarts{i}, nil |
| 80 |
} |
| 81 |
|
| 82 |
// Inst returns the underlying metric instrument. |
| 83 |
func (m Coldstarts) Inst() metric.Int64Counter { |
| 84 |
return m.Int64Counter |
| 85 |
} |
| 86 |
|
| 87 |
// Name returns the semantic convention name of the instrument. |
| 88 |
func (Coldstarts) Name() string { |
| 89 |
return "faas.coldstarts" |
| 90 |
} |
| 91 |
|
| 92 |
// Unit returns the semantic convention unit of the instrument |
| 93 |
func (Coldstarts) Unit() string { |
| 94 |
return "{coldstart}" |
| 95 |
} |
| 96 |
|
| 97 |
// Description returns the semantic convention description of the instrument |
| 98 |
func (Coldstarts) Description() string { |
| 99 |
return "Number of invocation cold starts." |
| 100 |
} |
| 101 |
|
| 102 |
// Add adds incr to the existing count for attrs. |
| 103 |
// |
| 104 |
// All additional attrs passed are included in the recorded value. |
| 105 |
func (m Coldstarts) Add( |
| 106 |
ctx context.Context, |
| 107 |
incr int64, |
| 108 |
attrs ...attribute.KeyValue, |
| 109 |
) { |
| 110 |
if len(attrs) == 0 { |
| 111 |
m.Int64Counter.Add(ctx, incr) |
| 112 |
return |
| 113 |
} |
| 114 |
|
| 115 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 116 |
defer func() { |
| 117 |
*o = (*o)[:0] |
| 118 |
addOptPool.Put(o) |
| 119 |
}() |
| 120 |
|
| 121 |
*o = append( |
| 122 |
*o, |
| 123 |
metric.WithAttributes( |
| 124 |
attrs..., |
| 125 |
), |
| 126 |
) |
| 127 |
|
| 128 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 129 |
} |
| 130 |
|
| 131 |
// AddSet adds incr to the existing count for set. |
| 132 |
func (m Coldstarts) AddSet(ctx context.Context, incr int64, set attribute.Set) { |
| 133 |
if set.Len() == 0 { |
| 134 |
m.Int64Counter.Add(ctx, incr) |
| 135 |
return |
| 136 |
} |
| 137 |
|
| 138 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 139 |
defer func() { |
| 140 |
*o = (*o)[:0] |
| 141 |
addOptPool.Put(o) |
| 142 |
}() |
| 143 |
|
| 144 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 145 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 146 |
} |
| 147 |
|
| 148 |
// AttrTrigger returns an optional attribute for the "faas.trigger" semantic |
| 149 |
// convention. It represents the type of the trigger which caused this function |
| 150 |
// invocation. |
| 151 |
func (Coldstarts) AttrTrigger(val TriggerAttr) attribute.KeyValue { |
| 152 |
return attribute.String("faas.trigger", string(val)) |
| 153 |
} |
| 154 |
|
| 155 |
// CPUUsage is an instrument used to record metric values conforming to the |
| 156 |
// "faas.cpu_usage" semantic conventions. It represents the distribution of CPU |
| 157 |
// usage per invocation. |
| 158 |
type CPUUsage struct { |
| 159 |
metric.Float64Histogram |
| 160 |
} |
| 161 |
|
| 162 |
var newCPUUsageOpts = []metric.Float64HistogramOption{ |
| 163 |
metric.WithDescription("Distribution of CPU usage per invocation."), |
| 164 |
metric.WithUnit("s"), |
| 165 |
} |
| 166 |
|
| 167 |
// NewCPUUsage returns a new CPUUsage instrument. |
| 168 |
func NewCPUUsage( |
| 169 |
m metric.Meter, |
| 170 |
opt ...metric.Float64HistogramOption, |
| 171 |
) (CPUUsage, error) { |
| 172 |
// Check if the meter is nil. |
| 173 |
if m == nil { |
| 174 |
return CPUUsage{noop.Float64Histogram{}}, nil |
| 175 |
} |
| 176 |
|
| 177 |
if len(opt) == 0 { |
| 178 |
opt = newCPUUsageOpts |
| 179 |
} else { |
| 180 |
opt = append(opt, newCPUUsageOpts...) |
| 181 |
} |
| 182 |
|
| 183 |
i, err := m.Float64Histogram( |
| 184 |
"faas.cpu_usage", |
| 185 |
opt..., |
| 186 |
) |
| 187 |
if err != nil { |
| 188 |
return CPUUsage{noop.Float64Histogram{}}, err |
| 189 |
} |
| 190 |
return CPUUsage{i}, nil |
| 191 |
} |
| 192 |
|
| 193 |
// Inst returns the underlying metric instrument. |
| 194 |
func (m CPUUsage) Inst() metric.Float64Histogram { |
| 195 |
return m.Float64Histogram |
| 196 |
} |
| 197 |
|
| 198 |
// Name returns the semantic convention name of the instrument. |
| 199 |
func (CPUUsage) Name() string { |
| 200 |
return "faas.cpu_usage" |
| 201 |
} |
| 202 |
|
| 203 |
// Unit returns the semantic convention unit of the instrument |
| 204 |
func (CPUUsage) Unit() string { |
| 205 |
return "s" |
| 206 |
} |
| 207 |
|
| 208 |
// Description returns the semantic convention description of the instrument |
| 209 |
func (CPUUsage) Description() string { |
| 210 |
return "Distribution of CPU usage per invocation." |
| 211 |
} |
| 212 |
|
| 213 |
// Record records val to the current distribution for attrs. |
| 214 |
// |
| 215 |
// All additional attrs passed are included in the recorded value. |
| 216 |
func (m CPUUsage) Record( |
| 217 |
ctx context.Context, |
| 218 |
val float64, |
| 219 |
attrs ...attribute.KeyValue, |
| 220 |
) { |
| 221 |
if len(attrs) == 0 { |
| 222 |
m.Float64Histogram.Record(ctx, val) |
| 223 |
return |
| 224 |
} |
| 225 |
|
| 226 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 227 |
defer func() { |
| 228 |
*o = (*o)[:0] |
| 229 |
recOptPool.Put(o) |
| 230 |
}() |
| 231 |
|
| 232 |
*o = append( |
| 233 |
*o, |
| 234 |
metric.WithAttributes( |
| 235 |
attrs..., |
| 236 |
), |
| 237 |
) |
| 238 |
|
| 239 |
m.Float64Histogram.Record(ctx, val, *o...) |
| 240 |
} |
| 241 |
|
| 242 |
// RecordSet records val to the current distribution for set. |
| 243 |
func (m CPUUsage) RecordSet(ctx context.Context, val float64, set attribute.Set) { |
| 244 |
if set.Len() == 0 { |
| 245 |
m.Float64Histogram.Record(ctx, val) |
| 246 |
return |
| 247 |
} |
| 248 |
|
| 249 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 250 |
defer func() { |
| 251 |
*o = (*o)[:0] |
| 252 |
recOptPool.Put(o) |
| 253 |
}() |
| 254 |
|
| 255 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 256 |
m.Float64Histogram.Record(ctx, val, *o...) |
| 257 |
} |
| 258 |
|
| 259 |
// AttrTrigger returns an optional attribute for the "faas.trigger" semantic |
| 260 |
// convention. It represents the type of the trigger which caused this function |
| 261 |
// invocation. |
| 262 |
func (CPUUsage) AttrTrigger(val TriggerAttr) attribute.KeyValue { |
| 263 |
return attribute.String("faas.trigger", string(val)) |
| 264 |
} |
| 265 |
|
| 266 |
// Errors is an instrument used to record metric values conforming to the |
| 267 |
// "faas.errors" semantic conventions. It represents the number of invocation |
| 268 |
// errors. |
| 269 |
type Errors struct { |
| 270 |
metric.Int64Counter |
| 271 |
} |
| 272 |
|
| 273 |
var newErrorsOpts = []metric.Int64CounterOption{ |
| 274 |
metric.WithDescription("Number of invocation errors."), |
| 275 |
metric.WithUnit("{error}"), |
| 276 |
} |
| 277 |
|
| 278 |
// NewErrors returns a new Errors instrument. |
| 279 |
func NewErrors( |
| 280 |
m metric.Meter, |
| 281 |
opt ...metric.Int64CounterOption, |
| 282 |
) (Errors, error) { |
| 283 |
// Check if the meter is nil. |
| 284 |
if m == nil { |
| 285 |
return Errors{noop.Int64Counter{}}, nil |
| 286 |
} |
| 287 |
|
| 288 |
if len(opt) == 0 { |
| 289 |
opt = newErrorsOpts |
| 290 |
} else { |
| 291 |
opt = append(opt, newErrorsOpts...) |
| 292 |
} |
| 293 |
|
| 294 |
i, err := m.Int64Counter( |
| 295 |
"faas.errors", |
| 296 |
opt..., |
| 297 |
) |
| 298 |
if err != nil { |
| 299 |
return Errors{noop.Int64Counter{}}, err |
| 300 |
} |
| 301 |
return Errors{i}, nil |
| 302 |
} |
| 303 |
|
| 304 |
// Inst returns the underlying metric instrument. |
| 305 |
func (m Errors) Inst() metric.Int64Counter { |
| 306 |
return m.Int64Counter |
| 307 |
} |
| 308 |
|
| 309 |
// Name returns the semantic convention name of the instrument. |
| 310 |
func (Errors) Name() string { |
| 311 |
return "faas.errors" |
| 312 |
} |
| 313 |
|
| 314 |
// Unit returns the semantic convention unit of the instrument |
| 315 |
func (Errors) Unit() string { |
| 316 |
return "{error}" |
| 317 |
} |
| 318 |
|
| 319 |
// Description returns the semantic convention description of the instrument |
| 320 |
func (Errors) Description() string { |
| 321 |
return "Number of invocation errors." |
| 322 |
} |
| 323 |
|
| 324 |
// Add adds incr to the existing count for attrs. |
| 325 |
// |
| 326 |
// All additional attrs passed are included in the recorded value. |
| 327 |
func (m Errors) Add( |
| 328 |
ctx context.Context, |
| 329 |
incr int64, |
| 330 |
attrs ...attribute.KeyValue, |
| 331 |
) { |
| 332 |
if len(attrs) == 0 { |
| 333 |
m.Int64Counter.Add(ctx, incr) |
| 334 |
return |
| 335 |
} |
| 336 |
|
| 337 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 338 |
defer func() { |
| 339 |
*o = (*o)[:0] |
| 340 |
addOptPool.Put(o) |
| 341 |
}() |
| 342 |
|
| 343 |
*o = append( |
| 344 |
*o, |
| 345 |
metric.WithAttributes( |
| 346 |
attrs..., |
| 347 |
), |
| 348 |
) |
| 349 |
|
| 350 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 351 |
} |
| 352 |
|
| 353 |
// AddSet adds incr to the existing count for set. |
| 354 |
func (m Errors) AddSet(ctx context.Context, incr int64, set attribute.Set) { |
| 355 |
if set.Len() == 0 { |
| 356 |
m.Int64Counter.Add(ctx, incr) |
| 357 |
return |
| 358 |
} |
| 359 |
|
| 360 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 361 |
defer func() { |
| 362 |
*o = (*o)[:0] |
| 363 |
addOptPool.Put(o) |
| 364 |
}() |
| 365 |
|
| 366 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 367 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 368 |
} |
| 369 |
|
| 370 |
// AttrTrigger returns an optional attribute for the "faas.trigger" semantic |
| 371 |
// convention. It represents the type of the trigger which caused this function |
| 372 |
// invocation. |
| 373 |
func (Errors) AttrTrigger(val TriggerAttr) attribute.KeyValue { |
| 374 |
return attribute.String("faas.trigger", string(val)) |
| 375 |
} |
| 376 |
|
| 377 |
// InitDuration is an instrument used to record metric values conforming to the |
| 378 |
// "faas.init_duration" semantic conventions. It represents the measures the |
| 379 |
// duration of the function's initialization, such as a cold start. |
| 380 |
type InitDuration struct { |
| 381 |
metric.Float64Histogram |
| 382 |
} |
| 383 |
|
| 384 |
var newInitDurationOpts = []metric.Float64HistogramOption{ |
| 385 |
metric.WithDescription("Measures the duration of the function's initialization, such as a cold start."), |
| 386 |
metric.WithUnit("s"), |
| 387 |
} |
| 388 |
|
| 389 |
// NewInitDuration returns a new InitDuration instrument. |
| 390 |
func NewInitDuration( |
| 391 |
m metric.Meter, |
| 392 |
opt ...metric.Float64HistogramOption, |
| 393 |
) (InitDuration, error) { |
| 394 |
// Check if the meter is nil. |
| 395 |
if m == nil { |
| 396 |
return InitDuration{noop.Float64Histogram{}}, nil |
| 397 |
} |
| 398 |
|
| 399 |
if len(opt) == 0 { |
| 400 |
opt = newInitDurationOpts |
| 401 |
} else { |
| 402 |
opt = append(opt, newInitDurationOpts...) |
| 403 |
} |
| 404 |
|
| 405 |
i, err := m.Float64Histogram( |
| 406 |
"faas.init_duration", |
| 407 |
opt..., |
| 408 |
) |
| 409 |
if err != nil { |
| 410 |
return InitDuration{noop.Float64Histogram{}}, err |
| 411 |
} |
| 412 |
return InitDuration{i}, nil |
| 413 |
} |
| 414 |
|
| 415 |
// Inst returns the underlying metric instrument. |
| 416 |
func (m InitDuration) Inst() metric.Float64Histogram { |
| 417 |
return m.Float64Histogram |
| 418 |
} |
| 419 |
|
| 420 |
// Name returns the semantic convention name of the instrument. |
| 421 |
func (InitDuration) Name() string { |
| 422 |
return "faas.init_duration" |
| 423 |
} |
| 424 |
|
| 425 |
// Unit returns the semantic convention unit of the instrument |
| 426 |
func (InitDuration) Unit() string { |
| 427 |
return "s" |
| 428 |
} |
| 429 |
|
| 430 |
// Description returns the semantic convention description of the instrument |
| 431 |
func (InitDuration) Description() string { |
| 432 |
return "Measures the duration of the function's initialization, such as a cold start." |
| 433 |
} |
| 434 |
|
| 435 |
// Record records val to the current distribution for attrs. |
| 436 |
// |
| 437 |
// All additional attrs passed are included in the recorded value. |
| 438 |
func (m InitDuration) Record( |
| 439 |
ctx context.Context, |
| 440 |
val float64, |
| 441 |
attrs ...attribute.KeyValue, |
| 442 |
) { |
| 443 |
if len(attrs) == 0 { |
| 444 |
m.Float64Histogram.Record(ctx, val) |
| 445 |
return |
| 446 |
} |
| 447 |
|
| 448 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 449 |
defer func() { |
| 450 |
*o = (*o)[:0] |
| 451 |
recOptPool.Put(o) |
| 452 |
}() |
| 453 |
|
| 454 |
*o = append( |
| 455 |
*o, |
| 456 |
metric.WithAttributes( |
| 457 |
attrs..., |
| 458 |
), |
| 459 |
) |
| 460 |
|
| 461 |
m.Float64Histogram.Record(ctx, val, *o...) |
| 462 |
} |
| 463 |
|
| 464 |
// RecordSet records val to the current distribution for set. |
| 465 |
func (m InitDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) { |
| 466 |
if set.Len() == 0 { |
| 467 |
m.Float64Histogram.Record(ctx, val) |
| 468 |
return |
| 469 |
} |
| 470 |
|
| 471 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 472 |
defer func() { |
| 473 |
*o = (*o)[:0] |
| 474 |
recOptPool.Put(o) |
| 475 |
}() |
| 476 |
|
| 477 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 478 |
m.Float64Histogram.Record(ctx, val, *o...) |
| 479 |
} |
| 480 |
|
| 481 |
// AttrTrigger returns an optional attribute for the "faas.trigger" semantic |
| 482 |
// convention. It represents the type of the trigger which caused this function |
| 483 |
// invocation. |
| 484 |
func (InitDuration) AttrTrigger(val TriggerAttr) attribute.KeyValue { |
| 485 |
return attribute.String("faas.trigger", string(val)) |
| 486 |
} |
| 487 |
|
| 488 |
// Invocations is an instrument used to record metric values conforming to the |
| 489 |
// "faas.invocations" semantic conventions. It represents the number of |
| 490 |
// successful invocations. |
| 491 |
type Invocations struct { |
| 492 |
metric.Int64Counter |
| 493 |
} |
| 494 |
|
| 495 |
var newInvocationsOpts = []metric.Int64CounterOption{ |
| 496 |
metric.WithDescription("Number of successful invocations."), |
| 497 |
metric.WithUnit("{invocation}"), |
| 498 |
} |
| 499 |
|
| 500 |
// NewInvocations returns a new Invocations instrument. |
| 501 |
func NewInvocations( |
| 502 |
m metric.Meter, |
| 503 |
opt ...metric.Int64CounterOption, |
| 504 |
) (Invocations, error) { |
| 505 |
// Check if the meter is nil. |
| 506 |
if m == nil { |
| 507 |
return Invocations{noop.Int64Counter{}}, nil |
| 508 |
} |
| 509 |
|
| 510 |
if len(opt) == 0 { |
| 511 |
opt = newInvocationsOpts |
| 512 |
} else { |
| 513 |
opt = append(opt, newInvocationsOpts...) |
| 514 |
} |
| 515 |
|
| 516 |
i, err := m.Int64Counter( |
| 517 |
"faas.invocations", |
| 518 |
opt..., |
| 519 |
) |
| 520 |
if err != nil { |
| 521 |
return Invocations{noop.Int64Counter{}}, err |
| 522 |
} |
| 523 |
return Invocations{i}, nil |
| 524 |
} |
| 525 |
|
| 526 |
// Inst returns the underlying metric instrument. |
| 527 |
func (m Invocations) Inst() metric.Int64Counter { |
| 528 |
return m.Int64Counter |
| 529 |
} |
| 530 |
|
| 531 |
// Name returns the semantic convention name of the instrument. |
| 532 |
func (Invocations) Name() string { |
| 533 |
return "faas.invocations" |
| 534 |
} |
| 535 |
|
| 536 |
// Unit returns the semantic convention unit of the instrument |
| 537 |
func (Invocations) Unit() string { |
| 538 |
return "{invocation}" |
| 539 |
} |
| 540 |
|
| 541 |
// Description returns the semantic convention description of the instrument |
| 542 |
func (Invocations) Description() string { |
| 543 |
return "Number of successful invocations." |
| 544 |
} |
| 545 |
|
| 546 |
// Add adds incr to the existing count for attrs. |
| 547 |
// |
| 548 |
// All additional attrs passed are included in the recorded value. |
| 549 |
func (m Invocations) Add( |
| 550 |
ctx context.Context, |
| 551 |
incr int64, |
| 552 |
attrs ...attribute.KeyValue, |
| 553 |
) { |
| 554 |
if len(attrs) == 0 { |
| 555 |
m.Int64Counter.Add(ctx, incr) |
| 556 |
return |
| 557 |
} |
| 558 |
|
| 559 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 560 |
defer func() { |
| 561 |
*o = (*o)[:0] |
| 562 |
addOptPool.Put(o) |
| 563 |
}() |
| 564 |
|
| 565 |
*o = append( |
| 566 |
*o, |
| 567 |
metric.WithAttributes( |
| 568 |
attrs..., |
| 569 |
), |
| 570 |
) |
| 571 |
|
| 572 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 573 |
} |
| 574 |
|
| 575 |
// AddSet adds incr to the existing count for set. |
| 576 |
func (m Invocations) AddSet(ctx context.Context, incr int64, set attribute.Set) { |
| 577 |
if set.Len() == 0 { |
| 578 |
m.Int64Counter.Add(ctx, incr) |
| 579 |
return |
| 580 |
} |
| 581 |
|
| 582 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 583 |
defer func() { |
| 584 |
*o = (*o)[:0] |
| 585 |
addOptPool.Put(o) |
| 586 |
}() |
| 587 |
|
| 588 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 589 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 590 |
} |
| 591 |
|
| 592 |
// AttrTrigger returns an optional attribute for the "faas.trigger" semantic |
| 593 |
// convention. It represents the type of the trigger which caused this function |
| 594 |
// invocation. |
| 595 |
func (Invocations) AttrTrigger(val TriggerAttr) attribute.KeyValue { |
| 596 |
return attribute.String("faas.trigger", string(val)) |
| 597 |
} |
| 598 |
|
| 599 |
// InvokeDuration is an instrument used to record metric values conforming to the |
| 600 |
// "faas.invoke_duration" semantic conventions. It represents the measures the |
| 601 |
// duration of the function's logic execution. |
| 602 |
type InvokeDuration struct { |
| 603 |
metric.Float64Histogram |
| 604 |
} |
| 605 |
|
| 606 |
var newInvokeDurationOpts = []metric.Float64HistogramOption{ |
| 607 |
metric.WithDescription("Measures the duration of the function's logic execution."), |
| 608 |
metric.WithUnit("s"), |
| 609 |
} |
| 610 |
|
| 611 |
// NewInvokeDuration returns a new InvokeDuration instrument. |
| 612 |
func NewInvokeDuration( |
| 613 |
m metric.Meter, |
| 614 |
opt ...metric.Float64HistogramOption, |
| 615 |
) (InvokeDuration, error) { |
| 616 |
// Check if the meter is nil. |
| 617 |
if m == nil { |
| 618 |
return InvokeDuration{noop.Float64Histogram{}}, nil |
| 619 |
} |
| 620 |
|
| 621 |
if len(opt) == 0 { |
| 622 |
opt = newInvokeDurationOpts |
| 623 |
} else { |
| 624 |
opt = append(opt, newInvokeDurationOpts...) |
| 625 |
} |
| 626 |
|
| 627 |
i, err := m.Float64Histogram( |
| 628 |
"faas.invoke_duration", |
| 629 |
opt..., |
| 630 |
) |
| 631 |
if err != nil { |
| 632 |
return InvokeDuration{noop.Float64Histogram{}}, err |
| 633 |
} |
| 634 |
return InvokeDuration{i}, nil |
| 635 |
} |
| 636 |
|
| 637 |
// Inst returns the underlying metric instrument. |
| 638 |
func (m InvokeDuration) Inst() metric.Float64Histogram { |
| 639 |
return m.Float64Histogram |
| 640 |
} |
| 641 |
|
| 642 |
// Name returns the semantic convention name of the instrument. |
| 643 |
func (InvokeDuration) Name() string { |
| 644 |
return "faas.invoke_duration" |
| 645 |
} |
| 646 |
|
| 647 |
// Unit returns the semantic convention unit of the instrument |
| 648 |
func (InvokeDuration) Unit() string { |
| 649 |
return "s" |
| 650 |
} |
| 651 |
|
| 652 |
// Description returns the semantic convention description of the instrument |
| 653 |
func (InvokeDuration) Description() string { |
| 654 |
return "Measures the duration of the function's logic execution." |
| 655 |
} |
| 656 |
|
| 657 |
// Record records val to the current distribution for attrs. |
| 658 |
// |
| 659 |
// All additional attrs passed are included in the recorded value. |
| 660 |
func (m InvokeDuration) Record( |
| 661 |
ctx context.Context, |
| 662 |
val float64, |
| 663 |
attrs ...attribute.KeyValue, |
| 664 |
) { |
| 665 |
if len(attrs) == 0 { |
| 666 |
m.Float64Histogram.Record(ctx, val) |
| 667 |
return |
| 668 |
} |
| 669 |
|
| 670 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 671 |
defer func() { |
| 672 |
*o = (*o)[:0] |
| 673 |
recOptPool.Put(o) |
| 674 |
}() |
| 675 |
|
| 676 |
*o = append( |
| 677 |
*o, |
| 678 |
metric.WithAttributes( |
| 679 |
attrs..., |
| 680 |
), |
| 681 |
) |
| 682 |
|
| 683 |
m.Float64Histogram.Record(ctx, val, *o...) |
| 684 |
} |
| 685 |
|
| 686 |
// RecordSet records val to the current distribution for set. |
| 687 |
func (m InvokeDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) { |
| 688 |
if set.Len() == 0 { |
| 689 |
m.Float64Histogram.Record(ctx, val) |
| 690 |
return |
| 691 |
} |
| 692 |
|
| 693 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 694 |
defer func() { |
| 695 |
*o = (*o)[:0] |
| 696 |
recOptPool.Put(o) |
| 697 |
}() |
| 698 |
|
| 699 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 700 |
m.Float64Histogram.Record(ctx, val, *o...) |
| 701 |
} |
| 702 |
|
| 703 |
// AttrTrigger returns an optional attribute for the "faas.trigger" semantic |
| 704 |
// convention. It represents the type of the trigger which caused this function |
| 705 |
// invocation. |
| 706 |
func (InvokeDuration) AttrTrigger(val TriggerAttr) attribute.KeyValue { |
| 707 |
return attribute.String("faas.trigger", string(val)) |
| 708 |
} |
| 709 |
|
| 710 |
// MemUsage is an instrument used to record metric values conforming to the |
| 711 |
// "faas.mem_usage" semantic conventions. It represents the distribution of max |
| 712 |
// memory usage per invocation. |
| 713 |
type MemUsage struct { |
| 714 |
metric.Int64Histogram |
| 715 |
} |
| 716 |
|
| 717 |
var newMemUsageOpts = []metric.Int64HistogramOption{ |
| 718 |
metric.WithDescription("Distribution of max memory usage per invocation."), |
| 719 |
metric.WithUnit("By"), |
| 720 |
} |
| 721 |
|
| 722 |
// NewMemUsage returns a new MemUsage instrument. |
| 723 |
func NewMemUsage( |
| 724 |
m metric.Meter, |
| 725 |
opt ...metric.Int64HistogramOption, |
| 726 |
) (MemUsage, error) { |
| 727 |
// Check if the meter is nil. |
| 728 |
if m == nil { |
| 729 |
return MemUsage{noop.Int64Histogram{}}, nil |
| 730 |
} |
| 731 |
|
| 732 |
if len(opt) == 0 { |
| 733 |
opt = newMemUsageOpts |
| 734 |
} else { |
| 735 |
opt = append(opt, newMemUsageOpts...) |
| 736 |
} |
| 737 |
|
| 738 |
i, err := m.Int64Histogram( |
| 739 |
"faas.mem_usage", |
| 740 |
opt..., |
| 741 |
) |
| 742 |
if err != nil { |
| 743 |
return MemUsage{noop.Int64Histogram{}}, err |
| 744 |
} |
| 745 |
return MemUsage{i}, nil |
| 746 |
} |
| 747 |
|
| 748 |
// Inst returns the underlying metric instrument. |
| 749 |
func (m MemUsage) Inst() metric.Int64Histogram { |
| 750 |
return m.Int64Histogram |
| 751 |
} |
| 752 |
|
| 753 |
// Name returns the semantic convention name of the instrument. |
| 754 |
func (MemUsage) Name() string { |
| 755 |
return "faas.mem_usage" |
| 756 |
} |
| 757 |
|
| 758 |
// Unit returns the semantic convention unit of the instrument |
| 759 |
func (MemUsage) Unit() string { |
| 760 |
return "By" |
| 761 |
} |
| 762 |
|
| 763 |
// Description returns the semantic convention description of the instrument |
| 764 |
func (MemUsage) Description() string { |
| 765 |
return "Distribution of max memory usage per invocation." |
| 766 |
} |
| 767 |
|
| 768 |
// Record records val to the current distribution for attrs. |
| 769 |
// |
| 770 |
// All additional attrs passed are included in the recorded value. |
| 771 |
func (m MemUsage) Record( |
| 772 |
ctx context.Context, |
| 773 |
val int64, |
| 774 |
attrs ...attribute.KeyValue, |
| 775 |
) { |
| 776 |
if len(attrs) == 0 { |
| 777 |
m.Int64Histogram.Record(ctx, val) |
| 778 |
return |
| 779 |
} |
| 780 |
|
| 781 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 782 |
defer func() { |
| 783 |
*o = (*o)[:0] |
| 784 |
recOptPool.Put(o) |
| 785 |
}() |
| 786 |
|
| 787 |
*o = append( |
| 788 |
*o, |
| 789 |
metric.WithAttributes( |
| 790 |
attrs..., |
| 791 |
), |
| 792 |
) |
| 793 |
|
| 794 |
m.Int64Histogram.Record(ctx, val, *o...) |
| 795 |
} |
| 796 |
|
| 797 |
// RecordSet records val to the current distribution for set. |
| 798 |
func (m MemUsage) RecordSet(ctx context.Context, val int64, set attribute.Set) { |
| 799 |
if set.Len() == 0 { |
| 800 |
m.Int64Histogram.Record(ctx, val) |
| 801 |
return |
| 802 |
} |
| 803 |
|
| 804 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 805 |
defer func() { |
| 806 |
*o = (*o)[:0] |
| 807 |
recOptPool.Put(o) |
| 808 |
}() |
| 809 |
|
| 810 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 811 |
m.Int64Histogram.Record(ctx, val, *o...) |
| 812 |
} |
| 813 |
|
| 814 |
// AttrTrigger returns an optional attribute for the "faas.trigger" semantic |
| 815 |
// convention. It represents the type of the trigger which caused this function |
| 816 |
// invocation. |
| 817 |
func (MemUsage) AttrTrigger(val TriggerAttr) attribute.KeyValue { |
| 818 |
return attribute.String("faas.trigger", string(val)) |
| 819 |
} |
| 820 |
|
| 821 |
// NetIO is an instrument used to record metric values conforming to the |
| 822 |
// "faas.net_io" semantic conventions. It represents the distribution of net I/O |
| 823 |
// usage per invocation. |
| 824 |
type NetIO struct { |
| 825 |
metric.Int64Histogram |
| 826 |
} |
| 827 |
|
| 828 |
var newNetIOOpts = []metric.Int64HistogramOption{ |
| 829 |
metric.WithDescription("Distribution of net I/O usage per invocation."), |
| 830 |
metric.WithUnit("By"), |
| 831 |
} |
| 832 |
|
| 833 |
// NewNetIO returns a new NetIO instrument. |
| 834 |
func NewNetIO( |
| 835 |
m metric.Meter, |
| 836 |
opt ...metric.Int64HistogramOption, |
| 837 |
) (NetIO, error) { |
| 838 |
// Check if the meter is nil. |
| 839 |
if m == nil { |
| 840 |
return NetIO{noop.Int64Histogram{}}, nil |
| 841 |
} |
| 842 |
|
| 843 |
if len(opt) == 0 { |
| 844 |
opt = newNetIOOpts |
| 845 |
} else { |
| 846 |
opt = append(opt, newNetIOOpts...) |
| 847 |
} |
| 848 |
|
| 849 |
i, err := m.Int64Histogram( |
| 850 |
"faas.net_io", |
| 851 |
opt..., |
| 852 |
) |
| 853 |
if err != nil { |
| 854 |
return NetIO{noop.Int64Histogram{}}, err |
| 855 |
} |
| 856 |
return NetIO{i}, nil |
| 857 |
} |
| 858 |
|
| 859 |
// Inst returns the underlying metric instrument. |
| 860 |
func (m NetIO) Inst() metric.Int64Histogram { |
| 861 |
return m.Int64Histogram |
| 862 |
} |
| 863 |
|
| 864 |
// Name returns the semantic convention name of the instrument. |
| 865 |
func (NetIO) Name() string { |
| 866 |
return "faas.net_io" |
| 867 |
} |
| 868 |
|
| 869 |
// Unit returns the semantic convention unit of the instrument |
| 870 |
func (NetIO) Unit() string { |
| 871 |
return "By" |
| 872 |
} |
| 873 |
|
| 874 |
// Description returns the semantic convention description of the instrument |
| 875 |
func (NetIO) Description() string { |
| 876 |
return "Distribution of net I/O usage per invocation." |
| 877 |
} |
| 878 |
|
| 879 |
// Record records val to the current distribution for attrs. |
| 880 |
// |
| 881 |
// All additional attrs passed are included in the recorded value. |
| 882 |
func (m NetIO) Record( |
| 883 |
ctx context.Context, |
| 884 |
val int64, |
| 885 |
attrs ...attribute.KeyValue, |
| 886 |
) { |
| 887 |
if len(attrs) == 0 { |
| 888 |
m.Int64Histogram.Record(ctx, val) |
| 889 |
return |
| 890 |
} |
| 891 |
|
| 892 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 893 |
defer func() { |
| 894 |
*o = (*o)[:0] |
| 895 |
recOptPool.Put(o) |
| 896 |
}() |
| 897 |
|
| 898 |
*o = append( |
| 899 |
*o, |
| 900 |
metric.WithAttributes( |
| 901 |
attrs..., |
| 902 |
), |
| 903 |
) |
| 904 |
|
| 905 |
m.Int64Histogram.Record(ctx, val, *o...) |
| 906 |
} |
| 907 |
|
| 908 |
// RecordSet records val to the current distribution for set. |
| 909 |
func (m NetIO) RecordSet(ctx context.Context, val int64, set attribute.Set) { |
| 910 |
if set.Len() == 0 { |
| 911 |
m.Int64Histogram.Record(ctx, val) |
| 912 |
return |
| 913 |
} |
| 914 |
|
| 915 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 916 |
defer func() { |
| 917 |
*o = (*o)[:0] |
| 918 |
recOptPool.Put(o) |
| 919 |
}() |
| 920 |
|
| 921 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 922 |
m.Int64Histogram.Record(ctx, val, *o...) |
| 923 |
} |
| 924 |
|
| 925 |
// AttrTrigger returns an optional attribute for the "faas.trigger" semantic |
| 926 |
// convention. It represents the type of the trigger which caused this function |
| 927 |
// invocation. |
| 928 |
func (NetIO) AttrTrigger(val TriggerAttr) attribute.KeyValue { |
| 929 |
return attribute.String("faas.trigger", string(val)) |
| 930 |
} |
| 931 |
|
| 932 |
// Timeouts is an instrument used to record metric values conforming to the |
| 933 |
// "faas.timeouts" semantic conventions. It represents the number of invocation |
| 934 |
// timeouts. |
| 935 |
type Timeouts struct { |
| 936 |
metric.Int64Counter |
| 937 |
} |
| 938 |
|
| 939 |
var newTimeoutsOpts = []metric.Int64CounterOption{ |
| 940 |
metric.WithDescription("Number of invocation timeouts."), |
| 941 |
metric.WithUnit("{timeout}"), |
| 942 |
} |
| 943 |
|
| 944 |
// NewTimeouts returns a new Timeouts instrument. |
| 945 |
func NewTimeouts( |
| 946 |
m metric.Meter, |
| 947 |
opt ...metric.Int64CounterOption, |
| 948 |
) (Timeouts, error) { |
| 949 |
// Check if the meter is nil. |
| 950 |
if m == nil { |
| 951 |
return Timeouts{noop.Int64Counter{}}, nil |
| 952 |
} |
| 953 |
|
| 954 |
if len(opt) == 0 { |
| 955 |
opt = newTimeoutsOpts |
| 956 |
} else { |
| 957 |
opt = append(opt, newTimeoutsOpts...) |
| 958 |
} |
| 959 |
|
| 960 |
i, err := m.Int64Counter( |
| 961 |
"faas.timeouts", |
| 962 |
opt..., |
| 963 |
) |
| 964 |
if err != nil { |
| 965 |
return Timeouts{noop.Int64Counter{}}, err |
| 966 |
} |
| 967 |
return Timeouts{i}, nil |
| 968 |
} |
| 969 |
|
| 970 |
// Inst returns the underlying metric instrument. |
| 971 |
func (m Timeouts) Inst() metric.Int64Counter { |
| 972 |
return m.Int64Counter |
| 973 |
} |
| 974 |
|
| 975 |
// Name returns the semantic convention name of the instrument. |
| 976 |
func (Timeouts) Name() string { |
| 977 |
return "faas.timeouts" |
| 978 |
} |
| 979 |
|
| 980 |
// Unit returns the semantic convention unit of the instrument |
| 981 |
func (Timeouts) Unit() string { |
| 982 |
return "{timeout}" |
| 983 |
} |
| 984 |
|
| 985 |
// Description returns the semantic convention description of the instrument |
| 986 |
func (Timeouts) Description() string { |
| 987 |
return "Number of invocation timeouts." |
| 988 |
} |
| 989 |
|
| 990 |
// Add adds incr to the existing count for attrs. |
| 991 |
// |
| 992 |
// All additional attrs passed are included in the recorded value. |
| 993 |
func (m Timeouts) Add( |
| 994 |
ctx context.Context, |
| 995 |
incr int64, |
| 996 |
attrs ...attribute.KeyValue, |
| 997 |
) { |
| 998 |
if len(attrs) == 0 { |
| 999 |
m.Int64Counter.Add(ctx, incr) |
| 1000 |
return |
| 1001 |
} |
| 1002 |
|
| 1003 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 1004 |
defer func() { |
| 1005 |
*o = (*o)[:0] |
| 1006 |
addOptPool.Put(o) |
| 1007 |
}() |
| 1008 |
|
| 1009 |
*o = append( |
| 1010 |
*o, |
| 1011 |
metric.WithAttributes( |
| 1012 |
attrs..., |
| 1013 |
), |
| 1014 |
) |
| 1015 |
|
| 1016 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 1017 |
} |
| 1018 |
|
| 1019 |
// AddSet adds incr to the existing count for set. |
| 1020 |
func (m Timeouts) AddSet(ctx context.Context, incr int64, set attribute.Set) { |
| 1021 |
if set.Len() == 0 { |
| 1022 |
m.Int64Counter.Add(ctx, incr) |
| 1023 |
return |
| 1024 |
} |
| 1025 |
|
| 1026 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 1027 |
defer func() { |
| 1028 |
*o = (*o)[:0] |
| 1029 |
addOptPool.Put(o) |
| 1030 |
}() |
| 1031 |
|
| 1032 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 1033 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 1034 |
} |
| 1035 |
|
| 1036 |
// AttrTrigger returns an optional attribute for the "faas.trigger" semantic |
| 1037 |
// convention. It represents the type of the trigger which caused this function |
| 1038 |
// invocation. |
| 1039 |
func (Timeouts) AttrTrigger(val TriggerAttr) attribute.KeyValue { |
| 1040 |
return attribute.String("faas.trigger", string(val)) |
| 1041 |
} |