Debian Codegraph @

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