Debian Codegraph @

semconv/v1.38.0/messagingconv/metric.go

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