| 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 messagingconv provides types and functionality for OpenTelemetry semantic |
| 7 |
// conventions in the "messaging" namespace. |
| 8 |
package messagingconv |
| 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 |
// ErrorTypeAttr is an attribute conforming to the error.type semantic |
| 25 |
// conventions. It represents the describes a class of error the operation ended |
| 26 |
// with. |
| 27 |
type ErrorTypeAttr string |
| 28 |
|
| 29 |
var ( |
| 30 |
// ErrorTypeOther is a fallback error value to be used when the instrumentation |
| 31 |
// doesn't define a custom value. |
| 32 |
ErrorTypeOther ErrorTypeAttr = "_OTHER" |
| 33 |
) |
| 34 |
|
| 35 |
// OperationTypeAttr is an attribute conforming to the messaging.operation.type |
| 36 |
// semantic conventions. It represents a string identifying the type of the |
| 37 |
// messaging operation. |
| 38 |
type OperationTypeAttr string |
| 39 |
|
| 40 |
var ( |
| 41 |
// OperationTypeCreate is a message is created. "Create" spans always refer to a |
| 42 |
// single message and are used to provide a unique creation context for messages |
| 43 |
// in batch sending scenarios. |
| 44 |
OperationTypeCreate OperationTypeAttr = "create" |
| 45 |
// OperationTypeSend is the one or more messages are provided for sending to an |
| 46 |
// intermediary. If a single message is sent, the context of the "Send" span can |
| 47 |
// be used as the creation context and no "Create" span needs to be created. |
| 48 |
OperationTypeSend OperationTypeAttr = "send" |
| 49 |
// OperationTypeReceive is the one or more messages are requested by a consumer. |
| 50 |
// This operation refers to pull-based scenarios, where consumers explicitly |
| 51 |
// call methods of messaging SDKs to receive messages. |
| 52 |
OperationTypeReceive OperationTypeAttr = "receive" |
| 53 |
// OperationTypeProcess is the one or more messages are processed by a consumer. |
| 54 |
OperationTypeProcess OperationTypeAttr = "process" |
| 55 |
// OperationTypeSettle is the one or more messages are settled. |
| 56 |
OperationTypeSettle OperationTypeAttr = "settle" |
| 57 |
) |
| 58 |
|
| 59 |
// SystemAttr is an attribute conforming to the messaging.system semantic |
| 60 |
// conventions. It represents the messaging system as identified by the client |
| 61 |
// instrumentation. |
| 62 |
type SystemAttr string |
| 63 |
|
| 64 |
var ( |
| 65 |
// SystemActiveMQ is the apache ActiveMQ. |
| 66 |
SystemActiveMQ SystemAttr = "activemq" |
| 67 |
// SystemAWSSQS is the amazon Simple Queue Service (SQS). |
| 68 |
SystemAWSSQS SystemAttr = "aws_sqs" |
| 69 |
// SystemEventGrid is the azure Event Grid. |
| 70 |
SystemEventGrid SystemAttr = "eventgrid" |
| 71 |
// SystemEventHubs is the azure Event Hubs. |
| 72 |
SystemEventHubs SystemAttr = "eventhubs" |
| 73 |
// SystemServiceBus is the azure Service Bus. |
| 74 |
SystemServiceBus SystemAttr = "servicebus" |
| 75 |
// SystemGCPPubSub is the google Cloud Pub/Sub. |
| 76 |
SystemGCPPubSub SystemAttr = "gcp_pubsub" |
| 77 |
// SystemJMS is the java Message Service. |
| 78 |
SystemJMS SystemAttr = "jms" |
| 79 |
// SystemKafka is the apache Kafka. |
| 80 |
SystemKafka SystemAttr = "kafka" |
| 81 |
// SystemRabbitMQ is the rabbitMQ. |
| 82 |
SystemRabbitMQ SystemAttr = "rabbitmq" |
| 83 |
// SystemRocketMQ is the apache RocketMQ. |
| 84 |
SystemRocketMQ SystemAttr = "rocketmq" |
| 85 |
// SystemPulsar is the apache Pulsar. |
| 86 |
SystemPulsar SystemAttr = "pulsar" |
| 87 |
) |
| 88 |
|
| 89 |
// ClientConsumedMessages is an instrument used to record metric values |
| 90 |
// conforming to the "messaging.client.consumed.messages" semantic conventions. |
| 91 |
// It represents the number of messages that were delivered to the application. |
| 92 |
type ClientConsumedMessages struct { |
| 93 |
metric.Int64Counter |
| 94 |
} |
| 95 |
|
| 96 |
// NewClientConsumedMessages returns a new ClientConsumedMessages instrument. |
| 97 |
func NewClientConsumedMessages( |
| 98 |
m metric.Meter, |
| 99 |
opt ...metric.Int64CounterOption, |
| 100 |
) (ClientConsumedMessages, error) { |
| 101 |
// Check if the meter is nil. |
| 102 |
if m == nil { |
| 103 |
return ClientConsumedMessages{noop.Int64Counter{}}, nil |
| 104 |
} |
| 105 |
|
| 106 |
i, err := m.Int64Counter( |
| 107 |
"messaging.client.consumed.messages", |
| 108 |
append([]metric.Int64CounterOption{ |
| 109 |
metric.WithDescription("Number of messages that were delivered to the application."), |
| 110 |
metric.WithUnit("{message}"), |
| 111 |
}, opt...)..., |
| 112 |
) |
| 113 |
if err != nil { |
| 114 |
return ClientConsumedMessages{noop.Int64Counter{}}, err |
| 115 |
} |
| 116 |
return ClientConsumedMessages{i}, nil |
| 117 |
} |
| 118 |
|
| 119 |
// Inst returns the underlying metric instrument. |
| 120 |
func (m ClientConsumedMessages) Inst() metric.Int64Counter { |
| 121 |
return m.Int64Counter |
| 122 |
} |
| 123 |
|
| 124 |
// Name returns the semantic convention name of the instrument. |
| 125 |
func (ClientConsumedMessages) Name() string { |
| 126 |
return "messaging.client.consumed.messages" |
| 127 |
} |
| 128 |
|
| 129 |
// Unit returns the semantic convention unit of the instrument |
| 130 |
func (ClientConsumedMessages) Unit() string { |
| 131 |
return "{message}" |
| 132 |
} |
| 133 |
|
| 134 |
// Description returns the semantic convention description of the instrument |
| 135 |
func (ClientConsumedMessages) Description() string { |
| 136 |
return "Number of messages that were delivered to the application." |
| 137 |
} |
| 138 |
|
| 139 |
// Add adds incr to the existing count for attrs. |
| 140 |
// |
| 141 |
// The operationName is the the system-specific name of the messaging operation. |
| 142 |
// |
| 143 |
// The system is the the messaging system as identified by the client |
| 144 |
// instrumentation. |
| 145 |
// |
| 146 |
// All additional attrs passed are included in the recorded value. |
| 147 |
// |
| 148 |
// Records the number of messages pulled from the broker or number of messages |
| 149 |
// dispatched to the application in push-based scenarios. |
| 150 |
// The metric SHOULD be reported once per message delivery. For example, if |
| 151 |
// receiving and processing operations are both instrumented for a single message |
| 152 |
// delivery, this counter is incremented when the message is received and not |
| 153 |
// reported when it is processed. |
| 154 |
func (m ClientConsumedMessages) Add( |
| 155 |
ctx context.Context, |
| 156 |
incr int64, |
| 157 |
operationName string, |
| 158 |
system SystemAttr, |
| 159 |
attrs ...attribute.KeyValue, |
| 160 |
) { |
| 161 |
if len(attrs) == 0 { |
| 162 |
m.Int64Counter.Add(ctx, incr) |
| 163 |
return |
| 164 |
} |
| 165 |
|
| 166 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 167 |
defer func() { |
| 168 |
*o = (*o)[:0] |
| 169 |
addOptPool.Put(o) |
| 170 |
}() |
| 171 |
|
| 172 |
*o = append( |
| 173 |
*o, |
| 174 |
metric.WithAttributes( |
| 175 |
append( |
| 176 |
attrs, |
| 177 |
attribute.String("messaging.operation.name", operationName), |
| 178 |
attribute.String("messaging.system", string(system)), |
| 179 |
)..., |
| 180 |
), |
| 181 |
) |
| 182 |
|
| 183 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 184 |
} |
| 185 |
|
| 186 |
// AddSet adds incr to the existing count for set. |
| 187 |
// |
| 188 |
// Records the number of messages pulled from the broker or number of messages |
| 189 |
// dispatched to the application in push-based scenarios. |
| 190 |
// The metric SHOULD be reported once per message delivery. For example, if |
| 191 |
// receiving and processing operations are both instrumented for a single message |
| 192 |
// delivery, this counter is incremented when the message is received and not |
| 193 |
// reported when it is processed. |
| 194 |
func (m ClientConsumedMessages) AddSet(ctx context.Context, incr int64, set attribute.Set) { |
| 195 |
if set.Len() == 0 { |
| 196 |
m.Int64Counter.Add(ctx, incr) |
| 197 |
return |
| 198 |
} |
| 199 |
|
| 200 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 201 |
defer func() { |
| 202 |
*o = (*o)[:0] |
| 203 |
addOptPool.Put(o) |
| 204 |
}() |
| 205 |
|
| 206 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 207 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 208 |
} |
| 209 |
|
| 210 |
// AttrErrorType returns an optional attribute for the "error.type" semantic |
| 211 |
// convention. It represents the describes a class of error the operation ended |
| 212 |
// with. |
| 213 |
func (ClientConsumedMessages) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue { |
| 214 |
return attribute.String("error.type", string(val)) |
| 215 |
} |
| 216 |
|
| 217 |
// AttrConsumerGroupName returns an optional attribute for the |
| 218 |
// "messaging.consumer.group.name" semantic convention. It represents the name of |
| 219 |
// the consumer group with which a consumer is associated. |
| 220 |
func (ClientConsumedMessages) AttrConsumerGroupName(val string) attribute.KeyValue { |
| 221 |
return attribute.String("messaging.consumer.group.name", val) |
| 222 |
} |
| 223 |
|
| 224 |
// AttrDestinationName returns an optional attribute for the |
| 225 |
// "messaging.destination.name" semantic convention. It represents the message |
| 226 |
// destination name. |
| 227 |
func (ClientConsumedMessages) AttrDestinationName(val string) attribute.KeyValue { |
| 228 |
return attribute.String("messaging.destination.name", val) |
| 229 |
} |
| 230 |
|
| 231 |
// AttrDestinationSubscriptionName returns an optional attribute for the |
| 232 |
// "messaging.destination.subscription.name" semantic convention. It represents |
| 233 |
// the name of the destination subscription from which a message is consumed. |
| 234 |
func (ClientConsumedMessages) AttrDestinationSubscriptionName(val string) attribute.KeyValue { |
| 235 |
return attribute.String("messaging.destination.subscription.name", val) |
| 236 |
} |
| 237 |
|
| 238 |
// AttrDestinationTemplate returns an optional attribute for the |
| 239 |
// "messaging.destination.template" semantic convention. It represents the low |
| 240 |
// cardinality representation of the messaging destination name. |
| 241 |
func (ClientConsumedMessages) AttrDestinationTemplate(val string) attribute.KeyValue { |
| 242 |
return attribute.String("messaging.destination.template", val) |
| 243 |
} |
| 244 |
|
| 245 |
// AttrServerAddress returns an optional attribute for the "server.address" |
| 246 |
// semantic convention. It represents the server domain name if available without |
| 247 |
// reverse DNS lookup; otherwise, IP address or Unix domain socket name. |
| 248 |
func (ClientConsumedMessages) AttrServerAddress(val string) attribute.KeyValue { |
| 249 |
return attribute.String("server.address", val) |
| 250 |
} |
| 251 |
|
| 252 |
// AttrDestinationPartitionID returns an optional attribute for the |
| 253 |
// "messaging.destination.partition.id" semantic convention. It represents the |
| 254 |
// identifier of the partition messages are sent to or received from, unique |
| 255 |
// within the `messaging.destination.name`. |
| 256 |
func (ClientConsumedMessages) AttrDestinationPartitionID(val string) attribute.KeyValue { |
| 257 |
return attribute.String("messaging.destination.partition.id", val) |
| 258 |
} |
| 259 |
|
| 260 |
// AttrServerPort returns an optional attribute for the "server.port" semantic |
| 261 |
// convention. It represents the server port number. |
| 262 |
func (ClientConsumedMessages) AttrServerPort(val int) attribute.KeyValue { |
| 263 |
return attribute.Int("server.port", val) |
| 264 |
} |
| 265 |
|
| 266 |
// ClientOperationDuration is an instrument used to record metric values |
| 267 |
// conforming to the "messaging.client.operation.duration" semantic conventions. |
| 268 |
// It represents the duration of messaging operation initiated by a producer or |
| 269 |
// consumer client. |
| 270 |
type ClientOperationDuration struct { |
| 271 |
metric.Float64Histogram |
| 272 |
} |
| 273 |
|
| 274 |
// NewClientOperationDuration returns a new ClientOperationDuration instrument. |
| 275 |
func NewClientOperationDuration( |
| 276 |
m metric.Meter, |
| 277 |
opt ...metric.Float64HistogramOption, |
| 278 |
) (ClientOperationDuration, error) { |
| 279 |
// Check if the meter is nil. |
| 280 |
if m == nil { |
| 281 |
return ClientOperationDuration{noop.Float64Histogram{}}, nil |
| 282 |
} |
| 283 |
|
| 284 |
i, err := m.Float64Histogram( |
| 285 |
"messaging.client.operation.duration", |
| 286 |
append([]metric.Float64HistogramOption{ |
| 287 |
metric.WithDescription("Duration of messaging operation initiated by a producer or consumer client."), |
| 288 |
metric.WithUnit("s"), |
| 289 |
}, opt...)..., |
| 290 |
) |
| 291 |
if err != nil { |
| 292 |
return ClientOperationDuration{noop.Float64Histogram{}}, err |
| 293 |
} |
| 294 |
return ClientOperationDuration{i}, nil |
| 295 |
} |
| 296 |
|
| 297 |
// Inst returns the underlying metric instrument. |
| 298 |
func (m ClientOperationDuration) Inst() metric.Float64Histogram { |
| 299 |
return m.Float64Histogram |
| 300 |
} |
| 301 |
|
| 302 |
// Name returns the semantic convention name of the instrument. |
| 303 |
func (ClientOperationDuration) Name() string { |
| 304 |
return "messaging.client.operation.duration" |
| 305 |
} |
| 306 |
|
| 307 |
// Unit returns the semantic convention unit of the instrument |
| 308 |
func (ClientOperationDuration) Unit() string { |
| 309 |
return "s" |
| 310 |
} |
| 311 |
|
| 312 |
// Description returns the semantic convention description of the instrument |
| 313 |
func (ClientOperationDuration) Description() string { |
| 314 |
return "Duration of messaging operation initiated by a producer or consumer client." |
| 315 |
} |
| 316 |
|
| 317 |
// Record records val to the current distribution for attrs. |
| 318 |
// |
| 319 |
// The operationName is the the system-specific name of the messaging operation. |
| 320 |
// |
| 321 |
// The system is the the messaging system as identified by the client |
| 322 |
// instrumentation. |
| 323 |
// |
| 324 |
// All additional attrs passed are included in the recorded value. |
| 325 |
// |
| 326 |
// This metric SHOULD NOT be used to report processing duration - processing |
| 327 |
// duration is reported in `messaging.process.duration` metric. |
| 328 |
func (m ClientOperationDuration) Record( |
| 329 |
ctx context.Context, |
| 330 |
val float64, |
| 331 |
operationName string, |
| 332 |
system SystemAttr, |
| 333 |
attrs ...attribute.KeyValue, |
| 334 |
) { |
| 335 |
if len(attrs) == 0 { |
| 336 |
m.Float64Histogram.Record(ctx, val) |
| 337 |
return |
| 338 |
} |
| 339 |
|
| 340 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 341 |
defer func() { |
| 342 |
*o = (*o)[:0] |
| 343 |
recOptPool.Put(o) |
| 344 |
}() |
| 345 |
|
| 346 |
*o = append( |
| 347 |
*o, |
| 348 |
metric.WithAttributes( |
| 349 |
append( |
| 350 |
attrs, |
| 351 |
attribute.String("messaging.operation.name", operationName), |
| 352 |
attribute.String("messaging.system", string(system)), |
| 353 |
)..., |
| 354 |
), |
| 355 |
) |
| 356 |
|
| 357 |
m.Float64Histogram.Record(ctx, val, *o...) |
| 358 |
} |
| 359 |
|
| 360 |
// RecordSet records val to the current distribution for set. |
| 361 |
// |
| 362 |
// This metric SHOULD NOT be used to report processing duration - processing |
| 363 |
// duration is reported in `messaging.process.duration` metric. |
| 364 |
func (m ClientOperationDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) { |
| 365 |
if set.Len() == 0 { |
| 366 |
m.Float64Histogram.Record(ctx, val) |
| 367 |
return |
| 368 |
} |
| 369 |
|
| 370 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 371 |
defer func() { |
| 372 |
*o = (*o)[:0] |
| 373 |
recOptPool.Put(o) |
| 374 |
}() |
| 375 |
|
| 376 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 377 |
m.Float64Histogram.Record(ctx, val, *o...) |
| 378 |
} |
| 379 |
|
| 380 |
// AttrErrorType returns an optional attribute for the "error.type" semantic |
| 381 |
// convention. It represents the describes a class of error the operation ended |
| 382 |
// with. |
| 383 |
func (ClientOperationDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue { |
| 384 |
return attribute.String("error.type", string(val)) |
| 385 |
} |
| 386 |
|
| 387 |
// AttrConsumerGroupName returns an optional attribute for the |
| 388 |
// "messaging.consumer.group.name" semantic convention. It represents the name of |
| 389 |
// the consumer group with which a consumer is associated. |
| 390 |
func (ClientOperationDuration) AttrConsumerGroupName(val string) attribute.KeyValue { |
| 391 |
return attribute.String("messaging.consumer.group.name", val) |
| 392 |
} |
| 393 |
|
| 394 |
// AttrDestinationName returns an optional attribute for the |
| 395 |
// "messaging.destination.name" semantic convention. It represents the message |
| 396 |
// destination name. |
| 397 |
func (ClientOperationDuration) AttrDestinationName(val string) attribute.KeyValue { |
| 398 |
return attribute.String("messaging.destination.name", val) |
| 399 |
} |
| 400 |
|
| 401 |
// AttrDestinationSubscriptionName returns an optional attribute for the |
| 402 |
// "messaging.destination.subscription.name" semantic convention. It represents |
| 403 |
// the name of the destination subscription from which a message is consumed. |
| 404 |
func (ClientOperationDuration) AttrDestinationSubscriptionName(val string) attribute.KeyValue { |
| 405 |
return attribute.String("messaging.destination.subscription.name", val) |
| 406 |
} |
| 407 |
|
| 408 |
// AttrDestinationTemplate returns an optional attribute for the |
| 409 |
// "messaging.destination.template" semantic convention. It represents the low |
| 410 |
// cardinality representation of the messaging destination name. |
| 411 |
func (ClientOperationDuration) AttrDestinationTemplate(val string) attribute.KeyValue { |
| 412 |
return attribute.String("messaging.destination.template", val) |
| 413 |
} |
| 414 |
|
| 415 |
// AttrOperationType returns an optional attribute for the |
| 416 |
// "messaging.operation.type" semantic convention. It represents a string |
| 417 |
// identifying the type of the messaging operation. |
| 418 |
func (ClientOperationDuration) AttrOperationType(val OperationTypeAttr) attribute.KeyValue { |
| 419 |
return attribute.String("messaging.operation.type", string(val)) |
| 420 |
} |
| 421 |
|
| 422 |
// AttrServerAddress returns an optional attribute for the "server.address" |
| 423 |
// semantic convention. It represents the server domain name if available without |
| 424 |
// reverse DNS lookup; otherwise, IP address or Unix domain socket name. |
| 425 |
func (ClientOperationDuration) AttrServerAddress(val string) attribute.KeyValue { |
| 426 |
return attribute.String("server.address", val) |
| 427 |
} |
| 428 |
|
| 429 |
// AttrDestinationPartitionID returns an optional attribute for the |
| 430 |
// "messaging.destination.partition.id" semantic convention. It represents the |
| 431 |
// identifier of the partition messages are sent to or received from, unique |
| 432 |
// within the `messaging.destination.name`. |
| 433 |
func (ClientOperationDuration) AttrDestinationPartitionID(val string) attribute.KeyValue { |
| 434 |
return attribute.String("messaging.destination.partition.id", val) |
| 435 |
} |
| 436 |
|
| 437 |
// AttrServerPort returns an optional attribute for the "server.port" semantic |
| 438 |
// convention. It represents the server port number. |
| 439 |
func (ClientOperationDuration) AttrServerPort(val int) attribute.KeyValue { |
| 440 |
return attribute.Int("server.port", val) |
| 441 |
} |
| 442 |
|
| 443 |
// ClientSentMessages is an instrument used to record metric values conforming to |
| 444 |
// the "messaging.client.sent.messages" semantic conventions. It represents the |
| 445 |
// number of messages producer attempted to send to the broker. |
| 446 |
type ClientSentMessages struct { |
| 447 |
metric.Int64Counter |
| 448 |
} |
| 449 |
|
| 450 |
// NewClientSentMessages returns a new ClientSentMessages instrument. |
| 451 |
func NewClientSentMessages( |
| 452 |
m metric.Meter, |
| 453 |
opt ...metric.Int64CounterOption, |
| 454 |
) (ClientSentMessages, error) { |
| 455 |
// Check if the meter is nil. |
| 456 |
if m == nil { |
| 457 |
return ClientSentMessages{noop.Int64Counter{}}, nil |
| 458 |
} |
| 459 |
|
| 460 |
i, err := m.Int64Counter( |
| 461 |
"messaging.client.sent.messages", |
| 462 |
append([]metric.Int64CounterOption{ |
| 463 |
metric.WithDescription("Number of messages producer attempted to send to the broker."), |
| 464 |
metric.WithUnit("{message}"), |
| 465 |
}, opt...)..., |
| 466 |
) |
| 467 |
if err != nil { |
| 468 |
return ClientSentMessages{noop.Int64Counter{}}, err |
| 469 |
} |
| 470 |
return ClientSentMessages{i}, nil |
| 471 |
} |
| 472 |
|
| 473 |
// Inst returns the underlying metric instrument. |
| 474 |
func (m ClientSentMessages) Inst() metric.Int64Counter { |
| 475 |
return m.Int64Counter |
| 476 |
} |
| 477 |
|
| 478 |
// Name returns the semantic convention name of the instrument. |
| 479 |
func (ClientSentMessages) Name() string { |
| 480 |
return "messaging.client.sent.messages" |
| 481 |
} |
| 482 |
|
| 483 |
// Unit returns the semantic convention unit of the instrument |
| 484 |
func (ClientSentMessages) Unit() string { |
| 485 |
return "{message}" |
| 486 |
} |
| 487 |
|
| 488 |
// Description returns the semantic convention description of the instrument |
| 489 |
func (ClientSentMessages) Description() string { |
| 490 |
return "Number of messages producer attempted to send to the broker." |
| 491 |
} |
| 492 |
|
| 493 |
// Add adds incr to the existing count for attrs. |
| 494 |
// |
| 495 |
// The operationName is the the system-specific name of the messaging operation. |
| 496 |
// |
| 497 |
// The system is the the messaging system as identified by the client |
| 498 |
// instrumentation. |
| 499 |
// |
| 500 |
// All additional attrs passed are included in the recorded value. |
| 501 |
// |
| 502 |
// This metric MUST NOT count messages that were created but haven't yet been |
| 503 |
// sent. |
| 504 |
func (m ClientSentMessages) Add( |
| 505 |
ctx context.Context, |
| 506 |
incr int64, |
| 507 |
operationName string, |
| 508 |
system SystemAttr, |
| 509 |
attrs ...attribute.KeyValue, |
| 510 |
) { |
| 511 |
if len(attrs) == 0 { |
| 512 |
m.Int64Counter.Add(ctx, incr) |
| 513 |
return |
| 514 |
} |
| 515 |
|
| 516 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 517 |
defer func() { |
| 518 |
*o = (*o)[:0] |
| 519 |
addOptPool.Put(o) |
| 520 |
}() |
| 521 |
|
| 522 |
*o = append( |
| 523 |
*o, |
| 524 |
metric.WithAttributes( |
| 525 |
append( |
| 526 |
attrs, |
| 527 |
attribute.String("messaging.operation.name", operationName), |
| 528 |
attribute.String("messaging.system", string(system)), |
| 529 |
)..., |
| 530 |
), |
| 531 |
) |
| 532 |
|
| 533 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 534 |
} |
| 535 |
|
| 536 |
// AddSet adds incr to the existing count for set. |
| 537 |
// |
| 538 |
// This metric MUST NOT count messages that were created but haven't yet been |
| 539 |
// sent. |
| 540 |
func (m ClientSentMessages) AddSet(ctx context.Context, incr int64, set attribute.Set) { |
| 541 |
if set.Len() == 0 { |
| 542 |
m.Int64Counter.Add(ctx, incr) |
| 543 |
return |
| 544 |
} |
| 545 |
|
| 546 |
o := addOptPool.Get().(*[]metric.AddOption) |
| 547 |
defer func() { |
| 548 |
*o = (*o)[:0] |
| 549 |
addOptPool.Put(o) |
| 550 |
}() |
| 551 |
|
| 552 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 553 |
m.Int64Counter.Add(ctx, incr, *o...) |
| 554 |
} |
| 555 |
|
| 556 |
// AttrErrorType returns an optional attribute for the "error.type" semantic |
| 557 |
// convention. It represents the describes a class of error the operation ended |
| 558 |
// with. |
| 559 |
func (ClientSentMessages) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue { |
| 560 |
return attribute.String("error.type", string(val)) |
| 561 |
} |
| 562 |
|
| 563 |
// AttrDestinationName returns an optional attribute for the |
| 564 |
// "messaging.destination.name" semantic convention. It represents the message |
| 565 |
// destination name. |
| 566 |
func (ClientSentMessages) AttrDestinationName(val string) attribute.KeyValue { |
| 567 |
return attribute.String("messaging.destination.name", val) |
| 568 |
} |
| 569 |
|
| 570 |
// AttrDestinationTemplate returns an optional attribute for the |
| 571 |
// "messaging.destination.template" semantic convention. It represents the low |
| 572 |
// cardinality representation of the messaging destination name. |
| 573 |
func (ClientSentMessages) AttrDestinationTemplate(val string) attribute.KeyValue { |
| 574 |
return attribute.String("messaging.destination.template", val) |
| 575 |
} |
| 576 |
|
| 577 |
// AttrServerAddress returns an optional attribute for the "server.address" |
| 578 |
// semantic convention. It represents the server domain name if available without |
| 579 |
// reverse DNS lookup; otherwise, IP address or Unix domain socket name. |
| 580 |
func (ClientSentMessages) AttrServerAddress(val string) attribute.KeyValue { |
| 581 |
return attribute.String("server.address", val) |
| 582 |
} |
| 583 |
|
| 584 |
// AttrDestinationPartitionID returns an optional attribute for the |
| 585 |
// "messaging.destination.partition.id" semantic convention. It represents the |
| 586 |
// identifier of the partition messages are sent to or received from, unique |
| 587 |
// within the `messaging.destination.name`. |
| 588 |
func (ClientSentMessages) AttrDestinationPartitionID(val string) attribute.KeyValue { |
| 589 |
return attribute.String("messaging.destination.partition.id", val) |
| 590 |
} |
| 591 |
|
| 592 |
// AttrServerPort returns an optional attribute for the "server.port" semantic |
| 593 |
// convention. It represents the server port number. |
| 594 |
func (ClientSentMessages) AttrServerPort(val int) attribute.KeyValue { |
| 595 |
return attribute.Int("server.port", val) |
| 596 |
} |
| 597 |
|
| 598 |
// ProcessDuration is an instrument used to record metric values conforming to |
| 599 |
// the "messaging.process.duration" semantic conventions. It represents the |
| 600 |
// duration of processing operation. |
| 601 |
type ProcessDuration struct { |
| 602 |
metric.Float64Histogram |
| 603 |
} |
| 604 |
|
| 605 |
// NewProcessDuration returns a new ProcessDuration instrument. |
| 606 |
func NewProcessDuration( |
| 607 |
m metric.Meter, |
| 608 |
opt ...metric.Float64HistogramOption, |
| 609 |
) (ProcessDuration, error) { |
| 610 |
// Check if the meter is nil. |
| 611 |
if m == nil { |
| 612 |
return ProcessDuration{noop.Float64Histogram{}}, nil |
| 613 |
} |
| 614 |
|
| 615 |
i, err := m.Float64Histogram( |
| 616 |
"messaging.process.duration", |
| 617 |
append([]metric.Float64HistogramOption{ |
| 618 |
metric.WithDescription("Duration of processing operation."), |
| 619 |
metric.WithUnit("s"), |
| 620 |
}, opt...)..., |
| 621 |
) |
| 622 |
if err != nil { |
| 623 |
return ProcessDuration{noop.Float64Histogram{}}, err |
| 624 |
} |
| 625 |
return ProcessDuration{i}, nil |
| 626 |
} |
| 627 |
|
| 628 |
// Inst returns the underlying metric instrument. |
| 629 |
func (m ProcessDuration) Inst() metric.Float64Histogram { |
| 630 |
return m.Float64Histogram |
| 631 |
} |
| 632 |
|
| 633 |
// Name returns the semantic convention name of the instrument. |
| 634 |
func (ProcessDuration) Name() string { |
| 635 |
return "messaging.process.duration" |
| 636 |
} |
| 637 |
|
| 638 |
// Unit returns the semantic convention unit of the instrument |
| 639 |
func (ProcessDuration) Unit() string { |
| 640 |
return "s" |
| 641 |
} |
| 642 |
|
| 643 |
// Description returns the semantic convention description of the instrument |
| 644 |
func (ProcessDuration) Description() string { |
| 645 |
return "Duration of processing operation." |
| 646 |
} |
| 647 |
|
| 648 |
// Record records val to the current distribution for attrs. |
| 649 |
// |
| 650 |
// The operationName is the the system-specific name of the messaging operation. |
| 651 |
// |
| 652 |
// The system is the the messaging system as identified by the client |
| 653 |
// instrumentation. |
| 654 |
// |
| 655 |
// All additional attrs passed are included in the recorded value. |
| 656 |
// |
| 657 |
// This metric MUST be reported for operations with `messaging.operation.type` |
| 658 |
// that matches `process`. |
| 659 |
func (m ProcessDuration) Record( |
| 660 |
ctx context.Context, |
| 661 |
val float64, |
| 662 |
operationName string, |
| 663 |
system SystemAttr, |
| 664 |
attrs ...attribute.KeyValue, |
| 665 |
) { |
| 666 |
if len(attrs) == 0 { |
| 667 |
m.Float64Histogram.Record(ctx, val) |
| 668 |
return |
| 669 |
} |
| 670 |
|
| 671 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 672 |
defer func() { |
| 673 |
*o = (*o)[:0] |
| 674 |
recOptPool.Put(o) |
| 675 |
}() |
| 676 |
|
| 677 |
*o = append( |
| 678 |
*o, |
| 679 |
metric.WithAttributes( |
| 680 |
append( |
| 681 |
attrs, |
| 682 |
attribute.String("messaging.operation.name", operationName), |
| 683 |
attribute.String("messaging.system", string(system)), |
| 684 |
)..., |
| 685 |
), |
| 686 |
) |
| 687 |
|
| 688 |
m.Float64Histogram.Record(ctx, val, *o...) |
| 689 |
} |
| 690 |
|
| 691 |
// RecordSet records val to the current distribution for set. |
| 692 |
// |
| 693 |
// This metric MUST be reported for operations with `messaging.operation.type` |
| 694 |
// that matches `process`. |
| 695 |
func (m ProcessDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) { |
| 696 |
if set.Len() == 0 { |
| 697 |
m.Float64Histogram.Record(ctx, val) |
| 698 |
return |
| 699 |
} |
| 700 |
|
| 701 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 702 |
defer func() { |
| 703 |
*o = (*o)[:0] |
| 704 |
recOptPool.Put(o) |
| 705 |
}() |
| 706 |
|
| 707 |
*o = append(*o, metric.WithAttributeSet(set)) |
| 708 |
m.Float64Histogram.Record(ctx, val, *o...) |
| 709 |
} |
| 710 |
|
| 711 |
// AttrErrorType returns an optional attribute for the "error.type" semantic |
| 712 |
// convention. It represents the describes a class of error the operation ended |
| 713 |
// with. |
| 714 |
func (ProcessDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue { |
| 715 |
return attribute.String("error.type", string(val)) |
| 716 |
} |
| 717 |
|
| 718 |
// AttrConsumerGroupName returns an optional attribute for the |
| 719 |
// "messaging.consumer.group.name" semantic convention. It represents the name of |
| 720 |
// the consumer group with which a consumer is associated. |
| 721 |
func (ProcessDuration) AttrConsumerGroupName(val string) attribute.KeyValue { |
| 722 |
return attribute.String("messaging.consumer.group.name", val) |
| 723 |
} |
| 724 |
|
| 725 |
// AttrDestinationName returns an optional attribute for the |
| 726 |
// "messaging.destination.name" semantic convention. It represents the message |
| 727 |
// destination name. |
| 728 |
func (ProcessDuration) AttrDestinationName(val string) attribute.KeyValue { |
| 729 |
return attribute.String("messaging.destination.name", val) |
| 730 |
} |
| 731 |
|
| 732 |
// AttrDestinationSubscriptionName returns an optional attribute for the |
| 733 |
// "messaging.destination.subscription.name" semantic convention. It represents |
| 734 |
// the name of the destination subscription from which a message is consumed. |
| 735 |
func (ProcessDuration) AttrDestinationSubscriptionName(val string) attribute.KeyValue { |
| 736 |
return attribute.String("messaging.destination.subscription.name", val) |
| 737 |
} |
| 738 |
|
| 739 |
// AttrDestinationTemplate returns an optional attribute for the |
| 740 |
// "messaging.destination.template" semantic convention. It represents the low |
| 741 |
// cardinality representation of the messaging destination name. |
| 742 |
func (ProcessDuration) AttrDestinationTemplate(val string) attribute.KeyValue { |
| 743 |
return attribute.String("messaging.destination.template", val) |
| 744 |
} |
| 745 |
|
| 746 |
// AttrServerAddress returns an optional attribute for the "server.address" |
| 747 |
// semantic convention. It represents the server domain name if available without |
| 748 |
// reverse DNS lookup; otherwise, IP address or Unix domain socket name. |
| 749 |
func (ProcessDuration) AttrServerAddress(val string) attribute.KeyValue { |
| 750 |
return attribute.String("server.address", val) |
| 751 |
} |
| 752 |
|
| 753 |
// AttrDestinationPartitionID returns an optional attribute for the |
| 754 |
// "messaging.destination.partition.id" semantic convention. It represents the |
| 755 |
// identifier of the partition messages are sent to or received from, unique |
| 756 |
// within the `messaging.destination.name`. |
| 757 |
func (ProcessDuration) AttrDestinationPartitionID(val string) attribute.KeyValue { |
| 758 |
return attribute.String("messaging.destination.partition.id", val) |
| 759 |
} |
| 760 |
|
| 761 |
// AttrServerPort returns an optional attribute for the "server.port" semantic |
| 762 |
// convention. It represents the server port number. |
| 763 |
func (ProcessDuration) AttrServerPort(val int) attribute.KeyValue { |
| 764 |
return attribute.Int("server.port", val) |
| 765 |
} |