Debian Codegraph @

semconv/v1.37.0/otelconv/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 otelconv provides types and functionality for OpenTelemetry semantic
7 // conventions in the "otel" namespace.
8 package otelconv
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 // ComponentTypeAttr is an attribute conforming to the otel.component.type
36 // semantic conventions. It represents a name identifying the type of the
37 // OpenTelemetry component.
38 type ComponentTypeAttr string
39
40 var (
41 // ComponentTypeBatchingSpanProcessor is the builtin SDK batching span
42 // processor.
43 ComponentTypeBatchingSpanProcessor ComponentTypeAttr = "batching_span_processor"
44 // ComponentTypeSimpleSpanProcessor is the builtin SDK simple span processor.
45 ComponentTypeSimpleSpanProcessor ComponentTypeAttr = "simple_span_processor"
46 // ComponentTypeBatchingLogProcessor is the builtin SDK batching log record
47 // processor.
48 ComponentTypeBatchingLogProcessor ComponentTypeAttr = "batching_log_processor"
49 // ComponentTypeSimpleLogProcessor is the builtin SDK simple log record
50 // processor.
51 ComponentTypeSimpleLogProcessor ComponentTypeAttr = "simple_log_processor"
52 // ComponentTypeOtlpGRPCSpanExporter is the OTLP span exporter over gRPC with
53 // protobuf serialization.
54 ComponentTypeOtlpGRPCSpanExporter ComponentTypeAttr = "otlp_grpc_span_exporter"
55 // ComponentTypeOtlpHTTPSpanExporter is the OTLP span exporter over HTTP with
56 // protobuf serialization.
57 ComponentTypeOtlpHTTPSpanExporter ComponentTypeAttr = "otlp_http_span_exporter"
58 // ComponentTypeOtlpHTTPJSONSpanExporter is the OTLP span exporter over HTTP
59 // with JSON serialization.
60 ComponentTypeOtlpHTTPJSONSpanExporter ComponentTypeAttr = "otlp_http_json_span_exporter"
61 // ComponentTypeZipkinHTTPSpanExporter is the zipkin span exporter over HTTP.
62 ComponentTypeZipkinHTTPSpanExporter ComponentTypeAttr = "zipkin_http_span_exporter"
63 // ComponentTypeOtlpGRPCLogExporter is the OTLP log record exporter over gRPC
64 // with protobuf serialization.
65 ComponentTypeOtlpGRPCLogExporter ComponentTypeAttr = "otlp_grpc_log_exporter"
66 // ComponentTypeOtlpHTTPLogExporter is the OTLP log record exporter over HTTP
67 // with protobuf serialization.
68 ComponentTypeOtlpHTTPLogExporter ComponentTypeAttr = "otlp_http_log_exporter"
69 // ComponentTypeOtlpHTTPJSONLogExporter is the OTLP log record exporter over
70 // HTTP with JSON serialization.
71 ComponentTypeOtlpHTTPJSONLogExporter ComponentTypeAttr = "otlp_http_json_log_exporter"
72 // ComponentTypePeriodicMetricReader is the builtin SDK periodically exporting
73 // metric reader.
74 ComponentTypePeriodicMetricReader ComponentTypeAttr = "periodic_metric_reader"
75 // ComponentTypeOtlpGRPCMetricExporter is the OTLP metric exporter over gRPC
76 // with protobuf serialization.
77 ComponentTypeOtlpGRPCMetricExporter ComponentTypeAttr = "otlp_grpc_metric_exporter"
78 // ComponentTypeOtlpHTTPMetricExporter is the OTLP metric exporter over HTTP
79 // with protobuf serialization.
80 ComponentTypeOtlpHTTPMetricExporter ComponentTypeAttr = "otlp_http_metric_exporter"
81 // ComponentTypeOtlpHTTPJSONMetricExporter is the OTLP metric exporter over HTTP
82 // with JSON serialization.
83 ComponentTypeOtlpHTTPJSONMetricExporter ComponentTypeAttr = "otlp_http_json_metric_exporter"
84 // ComponentTypePrometheusHTTPTextMetricExporter is the prometheus metric
85 // exporter over HTTP with the default text-based format.
86 ComponentTypePrometheusHTTPTextMetricExporter ComponentTypeAttr = "prometheus_http_text_metric_exporter"
87 )
88
89 // SpanParentOriginAttr is an attribute conforming to the otel.span.parent.origin
90 // semantic conventions. It represents the determines whether the span has a
91 // parent span, and if so, [whether it is a remote parent].
92 //
93 // [whether it is a remote parent]: https://opentelemetry.io/docs/specs/otel/trace/api/#isremote
94 type SpanParentOriginAttr string
95
96 var (
97 // SpanParentOriginNone is the span does not have a parent, it is a root span.
98 SpanParentOriginNone SpanParentOriginAttr = "none"
99 // SpanParentOriginLocal is the span has a parent and the parent's span context
100 // [isRemote()] is false.
101 //
102 // [isRemote()]: https://opentelemetry.io/docs/specs/otel/trace/api/#isremote
103 SpanParentOriginLocal SpanParentOriginAttr = "local"
104 // SpanParentOriginRemote is the span has a parent and the parent's span context
105 // [isRemote()] is true.
106 //
107 // [isRemote()]: https://opentelemetry.io/docs/specs/otel/trace/api/#isremote
108 SpanParentOriginRemote SpanParentOriginAttr = "remote"
109 )
110
111 // SpanSamplingResultAttr is an attribute conforming to the
112 // otel.span.sampling_result semantic conventions. It represents the result value
113 // of the sampler for this span.
114 type SpanSamplingResultAttr string
115
116 var (
117 // SpanSamplingResultDrop is the span is not sampled and not recording.
118 SpanSamplingResultDrop SpanSamplingResultAttr = "DROP"
119 // SpanSamplingResultRecordOnly is the span is not sampled, but recording.
120 SpanSamplingResultRecordOnly SpanSamplingResultAttr = "RECORD_ONLY"
121 // SpanSamplingResultRecordAndSample is the span is sampled and recording.
122 SpanSamplingResultRecordAndSample SpanSamplingResultAttr = "RECORD_AND_SAMPLE"
123 )
124
125 // RPCGRPCStatusCodeAttr is an attribute conforming to the rpc.grpc.status_code
126 // semantic conventions. It represents the gRPC status code of the last gRPC
127 // requests performed in scope of this export call.
128 type RPCGRPCStatusCodeAttr int64
129
130 var (
131 // RPCGRPCStatusCodeOk is the OK.
132 RPCGRPCStatusCodeOk RPCGRPCStatusCodeAttr = 0
133 // RPCGRPCStatusCodeCancelled is the CANCELLED.
134 RPCGRPCStatusCodeCancelled RPCGRPCStatusCodeAttr = 1
135 // RPCGRPCStatusCodeUnknown is the UNKNOWN.
136 RPCGRPCStatusCodeUnknown RPCGRPCStatusCodeAttr = 2
137 // RPCGRPCStatusCodeInvalidArgument is the INVALID_ARGUMENT.
138 RPCGRPCStatusCodeInvalidArgument RPCGRPCStatusCodeAttr = 3
139 // RPCGRPCStatusCodeDeadlineExceeded is the DEADLINE_EXCEEDED.
140 RPCGRPCStatusCodeDeadlineExceeded RPCGRPCStatusCodeAttr = 4
141 // RPCGRPCStatusCodeNotFound is the NOT_FOUND.
142 RPCGRPCStatusCodeNotFound RPCGRPCStatusCodeAttr = 5
143 // RPCGRPCStatusCodeAlreadyExists is the ALREADY_EXISTS.
144 RPCGRPCStatusCodeAlreadyExists RPCGRPCStatusCodeAttr = 6
145 // RPCGRPCStatusCodePermissionDenied is the PERMISSION_DENIED.
146 RPCGRPCStatusCodePermissionDenied RPCGRPCStatusCodeAttr = 7
147 // RPCGRPCStatusCodeResourceExhausted is the RESOURCE_EXHAUSTED.
148 RPCGRPCStatusCodeResourceExhausted RPCGRPCStatusCodeAttr = 8
149 // RPCGRPCStatusCodeFailedPrecondition is the FAILED_PRECONDITION.
150 RPCGRPCStatusCodeFailedPrecondition RPCGRPCStatusCodeAttr = 9
151 // RPCGRPCStatusCodeAborted is the ABORTED.
152 RPCGRPCStatusCodeAborted RPCGRPCStatusCodeAttr = 10
153 // RPCGRPCStatusCodeOutOfRange is the OUT_OF_RANGE.
154 RPCGRPCStatusCodeOutOfRange RPCGRPCStatusCodeAttr = 11
155 // RPCGRPCStatusCodeUnimplemented is the UNIMPLEMENTED.
156 RPCGRPCStatusCodeUnimplemented RPCGRPCStatusCodeAttr = 12
157 // RPCGRPCStatusCodeInternal is the INTERNAL.
158 RPCGRPCStatusCodeInternal RPCGRPCStatusCodeAttr = 13
159 // RPCGRPCStatusCodeUnavailable is the UNAVAILABLE.
160 RPCGRPCStatusCodeUnavailable RPCGRPCStatusCodeAttr = 14
161 // RPCGRPCStatusCodeDataLoss is the DATA_LOSS.
162 RPCGRPCStatusCodeDataLoss RPCGRPCStatusCodeAttr = 15
163 // RPCGRPCStatusCodeUnauthenticated is the UNAUTHENTICATED.
164 RPCGRPCStatusCodeUnauthenticated RPCGRPCStatusCodeAttr = 16
165 )
166
167 // SDKExporterLogExported is an instrument used to record metric values
168 // conforming to the "otel.sdk.exporter.log.exported" semantic conventions. It
169 // represents the number of log records for which the export has finished, either
170 // successful or failed.
171 type SDKExporterLogExported struct {
172 metric.Int64Counter
173 }
174
175 var newSDKExporterLogExportedOpts = []metric.Int64CounterOption{
176 metric.WithDescription("The number of log records for which the export has finished, either successful or failed."),
177 metric.WithUnit("{log_record}"),
178 }
179
180 // NewSDKExporterLogExported returns a new SDKExporterLogExported instrument.
181 func NewSDKExporterLogExported(
182 m metric.Meter,
183 opt ...metric.Int64CounterOption,
184 ) (SDKExporterLogExported, error) {
185 // Check if the meter is nil.
186 if m == nil {
187 return SDKExporterLogExported{noop.Int64Counter{}}, nil
188 }
189
190 if len(opt) == 0 {
191 opt = newSDKExporterLogExportedOpts
192 } else {
193 opt = append(opt, newSDKExporterLogExportedOpts...)
194 }
195
196 i, err := m.Int64Counter(
197 "otel.sdk.exporter.log.exported",
198 opt...,
199 )
200 if err != nil {
201 return SDKExporterLogExported{noop.Int64Counter{}}, err
202 }
203 return SDKExporterLogExported{i}, nil
204 }
205
206 // Inst returns the underlying metric instrument.
207 func (m SDKExporterLogExported) Inst() metric.Int64Counter {
208 return m.Int64Counter
209 }
210
211 // Name returns the semantic convention name of the instrument.
212 func (SDKExporterLogExported) Name() string {
213 return "otel.sdk.exporter.log.exported"
214 }
215
216 // Unit returns the semantic convention unit of the instrument
217 func (SDKExporterLogExported) Unit() string {
218 return "{log_record}"
219 }
220
221 // Description returns the semantic convention description of the instrument
222 func (SDKExporterLogExported) Description() string {
223 return "The number of log records for which the export has finished, either successful or failed."
224 }
225
226 // Add adds incr to the existing count for attrs.
227 //
228 // All additional attrs passed are included in the recorded value.
229 //
230 // For successful exports, `error.type` MUST NOT be set. For failed exports,
231 // `error.type` MUST contain the failure cause.
232 // For exporters with partial success semantics (e.g. OTLP with
233 // `rejected_log_records`), rejected log records MUST count as failed and only
234 // non-rejected log records count as success.
235 // If no rejection reason is available, `rejected` SHOULD be used as value for
236 // `error.type`.
237 func (m SDKExporterLogExported) Add(
238 ctx context.Context,
239 incr int64,
240 attrs ...attribute.KeyValue,
241 ) {
242 if len(attrs) == 0 {
243 m.Int64Counter.Add(ctx, incr)
244 return
245 }
246
247 o := addOptPool.Get().(*[]metric.AddOption)
248 defer func() {
249 *o = (*o)[:0]
250 addOptPool.Put(o)
251 }()
252
253 *o = append(
254 *o,
255 metric.WithAttributes(
256 attrs...,
257 ),
258 )
259
260 m.Int64Counter.Add(ctx, incr, *o...)
261 }
262
263 // AddSet adds incr to the existing count for set.
264 //
265 // For successful exports, `error.type` MUST NOT be set. For failed exports,
266 // `error.type` MUST contain the failure cause.
267 // For exporters with partial success semantics (e.g. OTLP with
268 // `rejected_log_records`), rejected log records MUST count as failed and only
269 // non-rejected log records count as success.
270 // If no rejection reason is available, `rejected` SHOULD be used as value for
271 // `error.type`.
272 func (m SDKExporterLogExported) AddSet(ctx context.Context, incr int64, set attribute.Set) {
273 if set.Len() == 0 {
274 m.Int64Counter.Add(ctx, incr)
275 return
276 }
277
278 o := addOptPool.Get().(*[]metric.AddOption)
279 defer func() {
280 *o = (*o)[:0]
281 addOptPool.Put(o)
282 }()
283
284 *o = append(*o, metric.WithAttributeSet(set))
285 m.Int64Counter.Add(ctx, incr, *o...)
286 }
287
288 // AttrErrorType returns an optional attribute for the "error.type" semantic
289 // convention. It represents the describes a class of error the operation ended
290 // with.
291 func (SDKExporterLogExported) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
292 return attribute.String("error.type", string(val))
293 }
294
295 // AttrComponentName returns an optional attribute for the "otel.component.name"
296 // semantic convention. It represents a name uniquely identifying the instance of
297 // the OpenTelemetry component within its containing SDK instance.
298 func (SDKExporterLogExported) AttrComponentName(val string) attribute.KeyValue {
299 return attribute.String("otel.component.name", val)
300 }
301
302 // AttrComponentType returns an optional attribute for the "otel.component.type"
303 // semantic convention. It represents a name identifying the type of the
304 // OpenTelemetry component.
305 func (SDKExporterLogExported) AttrComponentType(val ComponentTypeAttr) attribute.KeyValue {
306 return attribute.String("otel.component.type", string(val))
307 }
308
309 // AttrServerAddress returns an optional attribute for the "server.address"
310 // semantic convention. It represents the server domain name if available without
311 // reverse DNS lookup; otherwise, IP address or Unix domain socket name.
312 func (SDKExporterLogExported) AttrServerAddress(val string) attribute.KeyValue {
313 return attribute.String("server.address", val)
314 }
315
316 // AttrServerPort returns an optional attribute for the "server.port" semantic
317 // convention. It represents the server port number.
318 func (SDKExporterLogExported) AttrServerPort(val int) attribute.KeyValue {
319 return attribute.Int("server.port", val)
320 }
321
322 // SDKExporterLogInflight is an instrument used to record metric values
323 // conforming to the "otel.sdk.exporter.log.inflight" semantic conventions. It
324 // represents the number of log records which were passed to the exporter, but
325 // that have not been exported yet (neither successful, nor failed).
326 type SDKExporterLogInflight struct {
327 metric.Int64UpDownCounter
328 }
329
330 var newSDKExporterLogInflightOpts = []metric.Int64UpDownCounterOption{
331 metric.WithDescription("The number of log records which were passed to the exporter, but that have not been exported yet (neither successful, nor failed)."),
332 metric.WithUnit("{log_record}"),
333 }
334
335 // NewSDKExporterLogInflight returns a new SDKExporterLogInflight instrument.
336 func NewSDKExporterLogInflight(
337 m metric.Meter,
338 opt ...metric.Int64UpDownCounterOption,
339 ) (SDKExporterLogInflight, error) {
340 // Check if the meter is nil.
341 if m == nil {
342 return SDKExporterLogInflight{noop.Int64UpDownCounter{}}, nil
343 }
344
345 if len(opt) == 0 {
346 opt = newSDKExporterLogInflightOpts
347 } else {
348 opt = append(opt, newSDKExporterLogInflightOpts...)
349 }
350
351 i, err := m.Int64UpDownCounter(
352 "otel.sdk.exporter.log.inflight",
353 opt...,
354 )
355 if err != nil {
356 return SDKExporterLogInflight{noop.Int64UpDownCounter{}}, err
357 }
358 return SDKExporterLogInflight{i}, nil
359 }
360
361 // Inst returns the underlying metric instrument.
362 func (m SDKExporterLogInflight) Inst() metric.Int64UpDownCounter {
363 return m.Int64UpDownCounter
364 }
365
366 // Name returns the semantic convention name of the instrument.
367 func (SDKExporterLogInflight) Name() string {
368 return "otel.sdk.exporter.log.inflight"
369 }
370
371 // Unit returns the semantic convention unit of the instrument
372 func (SDKExporterLogInflight) Unit() string {
373 return "{log_record}"
374 }
375
376 // Description returns the semantic convention description of the instrument
377 func (SDKExporterLogInflight) Description() string {
378 return "The number of log records which were passed to the exporter, but that have not been exported yet (neither successful, nor failed)."
379 }
380
381 // Add adds incr to the existing count for attrs.
382 //
383 // All additional attrs passed are included in the recorded value.
384 //
385 // For successful exports, `error.type` MUST NOT be set. For failed exports,
386 // `error.type` MUST contain the failure cause.
387 func (m SDKExporterLogInflight) Add(
388 ctx context.Context,
389 incr int64,
390 attrs ...attribute.KeyValue,
391 ) {
392 if len(attrs) == 0 {
393 m.Int64UpDownCounter.Add(ctx, incr)
394 return
395 }
396
397 o := addOptPool.Get().(*[]metric.AddOption)
398 defer func() {
399 *o = (*o)[:0]
400 addOptPool.Put(o)
401 }()
402
403 *o = append(
404 *o,
405 metric.WithAttributes(
406 attrs...,
407 ),
408 )
409
410 m.Int64UpDownCounter.Add(ctx, incr, *o...)
411 }
412
413 // AddSet adds incr to the existing count for set.
414 //
415 // For successful exports, `error.type` MUST NOT be set. For failed exports,
416 // `error.type` MUST contain the failure cause.
417 func (m SDKExporterLogInflight) AddSet(ctx context.Context, incr int64, set attribute.Set) {
418 if set.Len() == 0 {
419 m.Int64UpDownCounter.Add(ctx, incr)
420 return
421 }
422
423 o := addOptPool.Get().(*[]metric.AddOption)
424 defer func() {
425 *o = (*o)[:0]
426 addOptPool.Put(o)
427 }()
428
429 *o = append(*o, metric.WithAttributeSet(set))
430 m.Int64UpDownCounter.Add(ctx, incr, *o...)
431 }
432
433 // AttrComponentName returns an optional attribute for the "otel.component.name"
434 // semantic convention. It represents a name uniquely identifying the instance of
435 // the OpenTelemetry component within its containing SDK instance.
436 func (SDKExporterLogInflight) AttrComponentName(val string) attribute.KeyValue {
437 return attribute.String("otel.component.name", val)
438 }
439
440 // AttrComponentType returns an optional attribute for the "otel.component.type"
441 // semantic convention. It represents a name identifying the type of the
442 // OpenTelemetry component.
443 func (SDKExporterLogInflight) AttrComponentType(val ComponentTypeAttr) attribute.KeyValue {
444 return attribute.String("otel.component.type", string(val))
445 }
446
447 // AttrServerAddress returns an optional attribute for the "server.address"
448 // semantic convention. It represents the server domain name if available without
449 // reverse DNS lookup; otherwise, IP address or Unix domain socket name.
450 func (SDKExporterLogInflight) AttrServerAddress(val string) attribute.KeyValue {
451 return attribute.String("server.address", val)
452 }
453
454 // AttrServerPort returns an optional attribute for the "server.port" semantic
455 // convention. It represents the server port number.
456 func (SDKExporterLogInflight) AttrServerPort(val int) attribute.KeyValue {
457 return attribute.Int("server.port", val)
458 }
459
460 // SDKExporterMetricDataPointExported is an instrument used to record metric
461 // values conforming to the "otel.sdk.exporter.metric_data_point.exported"
462 // semantic conventions. It represents the number of metric data points for which
463 // the export has finished, either successful or failed.
464 type SDKExporterMetricDataPointExported struct {
465 metric.Int64Counter
466 }
467
468 var newSDKExporterMetricDataPointExportedOpts = []metric.Int64CounterOption{
469 metric.WithDescription("The number of metric data points for which the export has finished, either successful or failed."),
470 metric.WithUnit("{data_point}"),
471 }
472
473 // NewSDKExporterMetricDataPointExported returns a new
474 // SDKExporterMetricDataPointExported instrument.
475 func NewSDKExporterMetricDataPointExported(
476 m metric.Meter,
477 opt ...metric.Int64CounterOption,
478 ) (SDKExporterMetricDataPointExported, error) {
479 // Check if the meter is nil.
480 if m == nil {
481 return SDKExporterMetricDataPointExported{noop.Int64Counter{}}, nil
482 }
483
484 if len(opt) == 0 {
485 opt = newSDKExporterMetricDataPointExportedOpts
486 } else {
487 opt = append(opt, newSDKExporterMetricDataPointExportedOpts...)
488 }
489
490 i, err := m.Int64Counter(
491 "otel.sdk.exporter.metric_data_point.exported",
492 opt...,
493 )
494 if err != nil {
495 return SDKExporterMetricDataPointExported{noop.Int64Counter{}}, err
496 }
497 return SDKExporterMetricDataPointExported{i}, nil
498 }
499
500 // Inst returns the underlying metric instrument.
501 func (m SDKExporterMetricDataPointExported) Inst() metric.Int64Counter {
502 return m.Int64Counter
503 }
504
505 // Name returns the semantic convention name of the instrument.
506 func (SDKExporterMetricDataPointExported) Name() string {
507 return "otel.sdk.exporter.metric_data_point.exported"
508 }
509
510 // Unit returns the semantic convention unit of the instrument
511 func (SDKExporterMetricDataPointExported) Unit() string {
512 return "{data_point}"
513 }
514
515 // Description returns the semantic convention description of the instrument
516 func (SDKExporterMetricDataPointExported) Description() string {
517 return "The number of metric data points for which the export has finished, either successful or failed."
518 }
519
520 // Add adds incr to the existing count for attrs.
521 //
522 // All additional attrs passed are included in the recorded value.
523 //
524 // For successful exports, `error.type` MUST NOT be set. For failed exports,
525 // `error.type` MUST contain the failure cause.
526 // For exporters with partial success semantics (e.g. OTLP with
527 // `rejected_data_points`), rejected data points MUST count as failed and only
528 // non-rejected data points count as success.
529 // If no rejection reason is available, `rejected` SHOULD be used as value for
530 // `error.type`.
531 func (m SDKExporterMetricDataPointExported) Add(
532 ctx context.Context,
533 incr int64,
534 attrs ...attribute.KeyValue,
535 ) {
536 if len(attrs) == 0 {
537 m.Int64Counter.Add(ctx, incr)
538 return
539 }
540
541 o := addOptPool.Get().(*[]metric.AddOption)
542 defer func() {
543 *o = (*o)[:0]
544 addOptPool.Put(o)
545 }()
546
547 *o = append(
548 *o,
549 metric.WithAttributes(
550 attrs...,
551 ),
552 )
553
554 m.Int64Counter.Add(ctx, incr, *o...)
555 }
556
557 // AddSet adds incr to the existing count for set.
558 //
559 // For successful exports, `error.type` MUST NOT be set. For failed exports,
560 // `error.type` MUST contain the failure cause.
561 // For exporters with partial success semantics (e.g. OTLP with
562 // `rejected_data_points`), rejected data points MUST count as failed and only
563 // non-rejected data points count as success.
564 // If no rejection reason is available, `rejected` SHOULD be used as value for
565 // `error.type`.
566 func (m SDKExporterMetricDataPointExported) 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 (SDKExporterMetricDataPointExported) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
586 return attribute.String("error.type", string(val))
587 }
588
589 // AttrComponentName returns an optional attribute for the "otel.component.name"
590 // semantic convention. It represents a name uniquely identifying the instance of
591 // the OpenTelemetry component within its containing SDK instance.
592 func (SDKExporterMetricDataPointExported) AttrComponentName(val string) attribute.KeyValue {
593 return attribute.String("otel.component.name", val)
594 }
595
596 // AttrComponentType returns an optional attribute for the "otel.component.type"
597 // semantic convention. It represents a name identifying the type of the
598 // OpenTelemetry component.
599 func (SDKExporterMetricDataPointExported) AttrComponentType(val ComponentTypeAttr) attribute.KeyValue {
600 return attribute.String("otel.component.type", string(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 (SDKExporterMetricDataPointExported) AttrServerAddress(val string) attribute.KeyValue {
607 return attribute.String("server.address", val)
608 }
609
610 // AttrServerPort returns an optional attribute for the "server.port" semantic
611 // convention. It represents the server port number.
612 func (SDKExporterMetricDataPointExported) AttrServerPort(val int) attribute.KeyValue {
613 return attribute.Int("server.port", val)
614 }
615
616 // SDKExporterMetricDataPointInflight is an instrument used to record metric
617 // values conforming to the "otel.sdk.exporter.metric_data_point.inflight"
618 // semantic conventions. It represents the number of metric data points which
619 // were passed to the exporter, but that have not been exported yet (neither
620 // successful, nor failed).
621 type SDKExporterMetricDataPointInflight struct {
622 metric.Int64UpDownCounter
623 }
624
625 var newSDKExporterMetricDataPointInflightOpts = []metric.Int64UpDownCounterOption{
626 metric.WithDescription("The number of metric data points which were passed to the exporter, but that have not been exported yet (neither successful, nor failed)."),
627 metric.WithUnit("{data_point}"),
628 }
629
630 // NewSDKExporterMetricDataPointInflight returns a new
631 // SDKExporterMetricDataPointInflight instrument.
632 func NewSDKExporterMetricDataPointInflight(
633 m metric.Meter,
634 opt ...metric.Int64UpDownCounterOption,
635 ) (SDKExporterMetricDataPointInflight, error) {
636 // Check if the meter is nil.
637 if m == nil {
638 return SDKExporterMetricDataPointInflight{noop.Int64UpDownCounter{}}, nil
639 }
640
641 if len(opt) == 0 {
642 opt = newSDKExporterMetricDataPointInflightOpts
643 } else {
644 opt = append(opt, newSDKExporterMetricDataPointInflightOpts...)
645 }
646
647 i, err := m.Int64UpDownCounter(
648 "otel.sdk.exporter.metric_data_point.inflight",
649 opt...,
650 )
651 if err != nil {
652 return SDKExporterMetricDataPointInflight{noop.Int64UpDownCounter{}}, err
653 }
654 return SDKExporterMetricDataPointInflight{i}, nil
655 }
656
657 // Inst returns the underlying metric instrument.
658 func (m SDKExporterMetricDataPointInflight) Inst() metric.Int64UpDownCounter {
659 return m.Int64UpDownCounter
660 }
661
662 // Name returns the semantic convention name of the instrument.
663 func (SDKExporterMetricDataPointInflight) Name() string {
664 return "otel.sdk.exporter.metric_data_point.inflight"
665 }
666
667 // Unit returns the semantic convention unit of the instrument
668 func (SDKExporterMetricDataPointInflight) Unit() string {
669 return "{data_point}"
670 }
671
672 // Description returns the semantic convention description of the instrument
673 func (SDKExporterMetricDataPointInflight) Description() string {
674 return "The number of metric data points which were passed to the exporter, but that have not been exported yet (neither successful, nor failed)."
675 }
676
677 // Add adds incr to the existing count for attrs.
678 //
679 // All additional attrs passed are included in the recorded value.
680 //
681 // For successful exports, `error.type` MUST NOT be set. For failed exports,
682 // `error.type` MUST contain the failure cause.
683 func (m SDKExporterMetricDataPointInflight) Add(
684 ctx context.Context,
685 incr int64,
686 attrs ...attribute.KeyValue,
687 ) {
688 if len(attrs) == 0 {
689 m.Int64UpDownCounter.Add(ctx, incr)
690 return
691 }
692
693 o := addOptPool.Get().(*[]metric.AddOption)
694 defer func() {
695 *o = (*o)[:0]
696 addOptPool.Put(o)
697 }()
698
699 *o = append(
700 *o,
701 metric.WithAttributes(
702 attrs...,
703 ),
704 )
705
706 m.Int64UpDownCounter.Add(ctx, incr, *o...)
707 }
708
709 // AddSet adds incr to the existing count for set.
710 //
711 // For successful exports, `error.type` MUST NOT be set. For failed exports,
712 // `error.type` MUST contain the failure cause.
713 func (m SDKExporterMetricDataPointInflight) AddSet(ctx context.Context, incr int64, set attribute.Set) {
714 if set.Len() == 0 {
715 m.Int64UpDownCounter.Add(ctx, incr)
716 return
717 }
718
719 o := addOptPool.Get().(*[]metric.AddOption)
720 defer func() {
721 *o = (*o)[:0]
722 addOptPool.Put(o)
723 }()
724
725 *o = append(*o, metric.WithAttributeSet(set))
726 m.Int64UpDownCounter.Add(ctx, incr, *o...)
727 }
728
729 // AttrComponentName returns an optional attribute for the "otel.component.name"
730 // semantic convention. It represents a name uniquely identifying the instance of
731 // the OpenTelemetry component within its containing SDK instance.
732 func (SDKExporterMetricDataPointInflight) AttrComponentName(val string) attribute.KeyValue {
733 return attribute.String("otel.component.name", val)
734 }
735
736 // AttrComponentType returns an optional attribute for the "otel.component.type"
737 // semantic convention. It represents a name identifying the type of the
738 // OpenTelemetry component.
739 func (SDKExporterMetricDataPointInflight) AttrComponentType(val ComponentTypeAttr) attribute.KeyValue {
740 return attribute.String("otel.component.type", string(val))
741 }
742
743 // AttrServerAddress returns an optional attribute for the "server.address"
744 // semantic convention. It represents the server domain name if available without
745 // reverse DNS lookup; otherwise, IP address or Unix domain socket name.
746 func (SDKExporterMetricDataPointInflight) AttrServerAddress(val string) attribute.KeyValue {
747 return attribute.String("server.address", val)
748 }
749
750 // AttrServerPort returns an optional attribute for the "server.port" semantic
751 // convention. It represents the server port number.
752 func (SDKExporterMetricDataPointInflight) AttrServerPort(val int) attribute.KeyValue {
753 return attribute.Int("server.port", val)
754 }
755
756 // SDKExporterOperationDuration is an instrument used to record metric values
757 // conforming to the "otel.sdk.exporter.operation.duration" semantic conventions.
758 // It represents the duration of exporting a batch of telemetry records.
759 type SDKExporterOperationDuration struct {
760 metric.Float64Histogram
761 }
762
763 var newSDKExporterOperationDurationOpts = []metric.Float64HistogramOption{
764 metric.WithDescription("The duration of exporting a batch of telemetry records."),
765 metric.WithUnit("s"),
766 }
767
768 // NewSDKExporterOperationDuration returns a new SDKExporterOperationDuration
769 // instrument.
770 func NewSDKExporterOperationDuration(
771 m metric.Meter,
772 opt ...metric.Float64HistogramOption,
773 ) (SDKExporterOperationDuration, error) {
774 // Check if the meter is nil.
775 if m == nil {
776 return SDKExporterOperationDuration{noop.Float64Histogram{}}, nil
777 }
778
779 if len(opt) == 0 {
780 opt = newSDKExporterOperationDurationOpts
781 } else {
782 opt = append(opt, newSDKExporterOperationDurationOpts...)
783 }
784
785 i, err := m.Float64Histogram(
786 "otel.sdk.exporter.operation.duration",
787 opt...,
788 )
789 if err != nil {
790 return SDKExporterOperationDuration{noop.Float64Histogram{}}, err
791 }
792 return SDKExporterOperationDuration{i}, nil
793 }
794
795 // Inst returns the underlying metric instrument.
796 func (m SDKExporterOperationDuration) Inst() metric.Float64Histogram {
797 return m.Float64Histogram
798 }
799
800 // Name returns the semantic convention name of the instrument.
801 func (SDKExporterOperationDuration) Name() string {
802 return "otel.sdk.exporter.operation.duration"
803 }
804
805 // Unit returns the semantic convention unit of the instrument
806 func (SDKExporterOperationDuration) Unit() string {
807 return "s"
808 }
809
810 // Description returns the semantic convention description of the instrument
811 func (SDKExporterOperationDuration) Description() string {
812 return "The duration of exporting a batch of telemetry records."
813 }
814
815 // Record records val to the current distribution for attrs.
816 //
817 // All additional attrs passed are included in the recorded value.
818 //
819 // This metric defines successful operations using the full success definitions
820 // for [http]
821 // and [grpc]. Anything else is defined as an unsuccessful operation. For
822 // successful
823 // operations, `error.type` MUST NOT be set. For unsuccessful export operations,
824 // `error.type` MUST contain a relevant failure cause.
825 //
826 // [http]: https://github.com/open-telemetry/opentelemetry-proto/blob/v1.5.0/docs/specification.md#full-success-1
827 // [grpc]: https://github.com/open-telemetry/opentelemetry-proto/blob/v1.5.0/docs/specification.md#full-success
828 func (m SDKExporterOperationDuration) Record(
829 ctx context.Context,
830 val float64,
831 attrs ...attribute.KeyValue,
832 ) {
833 if len(attrs) == 0 {
834 m.Float64Histogram.Record(ctx, val)
835 return
836 }
837
838 o := recOptPool.Get().(*[]metric.RecordOption)
839 defer func() {
840 *o = (*o)[:0]
841 recOptPool.Put(o)
842 }()
843
844 *o = append(
845 *o,
846 metric.WithAttributes(
847 attrs...,
848 ),
849 )
850
851 m.Float64Histogram.Record(ctx, val, *o...)
852 }
853
854 // RecordSet records val to the current distribution for set.
855 //
856 // This metric defines successful operations using the full success definitions
857 // for [http]
858 // and [grpc]. Anything else is defined as an unsuccessful operation. For
859 // successful
860 // operations, `error.type` MUST NOT be set. For unsuccessful export operations,
861 // `error.type` MUST contain a relevant failure cause.
862 //
863 // [http]: https://github.com/open-telemetry/opentelemetry-proto/blob/v1.5.0/docs/specification.md#full-success-1
864 // [grpc]: https://github.com/open-telemetry/opentelemetry-proto/blob/v1.5.0/docs/specification.md#full-success
865 func (m SDKExporterOperationDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
866 if set.Len() == 0 {
867 m.Float64Histogram.Record(ctx, val)
868 return
869 }
870
871 o := recOptPool.Get().(*[]metric.RecordOption)
872 defer func() {
873 *o = (*o)[:0]
874 recOptPool.Put(o)
875 }()
876
877 *o = append(*o, metric.WithAttributeSet(set))
878 m.Float64Histogram.Record(ctx, val, *o...)
879 }
880
881 // AttrErrorType returns an optional attribute for the "error.type" semantic
882 // convention. It represents the describes a class of error the operation ended
883 // with.
884 func (SDKExporterOperationDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
885 return attribute.String("error.type", string(val))
886 }
887
888 // AttrHTTPResponseStatusCode returns an optional attribute for the
889 // "http.response.status_code" semantic convention. It represents the HTTP status
890 // code of the last HTTP request performed in scope of this export call.
891 func (SDKExporterOperationDuration) AttrHTTPResponseStatusCode(val int) attribute.KeyValue {
892 return attribute.Int("http.response.status_code", val)
893 }
894
895 // AttrComponentName returns an optional attribute for the "otel.component.name"
896 // semantic convention. It represents a name uniquely identifying the instance of
897 // the OpenTelemetry component within its containing SDK instance.
898 func (SDKExporterOperationDuration) AttrComponentName(val string) attribute.KeyValue {
899 return attribute.String("otel.component.name", val)
900 }
901
902 // AttrComponentType returns an optional attribute for the "otel.component.type"
903 // semantic convention. It represents a name identifying the type of the
904 // OpenTelemetry component.
905 func (SDKExporterOperationDuration) AttrComponentType(val ComponentTypeAttr) attribute.KeyValue {
906 return attribute.String("otel.component.type", string(val))
907 }
908
909 // AttrRPCGRPCStatusCode returns an optional attribute for the
910 // "rpc.grpc.status_code" semantic convention. It represents the gRPC status code
911 // of the last gRPC requests performed in scope of this export call.
912 func (SDKExporterOperationDuration) AttrRPCGRPCStatusCode(val RPCGRPCStatusCodeAttr) attribute.KeyValue {
913 return attribute.Int64("rpc.grpc.status_code", int64(val))
914 }
915
916 // AttrServerAddress returns an optional attribute for the "server.address"
917 // semantic convention. It represents the server domain name if available without
918 // reverse DNS lookup; otherwise, IP address or Unix domain socket name.
919 func (SDKExporterOperationDuration) AttrServerAddress(val string) attribute.KeyValue {
920 return attribute.String("server.address", val)
921 }
922
923 // AttrServerPort returns an optional attribute for the "server.port" semantic
924 // convention. It represents the server port number.
925 func (SDKExporterOperationDuration) AttrServerPort(val int) attribute.KeyValue {
926 return attribute.Int("server.port", val)
927 }
928
929 // SDKExporterSpanExported is an instrument used to record metric values
930 // conforming to the "otel.sdk.exporter.span.exported" semantic conventions. It
931 // represents the number of spans for which the export has finished, either
932 // successful or failed.
933 type SDKExporterSpanExported struct {
934 metric.Int64Counter
935 }
936
937 var newSDKExporterSpanExportedOpts = []metric.Int64CounterOption{
938 metric.WithDescription("The number of spans for which the export has finished, either successful or failed."),
939 metric.WithUnit("{span}"),
940 }
941
942 // NewSDKExporterSpanExported returns a new SDKExporterSpanExported instrument.
943 func NewSDKExporterSpanExported(
944 m metric.Meter,
945 opt ...metric.Int64CounterOption,
946 ) (SDKExporterSpanExported, error) {
947 // Check if the meter is nil.
948 if m == nil {
949 return SDKExporterSpanExported{noop.Int64Counter{}}, nil
950 }
951
952 if len(opt) == 0 {
953 opt = newSDKExporterSpanExportedOpts
954 } else {
955 opt = append(opt, newSDKExporterSpanExportedOpts...)
956 }
957
958 i, err := m.Int64Counter(
959 "otel.sdk.exporter.span.exported",
960 opt...,
961 )
962 if err != nil {
963 return SDKExporterSpanExported{noop.Int64Counter{}}, err
964 }
965 return SDKExporterSpanExported{i}, nil
966 }
967
968 // Inst returns the underlying metric instrument.
969 func (m SDKExporterSpanExported) Inst() metric.Int64Counter {
970 return m.Int64Counter
971 }
972
973 // Name returns the semantic convention name of the instrument.
974 func (SDKExporterSpanExported) Name() string {
975 return "otel.sdk.exporter.span.exported"
976 }
977
978 // Unit returns the semantic convention unit of the instrument
979 func (SDKExporterSpanExported) Unit() string {
980 return "{span}"
981 }
982
983 // Description returns the semantic convention description of the instrument
984 func (SDKExporterSpanExported) Description() string {
985 return "The number of spans for which the export has finished, either successful or failed."
986 }
987
988 // Add adds incr to the existing count for attrs.
989 //
990 // All additional attrs passed are included in the recorded value.
991 //
992 // For successful exports, `error.type` MUST NOT be set. For failed exports,
993 // `error.type` MUST contain the failure cause.
994 // For exporters with partial success semantics (e.g. OTLP with `rejected_spans`
995 // ), rejected spans MUST count as failed and only non-rejected spans count as
996 // success.
997 // If no rejection reason is available, `rejected` SHOULD be used as value for
998 // `error.type`.
999 func (m SDKExporterSpanExported) Add(
1000 ctx context.Context,
1001 incr int64,
1002 attrs ...attribute.KeyValue,
1003 ) {
1004 if len(attrs) == 0 {
1005 m.Int64Counter.Add(ctx, incr)
1006 return
1007 }
1008
1009 o := addOptPool.Get().(*[]metric.AddOption)
1010 defer func() {
1011 *o = (*o)[:0]
1012 addOptPool.Put(o)
1013 }()
1014
1015 *o = append(
1016 *o,
1017 metric.WithAttributes(
1018 attrs...,
1019 ),
1020 )
1021
1022 m.Int64Counter.Add(ctx, incr, *o...)
1023 }
1024
1025 // AddSet adds incr to the existing count for set.
1026 //
1027 // For successful exports, `error.type` MUST NOT be set. For failed exports,
1028 // `error.type` MUST contain the failure cause.
1029 // For exporters with partial success semantics (e.g. OTLP with `rejected_spans`
1030 // ), rejected spans MUST count as failed and only non-rejected spans count as
1031 // success.
1032 // If no rejection reason is available, `rejected` SHOULD be used as value for
1033 // `error.type`.
1034 func (m SDKExporterSpanExported) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1035 if set.Len() == 0 {
1036 m.Int64Counter.Add(ctx, incr)
1037 return
1038 }
1039
1040 o := addOptPool.Get().(*[]metric.AddOption)
1041 defer func() {
1042 *o = (*o)[:0]
1043 addOptPool.Put(o)
1044 }()
1045
1046 *o = append(*o, metric.WithAttributeSet(set))
1047 m.Int64Counter.Add(ctx, incr, *o...)
1048 }
1049
1050 // AttrErrorType returns an optional attribute for the "error.type" semantic
1051 // convention. It represents the describes a class of error the operation ended
1052 // with.
1053 func (SDKExporterSpanExported) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1054 return attribute.String("error.type", string(val))
1055 }
1056
1057 // AttrComponentName returns an optional attribute for the "otel.component.name"
1058 // semantic convention. It represents a name uniquely identifying the instance of
1059 // the OpenTelemetry component within its containing SDK instance.
1060 func (SDKExporterSpanExported) AttrComponentName(val string) attribute.KeyValue {
1061 return attribute.String("otel.component.name", val)
1062 }
1063
1064 // AttrComponentType returns an optional attribute for the "otel.component.type"
1065 // semantic convention. It represents a name identifying the type of the
1066 // OpenTelemetry component.
1067 func (SDKExporterSpanExported) AttrComponentType(val ComponentTypeAttr) attribute.KeyValue {
1068 return attribute.String("otel.component.type", string(val))
1069 }
1070
1071 // AttrServerAddress returns an optional attribute for the "server.address"
1072 // semantic convention. It represents the server domain name if available without
1073 // reverse DNS lookup; otherwise, IP address or Unix domain socket name.
1074 func (SDKExporterSpanExported) AttrServerAddress(val string) attribute.KeyValue {
1075 return attribute.String("server.address", val)
1076 }
1077
1078 // AttrServerPort returns an optional attribute for the "server.port" semantic
1079 // convention. It represents the server port number.
1080 func (SDKExporterSpanExported) AttrServerPort(val int) attribute.KeyValue {
1081 return attribute.Int("server.port", val)
1082 }
1083
1084 // SDKExporterSpanInflight is an instrument used to record metric values
1085 // conforming to the "otel.sdk.exporter.span.inflight" semantic conventions. It
1086 // represents the number of spans which were passed to the exporter, but that
1087 // have not been exported yet (neither successful, nor failed).
1088 type SDKExporterSpanInflight struct {
1089 metric.Int64UpDownCounter
1090 }
1091
1092 var newSDKExporterSpanInflightOpts = []metric.Int64UpDownCounterOption{
1093 metric.WithDescription("The number of spans which were passed to the exporter, but that have not been exported yet (neither successful, nor failed)."),
1094 metric.WithUnit("{span}"),
1095 }
1096
1097 // NewSDKExporterSpanInflight returns a new SDKExporterSpanInflight instrument.
1098 func NewSDKExporterSpanInflight(
1099 m metric.Meter,
1100 opt ...metric.Int64UpDownCounterOption,
1101 ) (SDKExporterSpanInflight, error) {
1102 // Check if the meter is nil.
1103 if m == nil {
1104 return SDKExporterSpanInflight{noop.Int64UpDownCounter{}}, nil
1105 }
1106
1107 if len(opt) == 0 {
1108 opt = newSDKExporterSpanInflightOpts
1109 } else {
1110 opt = append(opt, newSDKExporterSpanInflightOpts...)
1111 }
1112
1113 i, err := m.Int64UpDownCounter(
1114 "otel.sdk.exporter.span.inflight",
1115 opt...,
1116 )
1117 if err != nil {
1118 return SDKExporterSpanInflight{noop.Int64UpDownCounter{}}, err
1119 }
1120 return SDKExporterSpanInflight{i}, nil
1121 }
1122
1123 // Inst returns the underlying metric instrument.
1124 func (m SDKExporterSpanInflight) Inst() metric.Int64UpDownCounter {
1125 return m.Int64UpDownCounter
1126 }
1127
1128 // Name returns the semantic convention name of the instrument.
1129 func (SDKExporterSpanInflight) Name() string {
1130 return "otel.sdk.exporter.span.inflight"
1131 }
1132
1133 // Unit returns the semantic convention unit of the instrument
1134 func (SDKExporterSpanInflight) Unit() string {
1135 return "{span}"
1136 }
1137
1138 // Description returns the semantic convention description of the instrument
1139 func (SDKExporterSpanInflight) Description() string {
1140 return "The number of spans which were passed to the exporter, but that have not been exported yet (neither successful, nor failed)."
1141 }
1142
1143 // Add adds incr to the existing count for attrs.
1144 //
1145 // All additional attrs passed are included in the recorded value.
1146 //
1147 // For successful exports, `error.type` MUST NOT be set. For failed exports,
1148 // `error.type` MUST contain the failure cause.
1149 func (m SDKExporterSpanInflight) Add(
1150 ctx context.Context,
1151 incr int64,
1152 attrs ...attribute.KeyValue,
1153 ) {
1154 if len(attrs) == 0 {
1155 m.Int64UpDownCounter.Add(ctx, incr)
1156 return
1157 }
1158
1159 o := addOptPool.Get().(*[]metric.AddOption)
1160 defer func() {
1161 *o = (*o)[:0]
1162 addOptPool.Put(o)
1163 }()
1164
1165 *o = append(
1166 *o,
1167 metric.WithAttributes(
1168 attrs...,
1169 ),
1170 )
1171
1172 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1173 }
1174
1175 // AddSet adds incr to the existing count for set.
1176 //
1177 // For successful exports, `error.type` MUST NOT be set. For failed exports,
1178 // `error.type` MUST contain the failure cause.
1179 func (m SDKExporterSpanInflight) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1180 if set.Len() == 0 {
1181 m.Int64UpDownCounter.Add(ctx, incr)
1182 return
1183 }
1184
1185 o := addOptPool.Get().(*[]metric.AddOption)
1186 defer func() {
1187 *o = (*o)[:0]
1188 addOptPool.Put(o)
1189 }()
1190
1191 *o = append(*o, metric.WithAttributeSet(set))
1192 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1193 }
1194
1195 // AttrComponentName returns an optional attribute for the "otel.component.name"
1196 // semantic convention. It represents a name uniquely identifying the instance of
1197 // the OpenTelemetry component within its containing SDK instance.
1198 func (SDKExporterSpanInflight) AttrComponentName(val string) attribute.KeyValue {
1199 return attribute.String("otel.component.name", val)
1200 }
1201
1202 // AttrComponentType returns an optional attribute for the "otel.component.type"
1203 // semantic convention. It represents a name identifying the type of the
1204 // OpenTelemetry component.
1205 func (SDKExporterSpanInflight) AttrComponentType(val ComponentTypeAttr) attribute.KeyValue {
1206 return attribute.String("otel.component.type", string(val))
1207 }
1208
1209 // AttrServerAddress returns an optional attribute for the "server.address"
1210 // semantic convention. It represents the server domain name if available without
1211 // reverse DNS lookup; otherwise, IP address or Unix domain socket name.
1212 func (SDKExporterSpanInflight) AttrServerAddress(val string) attribute.KeyValue {
1213 return attribute.String("server.address", val)
1214 }
1215
1216 // AttrServerPort returns an optional attribute for the "server.port" semantic
1217 // convention. It represents the server port number.
1218 func (SDKExporterSpanInflight) AttrServerPort(val int) attribute.KeyValue {
1219 return attribute.Int("server.port", val)
1220 }
1221
1222 // SDKLogCreated is an instrument used to record metric values conforming to the
1223 // "otel.sdk.log.created" semantic conventions. It represents the number of logs
1224 // submitted to enabled SDK Loggers.
1225 type SDKLogCreated struct {
1226 metric.Int64Counter
1227 }
1228
1229 var newSDKLogCreatedOpts = []metric.Int64CounterOption{
1230 metric.WithDescription("The number of logs submitted to enabled SDK Loggers."),
1231 metric.WithUnit("{log_record}"),
1232 }
1233
1234 // NewSDKLogCreated returns a new SDKLogCreated instrument.
1235 func NewSDKLogCreated(
1236 m metric.Meter,
1237 opt ...metric.Int64CounterOption,
1238 ) (SDKLogCreated, error) {
1239 // Check if the meter is nil.
1240 if m == nil {
1241 return SDKLogCreated{noop.Int64Counter{}}, nil
1242 }
1243
1244 if len(opt) == 0 {
1245 opt = newSDKLogCreatedOpts
1246 } else {
1247 opt = append(opt, newSDKLogCreatedOpts...)
1248 }
1249
1250 i, err := m.Int64Counter(
1251 "otel.sdk.log.created",
1252 opt...,
1253 )
1254 if err != nil {
1255 return SDKLogCreated{noop.Int64Counter{}}, err
1256 }
1257 return SDKLogCreated{i}, nil
1258 }
1259
1260 // Inst returns the underlying metric instrument.
1261 func (m SDKLogCreated) Inst() metric.Int64Counter {
1262 return m.Int64Counter
1263 }
1264
1265 // Name returns the semantic convention name of the instrument.
1266 func (SDKLogCreated) Name() string {
1267 return "otel.sdk.log.created"
1268 }
1269
1270 // Unit returns the semantic convention unit of the instrument
1271 func (SDKLogCreated) Unit() string {
1272 return "{log_record}"
1273 }
1274
1275 // Description returns the semantic convention description of the instrument
1276 func (SDKLogCreated) Description() string {
1277 return "The number of logs submitted to enabled SDK Loggers."
1278 }
1279
1280 // Add adds incr to the existing count for attrs.
1281 func (m SDKLogCreated) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
1282 if len(attrs) == 0 {
1283 m.Int64Counter.Add(ctx, incr)
1284 return
1285 }
1286
1287 o := addOptPool.Get().(*[]metric.AddOption)
1288 defer func() {
1289 *o = (*o)[:0]
1290 addOptPool.Put(o)
1291 }()
1292
1293 *o = append(*o, metric.WithAttributes(attrs...))
1294 m.Int64Counter.Add(ctx, incr, *o...)
1295 }
1296
1297 // AddSet adds incr to the existing count for set.
1298 func (m SDKLogCreated) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1299 if set.Len() == 0 {
1300 m.Int64Counter.Add(ctx, incr)
1301 return
1302 }
1303
1304 o := addOptPool.Get().(*[]metric.AddOption)
1305 defer func() {
1306 *o = (*o)[:0]
1307 addOptPool.Put(o)
1308 }()
1309
1310 *o = append(*o, metric.WithAttributeSet(set))
1311 m.Int64Counter.Add(ctx, incr, *o...)
1312 }
1313
1314 // SDKMetricReaderCollectionDuration is an instrument used to record metric
1315 // values conforming to the "otel.sdk.metric_reader.collection.duration" semantic
1316 // conventions. It represents the duration of the collect operation of the metric
1317 // reader.
1318 type SDKMetricReaderCollectionDuration struct {
1319 metric.Float64Histogram
1320 }
1321
1322 var newSDKMetricReaderCollectionDurationOpts = []metric.Float64HistogramOption{
1323 metric.WithDescription("The duration of the collect operation of the metric reader."),
1324 metric.WithUnit("s"),
1325 }
1326
1327 // NewSDKMetricReaderCollectionDuration returns a new
1328 // SDKMetricReaderCollectionDuration instrument.
1329 func NewSDKMetricReaderCollectionDuration(
1330 m metric.Meter,
1331 opt ...metric.Float64HistogramOption,
1332 ) (SDKMetricReaderCollectionDuration, error) {
1333 // Check if the meter is nil.
1334 if m == nil {
1335 return SDKMetricReaderCollectionDuration{noop.Float64Histogram{}}, nil
1336 }
1337
1338 if len(opt) == 0 {
1339 opt = newSDKMetricReaderCollectionDurationOpts
1340 } else {
1341 opt = append(opt, newSDKMetricReaderCollectionDurationOpts...)
1342 }
1343
1344 i, err := m.Float64Histogram(
1345 "otel.sdk.metric_reader.collection.duration",
1346 opt...,
1347 )
1348 if err != nil {
1349 return SDKMetricReaderCollectionDuration{noop.Float64Histogram{}}, err
1350 }
1351 return SDKMetricReaderCollectionDuration{i}, nil
1352 }
1353
1354 // Inst returns the underlying metric instrument.
1355 func (m SDKMetricReaderCollectionDuration) Inst() metric.Float64Histogram {
1356 return m.Float64Histogram
1357 }
1358
1359 // Name returns the semantic convention name of the instrument.
1360 func (SDKMetricReaderCollectionDuration) Name() string {
1361 return "otel.sdk.metric_reader.collection.duration"
1362 }
1363
1364 // Unit returns the semantic convention unit of the instrument
1365 func (SDKMetricReaderCollectionDuration) Unit() string {
1366 return "s"
1367 }
1368
1369 // Description returns the semantic convention description of the instrument
1370 func (SDKMetricReaderCollectionDuration) Description() string {
1371 return "The duration of the collect operation of the metric reader."
1372 }
1373
1374 // Record records val to the current distribution for attrs.
1375 //
1376 // All additional attrs passed are included in the recorded value.
1377 //
1378 // For successful collections, `error.type` MUST NOT be set. For failed
1379 // collections, `error.type` SHOULD contain the failure cause.
1380 // It can happen that metrics collection is successful for some MetricProducers,
1381 // while others fail. In that case `error.type` SHOULD be set to any of the
1382 // failure causes.
1383 func (m SDKMetricReaderCollectionDuration) Record(
1384 ctx context.Context,
1385 val float64,
1386 attrs ...attribute.KeyValue,
1387 ) {
1388 if len(attrs) == 0 {
1389 m.Float64Histogram.Record(ctx, val)
1390 return
1391 }
1392
1393 o := recOptPool.Get().(*[]metric.RecordOption)
1394 defer func() {
1395 *o = (*o)[:0]
1396 recOptPool.Put(o)
1397 }()
1398
1399 *o = append(
1400 *o,
1401 metric.WithAttributes(
1402 attrs...,
1403 ),
1404 )
1405
1406 m.Float64Histogram.Record(ctx, val, *o...)
1407 }
1408
1409 // RecordSet records val to the current distribution for set.
1410 //
1411 // For successful collections, `error.type` MUST NOT be set. For failed
1412 // collections, `error.type` SHOULD contain the failure cause.
1413 // It can happen that metrics collection is successful for some MetricProducers,
1414 // while others fail. In that case `error.type` SHOULD be set to any of the
1415 // failure causes.
1416 func (m SDKMetricReaderCollectionDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
1417 if set.Len() == 0 {
1418 m.Float64Histogram.Record(ctx, val)
1419 return
1420 }
1421
1422 o := recOptPool.Get().(*[]metric.RecordOption)
1423 defer func() {
1424 *o = (*o)[:0]
1425 recOptPool.Put(o)
1426 }()
1427
1428 *o = append(*o, metric.WithAttributeSet(set))
1429 m.Float64Histogram.Record(ctx, val, *o...)
1430 }
1431
1432 // AttrErrorType returns an optional attribute for the "error.type" semantic
1433 // convention. It represents the describes a class of error the operation ended
1434 // with.
1435 func (SDKMetricReaderCollectionDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1436 return attribute.String("error.type", string(val))
1437 }
1438
1439 // AttrComponentName returns an optional attribute for the "otel.component.name"
1440 // semantic convention. It represents a name uniquely identifying the instance of
1441 // the OpenTelemetry component within its containing SDK instance.
1442 func (SDKMetricReaderCollectionDuration) AttrComponentName(val string) attribute.KeyValue {
1443 return attribute.String("otel.component.name", val)
1444 }
1445
1446 // AttrComponentType returns an optional attribute for the "otel.component.type"
1447 // semantic convention. It represents a name identifying the type of the
1448 // OpenTelemetry component.
1449 func (SDKMetricReaderCollectionDuration) AttrComponentType(val ComponentTypeAttr) attribute.KeyValue {
1450 return attribute.String("otel.component.type", string(val))
1451 }
1452
1453 // SDKProcessorLogProcessed is an instrument used to record metric values
1454 // conforming to the "otel.sdk.processor.log.processed" semantic conventions. It
1455 // represents the number of log records for which the processing has finished,
1456 // either successful or failed.
1457 type SDKProcessorLogProcessed struct {
1458 metric.Int64Counter
1459 }
1460
1461 var newSDKProcessorLogProcessedOpts = []metric.Int64CounterOption{
1462 metric.WithDescription("The number of log records for which the processing has finished, either successful or failed."),
1463 metric.WithUnit("{log_record}"),
1464 }
1465
1466 // NewSDKProcessorLogProcessed returns a new SDKProcessorLogProcessed instrument.
1467 func NewSDKProcessorLogProcessed(
1468 m metric.Meter,
1469 opt ...metric.Int64CounterOption,
1470 ) (SDKProcessorLogProcessed, error) {
1471 // Check if the meter is nil.
1472 if m == nil {
1473 return SDKProcessorLogProcessed{noop.Int64Counter{}}, nil
1474 }
1475
1476 if len(opt) == 0 {
1477 opt = newSDKProcessorLogProcessedOpts
1478 } else {
1479 opt = append(opt, newSDKProcessorLogProcessedOpts...)
1480 }
1481
1482 i, err := m.Int64Counter(
1483 "otel.sdk.processor.log.processed",
1484 opt...,
1485 )
1486 if err != nil {
1487 return SDKProcessorLogProcessed{noop.Int64Counter{}}, err
1488 }
1489 return SDKProcessorLogProcessed{i}, nil
1490 }
1491
1492 // Inst returns the underlying metric instrument.
1493 func (m SDKProcessorLogProcessed) Inst() metric.Int64Counter {
1494 return m.Int64Counter
1495 }
1496
1497 // Name returns the semantic convention name of the instrument.
1498 func (SDKProcessorLogProcessed) Name() string {
1499 return "otel.sdk.processor.log.processed"
1500 }
1501
1502 // Unit returns the semantic convention unit of the instrument
1503 func (SDKProcessorLogProcessed) Unit() string {
1504 return "{log_record}"
1505 }
1506
1507 // Description returns the semantic convention description of the instrument
1508 func (SDKProcessorLogProcessed) Description() string {
1509 return "The number of log records for which the processing has finished, either successful or failed."
1510 }
1511
1512 // Add adds incr to the existing count for attrs.
1513 //
1514 // All additional attrs passed are included in the recorded value.
1515 //
1516 // For successful processing, `error.type` MUST NOT be set. For failed
1517 // processing, `error.type` MUST contain the failure cause.
1518 // For the SDK Simple and Batching Log Record Processor a log record is
1519 // considered to be processed already when it has been submitted to the exporter,
1520 // not when the corresponding export call has finished.
1521 func (m SDKProcessorLogProcessed) Add(
1522 ctx context.Context,
1523 incr int64,
1524 attrs ...attribute.KeyValue,
1525 ) {
1526 if len(attrs) == 0 {
1527 m.Int64Counter.Add(ctx, incr)
1528 return
1529 }
1530
1531 o := addOptPool.Get().(*[]metric.AddOption)
1532 defer func() {
1533 *o = (*o)[:0]
1534 addOptPool.Put(o)
1535 }()
1536
1537 *o = append(
1538 *o,
1539 metric.WithAttributes(
1540 attrs...,
1541 ),
1542 )
1543
1544 m.Int64Counter.Add(ctx, incr, *o...)
1545 }
1546
1547 // AddSet adds incr to the existing count for set.
1548 //
1549 // For successful processing, `error.type` MUST NOT be set. For failed
1550 // processing, `error.type` MUST contain the failure cause.
1551 // For the SDK Simple and Batching Log Record Processor a log record is
1552 // considered to be processed already when it has been submitted to the exporter,
1553 // not when the corresponding export call has finished.
1554 func (m SDKProcessorLogProcessed) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1555 if set.Len() == 0 {
1556 m.Int64Counter.Add(ctx, incr)
1557 return
1558 }
1559
1560 o := addOptPool.Get().(*[]metric.AddOption)
1561 defer func() {
1562 *o = (*o)[:0]
1563 addOptPool.Put(o)
1564 }()
1565
1566 *o = append(*o, metric.WithAttributeSet(set))
1567 m.Int64Counter.Add(ctx, incr, *o...)
1568 }
1569
1570 // AttrErrorType returns an optional attribute for the "error.type" semantic
1571 // convention. It represents a low-cardinality description of the failure reason.
1572 // SDK Batching Log Record Processors MUST use `queue_full` for log records
1573 // dropped due to a full queue.
1574 func (SDKProcessorLogProcessed) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1575 return attribute.String("error.type", string(val))
1576 }
1577
1578 // AttrComponentName returns an optional attribute for the "otel.component.name"
1579 // semantic convention. It represents a name uniquely identifying the instance of
1580 // the OpenTelemetry component within its containing SDK instance.
1581 func (SDKProcessorLogProcessed) AttrComponentName(val string) attribute.KeyValue {
1582 return attribute.String("otel.component.name", val)
1583 }
1584
1585 // AttrComponentType returns an optional attribute for the "otel.component.type"
1586 // semantic convention. It represents a name identifying the type of the
1587 // OpenTelemetry component.
1588 func (SDKProcessorLogProcessed) AttrComponentType(val ComponentTypeAttr) attribute.KeyValue {
1589 return attribute.String("otel.component.type", string(val))
1590 }
1591
1592 // SDKProcessorLogQueueCapacity is an instrument used to record metric values
1593 // conforming to the "otel.sdk.processor.log.queue.capacity" semantic
1594 // conventions. It represents the maximum number of log records the queue of a
1595 // given instance of an SDK Log Record processor can hold.
1596 type SDKProcessorLogQueueCapacity struct {
1597 metric.Int64ObservableUpDownCounter
1598 }
1599
1600 var newSDKProcessorLogQueueCapacityOpts = []metric.Int64ObservableUpDownCounterOption{
1601 metric.WithDescription("The maximum number of log records the queue of a given instance of an SDK Log Record processor can hold."),
1602 metric.WithUnit("{log_record}"),
1603 }
1604
1605 // NewSDKProcessorLogQueueCapacity returns a new SDKProcessorLogQueueCapacity
1606 // instrument.
1607 func NewSDKProcessorLogQueueCapacity(
1608 m metric.Meter,
1609 opt ...metric.Int64ObservableUpDownCounterOption,
1610 ) (SDKProcessorLogQueueCapacity, error) {
1611 // Check if the meter is nil.
1612 if m == nil {
1613 return SDKProcessorLogQueueCapacity{noop.Int64ObservableUpDownCounter{}}, nil
1614 }
1615
1616 if len(opt) == 0 {
1617 opt = newSDKProcessorLogQueueCapacityOpts
1618 } else {
1619 opt = append(opt, newSDKProcessorLogQueueCapacityOpts...)
1620 }
1621
1622 i, err := m.Int64ObservableUpDownCounter(
1623 "otel.sdk.processor.log.queue.capacity",
1624 opt...,
1625 )
1626 if err != nil {
1627 return SDKProcessorLogQueueCapacity{noop.Int64ObservableUpDownCounter{}}, err
1628 }
1629 return SDKProcessorLogQueueCapacity{i}, nil
1630 }
1631
1632 // Inst returns the underlying metric instrument.
1633 func (m SDKProcessorLogQueueCapacity) Inst() metric.Int64ObservableUpDownCounter {
1634 return m.Int64ObservableUpDownCounter
1635 }
1636
1637 // Name returns the semantic convention name of the instrument.
1638 func (SDKProcessorLogQueueCapacity) Name() string {
1639 return "otel.sdk.processor.log.queue.capacity"
1640 }
1641
1642 // Unit returns the semantic convention unit of the instrument
1643 func (SDKProcessorLogQueueCapacity) Unit() string {
1644 return "{log_record}"
1645 }
1646
1647 // Description returns the semantic convention description of the instrument
1648 func (SDKProcessorLogQueueCapacity) Description() string {
1649 return "The maximum number of log records the queue of a given instance of an SDK Log Record processor can hold."
1650 }
1651
1652 // AttrComponentName returns an optional attribute for the "otel.component.name"
1653 // semantic convention. It represents a name uniquely identifying the instance of
1654 // the OpenTelemetry component within its containing SDK instance.
1655 func (SDKProcessorLogQueueCapacity) AttrComponentName(val string) attribute.KeyValue {
1656 return attribute.String("otel.component.name", val)
1657 }
1658
1659 // AttrComponentType returns an optional attribute for the "otel.component.type"
1660 // semantic convention. It represents a name identifying the type of the
1661 // OpenTelemetry component.
1662 func (SDKProcessorLogQueueCapacity) AttrComponentType(val ComponentTypeAttr) attribute.KeyValue {
1663 return attribute.String("otel.component.type", string(val))
1664 }
1665
1666 // SDKProcessorLogQueueSize is an instrument used to record metric values
1667 // conforming to the "otel.sdk.processor.log.queue.size" semantic conventions. It
1668 // represents the number of log records in the queue of a given instance of an
1669 // SDK log processor.
1670 type SDKProcessorLogQueueSize struct {
1671 metric.Int64ObservableUpDownCounter
1672 }
1673
1674 var newSDKProcessorLogQueueSizeOpts = []metric.Int64ObservableUpDownCounterOption{
1675 metric.WithDescription("The number of log records in the queue of a given instance of an SDK log processor."),
1676 metric.WithUnit("{log_record}"),
1677 }
1678
1679 // NewSDKProcessorLogQueueSize returns a new SDKProcessorLogQueueSize instrument.
1680 func NewSDKProcessorLogQueueSize(
1681 m metric.Meter,
1682 opt ...metric.Int64ObservableUpDownCounterOption,
1683 ) (SDKProcessorLogQueueSize, error) {
1684 // Check if the meter is nil.
1685 if m == nil {
1686 return SDKProcessorLogQueueSize{noop.Int64ObservableUpDownCounter{}}, nil
1687 }
1688
1689 if len(opt) == 0 {
1690 opt = newSDKProcessorLogQueueSizeOpts
1691 } else {
1692 opt = append(opt, newSDKProcessorLogQueueSizeOpts...)
1693 }
1694
1695 i, err := m.Int64ObservableUpDownCounter(
1696 "otel.sdk.processor.log.queue.size",
1697 opt...,
1698 )
1699 if err != nil {
1700 return SDKProcessorLogQueueSize{noop.Int64ObservableUpDownCounter{}}, err
1701 }
1702 return SDKProcessorLogQueueSize{i}, nil
1703 }
1704
1705 // Inst returns the underlying metric instrument.
1706 func (m SDKProcessorLogQueueSize) Inst() metric.Int64ObservableUpDownCounter {
1707 return m.Int64ObservableUpDownCounter
1708 }
1709
1710 // Name returns the semantic convention name of the instrument.
1711 func (SDKProcessorLogQueueSize) Name() string {
1712 return "otel.sdk.processor.log.queue.size"
1713 }
1714
1715 // Unit returns the semantic convention unit of the instrument
1716 func (SDKProcessorLogQueueSize) Unit() string {
1717 return "{log_record}"
1718 }
1719
1720 // Description returns the semantic convention description of the instrument
1721 func (SDKProcessorLogQueueSize) Description() string {
1722 return "The number of log records in the queue of a given instance of an SDK log processor."
1723 }
1724
1725 // AttrComponentName returns an optional attribute for the "otel.component.name"
1726 // semantic convention. It represents a name uniquely identifying the instance of
1727 // the OpenTelemetry component within its containing SDK instance.
1728 func (SDKProcessorLogQueueSize) AttrComponentName(val string) attribute.KeyValue {
1729 return attribute.String("otel.component.name", val)
1730 }
1731
1732 // AttrComponentType returns an optional attribute for the "otel.component.type"
1733 // semantic convention. It represents a name identifying the type of the
1734 // OpenTelemetry component.
1735 func (SDKProcessorLogQueueSize) AttrComponentType(val ComponentTypeAttr) attribute.KeyValue {
1736 return attribute.String("otel.component.type", string(val))
1737 }
1738
1739 // SDKProcessorSpanProcessed is an instrument used to record metric values
1740 // conforming to the "otel.sdk.processor.span.processed" semantic conventions. It
1741 // represents the number of spans for which the processing has finished, either
1742 // successful or failed.
1743 type SDKProcessorSpanProcessed struct {
1744 metric.Int64Counter
1745 }
1746
1747 var newSDKProcessorSpanProcessedOpts = []metric.Int64CounterOption{
1748 metric.WithDescription("The number of spans for which the processing has finished, either successful or failed."),
1749 metric.WithUnit("{span}"),
1750 }
1751
1752 // NewSDKProcessorSpanProcessed returns a new SDKProcessorSpanProcessed
1753 // instrument.
1754 func NewSDKProcessorSpanProcessed(
1755 m metric.Meter,
1756 opt ...metric.Int64CounterOption,
1757 ) (SDKProcessorSpanProcessed, error) {
1758 // Check if the meter is nil.
1759 if m == nil {
1760 return SDKProcessorSpanProcessed{noop.Int64Counter{}}, nil
1761 }
1762
1763 if len(opt) == 0 {
1764 opt = newSDKProcessorSpanProcessedOpts
1765 } else {
1766 opt = append(opt, newSDKProcessorSpanProcessedOpts...)
1767 }
1768
1769 i, err := m.Int64Counter(
1770 "otel.sdk.processor.span.processed",
1771 opt...,
1772 )
1773 if err != nil {
1774 return SDKProcessorSpanProcessed{noop.Int64Counter{}}, err
1775 }
1776 return SDKProcessorSpanProcessed{i}, nil
1777 }
1778
1779 // Inst returns the underlying metric instrument.
1780 func (m SDKProcessorSpanProcessed) Inst() metric.Int64Counter {
1781 return m.Int64Counter
1782 }
1783
1784 // Name returns the semantic convention name of the instrument.
1785 func (SDKProcessorSpanProcessed) Name() string {
1786 return "otel.sdk.processor.span.processed"
1787 }
1788
1789 // Unit returns the semantic convention unit of the instrument
1790 func (SDKProcessorSpanProcessed) Unit() string {
1791 return "{span}"
1792 }
1793
1794 // Description returns the semantic convention description of the instrument
1795 func (SDKProcessorSpanProcessed) Description() string {
1796 return "The number of spans for which the processing has finished, either successful or failed."
1797 }
1798
1799 // Add adds incr to the existing count for attrs.
1800 //
1801 // All additional attrs passed are included in the recorded value.
1802 //
1803 // For successful processing, `error.type` MUST NOT be set. For failed
1804 // processing, `error.type` MUST contain the failure cause.
1805 // For the SDK Simple and Batching Span Processor a span is considered to be
1806 // processed already when it has been submitted to the exporter, not when the
1807 // corresponding export call has finished.
1808 func (m SDKProcessorSpanProcessed) Add(
1809 ctx context.Context,
1810 incr int64,
1811 attrs ...attribute.KeyValue,
1812 ) {
1813 if len(attrs) == 0 {
1814 m.Int64Counter.Add(ctx, incr)
1815 return
1816 }
1817
1818 o := addOptPool.Get().(*[]metric.AddOption)
1819 defer func() {
1820 *o = (*o)[:0]
1821 addOptPool.Put(o)
1822 }()
1823
1824 *o = append(
1825 *o,
1826 metric.WithAttributes(
1827 attrs...,
1828 ),
1829 )
1830
1831 m.Int64Counter.Add(ctx, incr, *o...)
1832 }
1833
1834 // AddSet adds incr to the existing count for set.
1835 //
1836 // For successful processing, `error.type` MUST NOT be set. For failed
1837 // processing, `error.type` MUST contain the failure cause.
1838 // For the SDK Simple and Batching Span Processor a span is considered to be
1839 // processed already when it has been submitted to the exporter, not when the
1840 // corresponding export call has finished.
1841 func (m SDKProcessorSpanProcessed) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1842 if set.Len() == 0 {
1843 m.Int64Counter.Add(ctx, incr)
1844 return
1845 }
1846
1847 o := addOptPool.Get().(*[]metric.AddOption)
1848 defer func() {
1849 *o = (*o)[:0]
1850 addOptPool.Put(o)
1851 }()
1852
1853 *o = append(*o, metric.WithAttributeSet(set))
1854 m.Int64Counter.Add(ctx, incr, *o...)
1855 }
1856
1857 // AttrErrorType returns an optional attribute for the "error.type" semantic
1858 // convention. It represents a low-cardinality description of the failure reason.
1859 // SDK Batching Span Processors MUST use `queue_full` for spans dropped due to a
1860 // full queue.
1861 func (SDKProcessorSpanProcessed) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1862 return attribute.String("error.type", string(val))
1863 }
1864
1865 // AttrComponentName returns an optional attribute for the "otel.component.name"
1866 // semantic convention. It represents a name uniquely identifying the instance of
1867 // the OpenTelemetry component within its containing SDK instance.
1868 func (SDKProcessorSpanProcessed) AttrComponentName(val string) attribute.KeyValue {
1869 return attribute.String("otel.component.name", val)
1870 }
1871
1872 // AttrComponentType returns an optional attribute for the "otel.component.type"
1873 // semantic convention. It represents a name identifying the type of the
1874 // OpenTelemetry component.
1875 func (SDKProcessorSpanProcessed) AttrComponentType(val ComponentTypeAttr) attribute.KeyValue {
1876 return attribute.String("otel.component.type", string(val))
1877 }
1878
1879 // SDKProcessorSpanQueueCapacity is an instrument used to record metric values
1880 // conforming to the "otel.sdk.processor.span.queue.capacity" semantic
1881 // conventions. It represents the maximum number of spans the queue of a given
1882 // instance of an SDK span processor can hold.
1883 type SDKProcessorSpanQueueCapacity struct {
1884 metric.Int64ObservableUpDownCounter
1885 }
1886
1887 var newSDKProcessorSpanQueueCapacityOpts = []metric.Int64ObservableUpDownCounterOption{
1888 metric.WithDescription("The maximum number of spans the queue of a given instance of an SDK span processor can hold."),
1889 metric.WithUnit("{span}"),
1890 }
1891
1892 // NewSDKProcessorSpanQueueCapacity returns a new SDKProcessorSpanQueueCapacity
1893 // instrument.
1894 func NewSDKProcessorSpanQueueCapacity(
1895 m metric.Meter,
1896 opt ...metric.Int64ObservableUpDownCounterOption,
1897 ) (SDKProcessorSpanQueueCapacity, error) {
1898 // Check if the meter is nil.
1899 if m == nil {
1900 return SDKProcessorSpanQueueCapacity{noop.Int64ObservableUpDownCounter{}}, nil
1901 }
1902
1903 if len(opt) == 0 {
1904 opt = newSDKProcessorSpanQueueCapacityOpts
1905 } else {
1906 opt = append(opt, newSDKProcessorSpanQueueCapacityOpts...)
1907 }
1908
1909 i, err := m.Int64ObservableUpDownCounter(
1910 "otel.sdk.processor.span.queue.capacity",
1911 opt...,
1912 )
1913 if err != nil {
1914 return SDKProcessorSpanQueueCapacity{noop.Int64ObservableUpDownCounter{}}, err
1915 }
1916 return SDKProcessorSpanQueueCapacity{i}, nil
1917 }
1918
1919 // Inst returns the underlying metric instrument.
1920 func (m SDKProcessorSpanQueueCapacity) Inst() metric.Int64ObservableUpDownCounter {
1921 return m.Int64ObservableUpDownCounter
1922 }
1923
1924 // Name returns the semantic convention name of the instrument.
1925 func (SDKProcessorSpanQueueCapacity) Name() string {
1926 return "otel.sdk.processor.span.queue.capacity"
1927 }
1928
1929 // Unit returns the semantic convention unit of the instrument
1930 func (SDKProcessorSpanQueueCapacity) Unit() string {
1931 return "{span}"
1932 }
1933
1934 // Description returns the semantic convention description of the instrument
1935 func (SDKProcessorSpanQueueCapacity) Description() string {
1936 return "The maximum number of spans the queue of a given instance of an SDK span processor can hold."
1937 }
1938
1939 // AttrComponentName returns an optional attribute for the "otel.component.name"
1940 // semantic convention. It represents a name uniquely identifying the instance of
1941 // the OpenTelemetry component within its containing SDK instance.
1942 func (SDKProcessorSpanQueueCapacity) AttrComponentName(val string) attribute.KeyValue {
1943 return attribute.String("otel.component.name", val)
1944 }
1945
1946 // AttrComponentType returns an optional attribute for the "otel.component.type"
1947 // semantic convention. It represents a name identifying the type of the
1948 // OpenTelemetry component.
1949 func (SDKProcessorSpanQueueCapacity) AttrComponentType(val ComponentTypeAttr) attribute.KeyValue {
1950 return attribute.String("otel.component.type", string(val))
1951 }
1952
1953 // SDKProcessorSpanQueueSize is an instrument used to record metric values
1954 // conforming to the "otel.sdk.processor.span.queue.size" semantic conventions.
1955 // It represents the number of spans in the queue of a given instance of an SDK
1956 // span processor.
1957 type SDKProcessorSpanQueueSize struct {
1958 metric.Int64ObservableUpDownCounter
1959 }
1960
1961 var newSDKProcessorSpanQueueSizeOpts = []metric.Int64ObservableUpDownCounterOption{
1962 metric.WithDescription("The number of spans in the queue of a given instance of an SDK span processor."),
1963 metric.WithUnit("{span}"),
1964 }
1965
1966 // NewSDKProcessorSpanQueueSize returns a new SDKProcessorSpanQueueSize
1967 // instrument.
1968 func NewSDKProcessorSpanQueueSize(
1969 m metric.Meter,
1970 opt ...metric.Int64ObservableUpDownCounterOption,
1971 ) (SDKProcessorSpanQueueSize, error) {
1972 // Check if the meter is nil.
1973 if m == nil {
1974 return SDKProcessorSpanQueueSize{noop.Int64ObservableUpDownCounter{}}, nil
1975 }
1976
1977 if len(opt) == 0 {
1978 opt = newSDKProcessorSpanQueueSizeOpts
1979 } else {
1980 opt = append(opt, newSDKProcessorSpanQueueSizeOpts...)
1981 }
1982
1983 i, err := m.Int64ObservableUpDownCounter(
1984 "otel.sdk.processor.span.queue.size",
1985 opt...,
1986 )
1987 if err != nil {
1988 return SDKProcessorSpanQueueSize{noop.Int64ObservableUpDownCounter{}}, err
1989 }
1990 return SDKProcessorSpanQueueSize{i}, nil
1991 }
1992
1993 // Inst returns the underlying metric instrument.
1994 func (m SDKProcessorSpanQueueSize) Inst() metric.Int64ObservableUpDownCounter {
1995 return m.Int64ObservableUpDownCounter
1996 }
1997
1998 // Name returns the semantic convention name of the instrument.
1999 func (SDKProcessorSpanQueueSize) Name() string {
2000 return "otel.sdk.processor.span.queue.size"
2001 }
2002
2003 // Unit returns the semantic convention unit of the instrument
2004 func (SDKProcessorSpanQueueSize) Unit() string {
2005 return "{span}"
2006 }
2007
2008 // Description returns the semantic convention description of the instrument
2009 func (SDKProcessorSpanQueueSize) Description() string {
2010 return "The number of spans in the queue of a given instance of an SDK span processor."
2011 }
2012
2013 // AttrComponentName returns an optional attribute for the "otel.component.name"
2014 // semantic convention. It represents a name uniquely identifying the instance of
2015 // the OpenTelemetry component within its containing SDK instance.
2016 func (SDKProcessorSpanQueueSize) AttrComponentName(val string) attribute.KeyValue {
2017 return attribute.String("otel.component.name", val)
2018 }
2019
2020 // AttrComponentType returns an optional attribute for the "otel.component.type"
2021 // semantic convention. It represents a name identifying the type of the
2022 // OpenTelemetry component.
2023 func (SDKProcessorSpanQueueSize) AttrComponentType(val ComponentTypeAttr) attribute.KeyValue {
2024 return attribute.String("otel.component.type", string(val))
2025 }
2026
2027 // SDKSpanLive is an instrument used to record metric values conforming to the
2028 // "otel.sdk.span.live" semantic conventions. It represents the number of created
2029 // spans with `recording=true` for which the end operation has not been called
2030 // yet.
2031 type SDKSpanLive struct {
2032 metric.Int64UpDownCounter
2033 }
2034
2035 var newSDKSpanLiveOpts = []metric.Int64UpDownCounterOption{
2036 metric.WithDescription("The number of created spans with `recording=true` for which the end operation has not been called yet."),
2037 metric.WithUnit("{span}"),
2038 }
2039
2040 // NewSDKSpanLive returns a new SDKSpanLive instrument.
2041 func NewSDKSpanLive(
2042 m metric.Meter,
2043 opt ...metric.Int64UpDownCounterOption,
2044 ) (SDKSpanLive, error) {
2045 // Check if the meter is nil.
2046 if m == nil {
2047 return SDKSpanLive{noop.Int64UpDownCounter{}}, nil
2048 }
2049
2050 if len(opt) == 0 {
2051 opt = newSDKSpanLiveOpts
2052 } else {
2053 opt = append(opt, newSDKSpanLiveOpts...)
2054 }
2055
2056 i, err := m.Int64UpDownCounter(
2057 "otel.sdk.span.live",
2058 opt...,
2059 )
2060 if err != nil {
2061 return SDKSpanLive{noop.Int64UpDownCounter{}}, err
2062 }
2063 return SDKSpanLive{i}, nil
2064 }
2065
2066 // Inst returns the underlying metric instrument.
2067 func (m SDKSpanLive) Inst() metric.Int64UpDownCounter {
2068 return m.Int64UpDownCounter
2069 }
2070
2071 // Name returns the semantic convention name of the instrument.
2072 func (SDKSpanLive) Name() string {
2073 return "otel.sdk.span.live"
2074 }
2075
2076 // Unit returns the semantic convention unit of the instrument
2077 func (SDKSpanLive) Unit() string {
2078 return "{span}"
2079 }
2080
2081 // Description returns the semantic convention description of the instrument
2082 func (SDKSpanLive) Description() string {
2083 return "The number of created spans with `recording=true` for which the end operation has not been called yet."
2084 }
2085
2086 // Add adds incr to the existing count for attrs.
2087 //
2088 // All additional attrs passed are included in the recorded value.
2089 func (m SDKSpanLive) Add(
2090 ctx context.Context,
2091 incr int64,
2092 attrs ...attribute.KeyValue,
2093 ) {
2094 if len(attrs) == 0 {
2095 m.Int64UpDownCounter.Add(ctx, incr)
2096 return
2097 }
2098
2099 o := addOptPool.Get().(*[]metric.AddOption)
2100 defer func() {
2101 *o = (*o)[:0]
2102 addOptPool.Put(o)
2103 }()
2104
2105 *o = append(
2106 *o,
2107 metric.WithAttributes(
2108 attrs...,
2109 ),
2110 )
2111
2112 m.Int64UpDownCounter.Add(ctx, incr, *o...)
2113 }
2114
2115 // AddSet adds incr to the existing count for set.
2116 func (m SDKSpanLive) AddSet(ctx context.Context, incr int64, set attribute.Set) {
2117 if set.Len() == 0 {
2118 m.Int64UpDownCounter.Add(ctx, incr)
2119 return
2120 }
2121
2122 o := addOptPool.Get().(*[]metric.AddOption)
2123 defer func() {
2124 *o = (*o)[:0]
2125 addOptPool.Put(o)
2126 }()
2127
2128 *o = append(*o, metric.WithAttributeSet(set))
2129 m.Int64UpDownCounter.Add(ctx, incr, *o...)
2130 }
2131
2132 // AttrSpanSamplingResult returns an optional attribute for the
2133 // "otel.span.sampling_result" semantic convention. It represents the result
2134 // value of the sampler for this span.
2135 func (SDKSpanLive) AttrSpanSamplingResult(val SpanSamplingResultAttr) attribute.KeyValue {
2136 return attribute.String("otel.span.sampling_result", string(val))
2137 }
2138
2139 // SDKSpanStarted is an instrument used to record metric values conforming to the
2140 // "otel.sdk.span.started" semantic conventions. It represents the number of
2141 // created spans.
2142 type SDKSpanStarted struct {
2143 metric.Int64Counter
2144 }
2145
2146 var newSDKSpanStartedOpts = []metric.Int64CounterOption{
2147 metric.WithDescription("The number of created spans."),
2148 metric.WithUnit("{span}"),
2149 }
2150
2151 // NewSDKSpanStarted returns a new SDKSpanStarted instrument.
2152 func NewSDKSpanStarted(
2153 m metric.Meter,
2154 opt ...metric.Int64CounterOption,
2155 ) (SDKSpanStarted, error) {
2156 // Check if the meter is nil.
2157 if m == nil {
2158 return SDKSpanStarted{noop.Int64Counter{}}, nil
2159 }
2160
2161 if len(opt) == 0 {
2162 opt = newSDKSpanStartedOpts
2163 } else {
2164 opt = append(opt, newSDKSpanStartedOpts...)
2165 }
2166
2167 i, err := m.Int64Counter(
2168 "otel.sdk.span.started",
2169 opt...,
2170 )
2171 if err != nil {
2172 return SDKSpanStarted{noop.Int64Counter{}}, err
2173 }
2174 return SDKSpanStarted{i}, nil
2175 }
2176
2177 // Inst returns the underlying metric instrument.
2178 func (m SDKSpanStarted) Inst() metric.Int64Counter {
2179 return m.Int64Counter
2180 }
2181
2182 // Name returns the semantic convention name of the instrument.
2183 func (SDKSpanStarted) Name() string {
2184 return "otel.sdk.span.started"
2185 }
2186
2187 // Unit returns the semantic convention unit of the instrument
2188 func (SDKSpanStarted) Unit() string {
2189 return "{span}"
2190 }
2191
2192 // Description returns the semantic convention description of the instrument
2193 func (SDKSpanStarted) Description() string {
2194 return "The number of created spans."
2195 }
2196
2197 // Add adds incr to the existing count for attrs.
2198 //
2199 // All additional attrs passed are included in the recorded value.
2200 //
2201 // Implementations MUST record this metric for all spans, even for non-recording
2202 // ones.
2203 func (m SDKSpanStarted) Add(
2204 ctx context.Context,
2205 incr int64,
2206 attrs ...attribute.KeyValue,
2207 ) {
2208 if len(attrs) == 0 {
2209 m.Int64Counter.Add(ctx, incr)
2210 return
2211 }
2212
2213 o := addOptPool.Get().(*[]metric.AddOption)
2214 defer func() {
2215 *o = (*o)[:0]
2216 addOptPool.Put(o)
2217 }()
2218
2219 *o = append(
2220 *o,
2221 metric.WithAttributes(
2222 attrs...,
2223 ),
2224 )
2225
2226 m.Int64Counter.Add(ctx, incr, *o...)
2227 }
2228
2229 // AddSet adds incr to the existing count for set.
2230 //
2231 // Implementations MUST record this metric for all spans, even for non-recording
2232 // ones.
2233 func (m SDKSpanStarted) AddSet(ctx context.Context, incr int64, set attribute.Set) {
2234 if set.Len() == 0 {
2235 m.Int64Counter.Add(ctx, incr)
2236 return
2237 }
2238
2239 o := addOptPool.Get().(*[]metric.AddOption)
2240 defer func() {
2241 *o = (*o)[:0]
2242 addOptPool.Put(o)
2243 }()
2244
2245 *o = append(*o, metric.WithAttributeSet(set))
2246 m.Int64Counter.Add(ctx, incr, *o...)
2247 }
2248
2249 // AttrSpanParentOrigin returns an optional attribute for the
2250 // "otel.span.parent.origin" semantic convention. It represents the determines
2251 // whether the span has a parent span, and if so, [whether it is a remote parent]
2252 // .
2253 //
2254 // [whether it is a remote parent]: https://opentelemetry.io/docs/specs/otel/trace/api/#isremote
2255 func (SDKSpanStarted) AttrSpanParentOrigin(val SpanParentOriginAttr) attribute.KeyValue {
2256 return attribute.String("otel.span.parent.origin", string(val))
2257 }
2258
2259 // AttrSpanSamplingResult returns an optional attribute for the
2260 // "otel.span.sampling_result" semantic convention. It represents the result
2261 // value of the sampler for this span.
2262 func (SDKSpanStarted) AttrSpanSamplingResult(val SpanSamplingResultAttr) attribute.KeyValue {
2263 return attribute.String("otel.span.sampling_result", string(val))
2264 }