Debian Codegraph @

semconv/v1.37.0/dbconv/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 dbconv provides types and functionality for OpenTelemetry semantic
7 // conventions in the "db" namespace.
8 package dbconv
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 // ClientConnectionStateAttr is an attribute conforming to the
25 // db.client.connection.state semantic conventions. It represents the state of a
26 // connection in the pool.
27 type ClientConnectionStateAttr string
28
29 var (
30 // ClientConnectionStateIdle is the standardized value "idle" of
31 // ClientConnectionStateAttr.
32 ClientConnectionStateIdle ClientConnectionStateAttr = "idle"
33 // ClientConnectionStateUsed is the standardized value "used" of
34 // ClientConnectionStateAttr.
35 ClientConnectionStateUsed ClientConnectionStateAttr = "used"
36 )
37
38 // SystemNameAttr is an attribute conforming to the db.system.name semantic
39 // conventions. It represents the database management system (DBMS) product as
40 // identified by the client instrumentation.
41 type SystemNameAttr string
42
43 var (
44 // SystemNameOtherSQL is the some other SQL database. Fallback only.
45 SystemNameOtherSQL SystemNameAttr = "other_sql"
46 // SystemNameSoftwareagAdabas is the [Adabas (Adaptable Database System)].
47 //
48 // [Adabas (Adaptable Database System)]: https://documentation.softwareag.com/?pf=adabas
49 SystemNameSoftwareagAdabas SystemNameAttr = "softwareag.adabas"
50 // SystemNameActianIngres is the [Actian Ingres].
51 //
52 // [Actian Ingres]: https://www.actian.com/databases/ingres/
53 SystemNameActianIngres SystemNameAttr = "actian.ingres"
54 // SystemNameAWSDynamoDB is the [Amazon DynamoDB].
55 //
56 // [Amazon DynamoDB]: https://aws.amazon.com/pm/dynamodb/
57 SystemNameAWSDynamoDB SystemNameAttr = "aws.dynamodb"
58 // SystemNameAWSRedshift is the [Amazon Redshift].
59 //
60 // [Amazon Redshift]: https://aws.amazon.com/redshift/
61 SystemNameAWSRedshift SystemNameAttr = "aws.redshift"
62 // SystemNameAzureCosmosDB is the [Azure Cosmos DB].
63 //
64 // [Azure Cosmos DB]: https://learn.microsoft.com/azure/cosmos-db
65 SystemNameAzureCosmosDB SystemNameAttr = "azure.cosmosdb"
66 // SystemNameIntersystemsCache is the [InterSystems Caché].
67 //
68 // [InterSystems Caché]: https://www.intersystems.com/products/cache/
69 SystemNameIntersystemsCache SystemNameAttr = "intersystems.cache"
70 // SystemNameCassandra is the [Apache Cassandra].
71 //
72 // [Apache Cassandra]: https://cassandra.apache.org/
73 SystemNameCassandra SystemNameAttr = "cassandra"
74 // SystemNameClickHouse is the [ClickHouse].
75 //
76 // [ClickHouse]: https://clickhouse.com/
77 SystemNameClickHouse SystemNameAttr = "clickhouse"
78 // SystemNameCockroachDB is the [CockroachDB].
79 //
80 // [CockroachDB]: https://www.cockroachlabs.com/
81 SystemNameCockroachDB SystemNameAttr = "cockroachdb"
82 // SystemNameCouchbase is the [Couchbase].
83 //
84 // [Couchbase]: https://www.couchbase.com/
85 SystemNameCouchbase SystemNameAttr = "couchbase"
86 // SystemNameCouchDB is the [Apache CouchDB].
87 //
88 // [Apache CouchDB]: https://couchdb.apache.org/
89 SystemNameCouchDB SystemNameAttr = "couchdb"
90 // SystemNameDerby is the [Apache Derby].
91 //
92 // [Apache Derby]: https://db.apache.org/derby/
93 SystemNameDerby SystemNameAttr = "derby"
94 // SystemNameElasticsearch is the [Elasticsearch].
95 //
96 // [Elasticsearch]: https://www.elastic.co/elasticsearch
97 SystemNameElasticsearch SystemNameAttr = "elasticsearch"
98 // SystemNameFirebirdSQL is the [Firebird].
99 //
100 // [Firebird]: https://www.firebirdsql.org/
101 SystemNameFirebirdSQL SystemNameAttr = "firebirdsql"
102 // SystemNameGCPSpanner is the [Google Cloud Spanner].
103 //
104 // [Google Cloud Spanner]: https://cloud.google.com/spanner
105 SystemNameGCPSpanner SystemNameAttr = "gcp.spanner"
106 // SystemNameGeode is the [Apache Geode].
107 //
108 // [Apache Geode]: https://geode.apache.org/
109 SystemNameGeode SystemNameAttr = "geode"
110 // SystemNameH2database is the [H2 Database].
111 //
112 // [H2 Database]: https://h2database.com/
113 SystemNameH2database SystemNameAttr = "h2database"
114 // SystemNameHBase is the [Apache HBase].
115 //
116 // [Apache HBase]: https://hbase.apache.org/
117 SystemNameHBase SystemNameAttr = "hbase"
118 // SystemNameHive is the [Apache Hive].
119 //
120 // [Apache Hive]: https://hive.apache.org/
121 SystemNameHive SystemNameAttr = "hive"
122 // SystemNameHSQLDB is the [HyperSQL Database].
123 //
124 // [HyperSQL Database]: https://hsqldb.org/
125 SystemNameHSQLDB SystemNameAttr = "hsqldb"
126 // SystemNameIBMDB2 is the [IBM Db2].
127 //
128 // [IBM Db2]: https://www.ibm.com/db2
129 SystemNameIBMDB2 SystemNameAttr = "ibm.db2"
130 // SystemNameIBMInformix is the [IBM Informix].
131 //
132 // [IBM Informix]: https://www.ibm.com/products/informix
133 SystemNameIBMInformix SystemNameAttr = "ibm.informix"
134 // SystemNameIBMNetezza is the [IBM Netezza].
135 //
136 // [IBM Netezza]: https://www.ibm.com/products/netezza
137 SystemNameIBMNetezza SystemNameAttr = "ibm.netezza"
138 // SystemNameInfluxDB is the [InfluxDB].
139 //
140 // [InfluxDB]: https://www.influxdata.com/
141 SystemNameInfluxDB SystemNameAttr = "influxdb"
142 // SystemNameInstantDB is the [Instant].
143 //
144 // [Instant]: https://www.instantdb.com/
145 SystemNameInstantDB SystemNameAttr = "instantdb"
146 // SystemNameMariaDB is the [MariaDB].
147 //
148 // [MariaDB]: https://mariadb.org/
149 SystemNameMariaDB SystemNameAttr = "mariadb"
150 // SystemNameMemcached is the [Memcached].
151 //
152 // [Memcached]: https://memcached.org/
153 SystemNameMemcached SystemNameAttr = "memcached"
154 // SystemNameMongoDB is the [MongoDB].
155 //
156 // [MongoDB]: https://www.mongodb.com/
157 SystemNameMongoDB SystemNameAttr = "mongodb"
158 // SystemNameMicrosoftSQLServer is the [Microsoft SQL Server].
159 //
160 // [Microsoft SQL Server]: https://www.microsoft.com/sql-server
161 SystemNameMicrosoftSQLServer SystemNameAttr = "microsoft.sql_server"
162 // SystemNameMySQL is the [MySQL].
163 //
164 // [MySQL]: https://www.mysql.com/
165 SystemNameMySQL SystemNameAttr = "mysql"
166 // SystemNameNeo4j is the [Neo4j].
167 //
168 // [Neo4j]: https://neo4j.com/
169 SystemNameNeo4j SystemNameAttr = "neo4j"
170 // SystemNameOpenSearch is the [OpenSearch].
171 //
172 // [OpenSearch]: https://opensearch.org/
173 SystemNameOpenSearch SystemNameAttr = "opensearch"
174 // SystemNameOracleDB is the [Oracle Database].
175 //
176 // [Oracle Database]: https://www.oracle.com/database/
177 SystemNameOracleDB SystemNameAttr = "oracle.db"
178 // SystemNamePostgreSQL is the [PostgreSQL].
179 //
180 // [PostgreSQL]: https://www.postgresql.org/
181 SystemNamePostgreSQL SystemNameAttr = "postgresql"
182 // SystemNameRedis is the [Redis].
183 //
184 // [Redis]: https://redis.io/
185 SystemNameRedis SystemNameAttr = "redis"
186 // SystemNameSAPHANA is the [SAP HANA].
187 //
188 // [SAP HANA]: https://www.sap.com/products/technology-platform/hana/what-is-sap-hana.html
189 SystemNameSAPHANA SystemNameAttr = "sap.hana"
190 // SystemNameSAPMaxDB is the [SAP MaxDB].
191 //
192 // [SAP MaxDB]: https://maxdb.sap.com/
193 SystemNameSAPMaxDB SystemNameAttr = "sap.maxdb"
194 // SystemNameSQLite is the [SQLite].
195 //
196 // [SQLite]: https://www.sqlite.org/
197 SystemNameSQLite SystemNameAttr = "sqlite"
198 // SystemNameTeradata is the [Teradata].
199 //
200 // [Teradata]: https://www.teradata.com/
201 SystemNameTeradata SystemNameAttr = "teradata"
202 // SystemNameTrino is the [Trino].
203 //
204 // [Trino]: https://trino.io/
205 SystemNameTrino SystemNameAttr = "trino"
206 )
207
208 // ErrorTypeAttr is an attribute conforming to the error.type semantic
209 // conventions. It represents the describes a class of error the operation ended
210 // with.
211 type ErrorTypeAttr string
212
213 var (
214 // ErrorTypeOther is a fallback error value to be used when the instrumentation
215 // doesn't define a custom value.
216 ErrorTypeOther ErrorTypeAttr = "_OTHER"
217 )
218
219 // ClientConnectionCount is an instrument used to record metric values conforming
220 // to the "db.client.connection.count" semantic conventions. It represents the
221 // number of connections that are currently in state described by the `state`
222 // attribute.
223 type ClientConnectionCount struct {
224 metric.Int64UpDownCounter
225 }
226
227 var newClientConnectionCountOpts = []metric.Int64UpDownCounterOption{
228 metric.WithDescription("The number of connections that are currently in state described by the `state` attribute."),
229 metric.WithUnit("{connection}"),
230 }
231
232 // NewClientConnectionCount returns a new ClientConnectionCount instrument.
233 func NewClientConnectionCount(
234 m metric.Meter,
235 opt ...metric.Int64UpDownCounterOption,
236 ) (ClientConnectionCount, error) {
237 // Check if the meter is nil.
238 if m == nil {
239 return ClientConnectionCount{noop.Int64UpDownCounter{}}, nil
240 }
241
242 if len(opt) == 0 {
243 opt = newClientConnectionCountOpts
244 } else {
245 opt = append(opt, newClientConnectionCountOpts...)
246 }
247
248 i, err := m.Int64UpDownCounter(
249 "db.client.connection.count",
250 opt...,
251 )
252 if err != nil {
253 return ClientConnectionCount{noop.Int64UpDownCounter{}}, err
254 }
255 return ClientConnectionCount{i}, nil
256 }
257
258 // Inst returns the underlying metric instrument.
259 func (m ClientConnectionCount) Inst() metric.Int64UpDownCounter {
260 return m.Int64UpDownCounter
261 }
262
263 // Name returns the semantic convention name of the instrument.
264 func (ClientConnectionCount) Name() string {
265 return "db.client.connection.count"
266 }
267
268 // Unit returns the semantic convention unit of the instrument
269 func (ClientConnectionCount) Unit() string {
270 return "{connection}"
271 }
272
273 // Description returns the semantic convention description of the instrument
274 func (ClientConnectionCount) Description() string {
275 return "The number of connections that are currently in state described by the `state` attribute."
276 }
277
278 // Add adds incr to the existing count for attrs.
279 //
280 // The clientConnectionPoolName is the the name of the connection pool; unique
281 // within the instrumented application. In case the connection pool
282 // implementation doesn't provide a name, instrumentation SHOULD use a
283 // combination of parameters that would make the name unique, for example,
284 // combining attributes `server.address`, `server.port`, and `db.namespace`,
285 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
286 // generate connection pool name following different patterns SHOULD document it.
287 //
288 // The clientConnectionState is the the state of a connection in the pool
289 func (m ClientConnectionCount) Add(
290 ctx context.Context,
291 incr int64,
292 clientConnectionPoolName string,
293 clientConnectionState ClientConnectionStateAttr,
294 attrs ...attribute.KeyValue,
295 ) {
296 if len(attrs) == 0 {
297 m.Int64UpDownCounter.Add(ctx, incr)
298 return
299 }
300
301 o := addOptPool.Get().(*[]metric.AddOption)
302 defer func() {
303 *o = (*o)[:0]
304 addOptPool.Put(o)
305 }()
306
307 *o = append(
308 *o,
309 metric.WithAttributes(
310 append(
311 attrs,
312 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
313 attribute.String("db.client.connection.state", string(clientConnectionState)),
314 )...,
315 ),
316 )
317
318 m.Int64UpDownCounter.Add(ctx, incr, *o...)
319 }
320
321 // AddSet adds incr to the existing count for set.
322 func (m ClientConnectionCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
323 if set.Len() == 0 {
324 m.Int64UpDownCounter.Add(ctx, incr)
325 return
326 }
327
328 o := addOptPool.Get().(*[]metric.AddOption)
329 defer func() {
330 *o = (*o)[:0]
331 addOptPool.Put(o)
332 }()
333
334 *o = append(*o, metric.WithAttributeSet(set))
335 m.Int64UpDownCounter.Add(ctx, incr, *o...)
336 }
337
338 // ClientConnectionCreateTime is an instrument used to record metric values
339 // conforming to the "db.client.connection.create_time" semantic conventions. It
340 // represents the time it took to create a new connection.
341 type ClientConnectionCreateTime struct {
342 metric.Float64Histogram
343 }
344
345 var newClientConnectionCreateTimeOpts = []metric.Float64HistogramOption{
346 metric.WithDescription("The time it took to create a new connection."),
347 metric.WithUnit("s"),
348 }
349
350 // NewClientConnectionCreateTime returns a new ClientConnectionCreateTime
351 // instrument.
352 func NewClientConnectionCreateTime(
353 m metric.Meter,
354 opt ...metric.Float64HistogramOption,
355 ) (ClientConnectionCreateTime, error) {
356 // Check if the meter is nil.
357 if m == nil {
358 return ClientConnectionCreateTime{noop.Float64Histogram{}}, nil
359 }
360
361 if len(opt) == 0 {
362 opt = newClientConnectionCreateTimeOpts
363 } else {
364 opt = append(opt, newClientConnectionCreateTimeOpts...)
365 }
366
367 i, err := m.Float64Histogram(
368 "db.client.connection.create_time",
369 opt...,
370 )
371 if err != nil {
372 return ClientConnectionCreateTime{noop.Float64Histogram{}}, err
373 }
374 return ClientConnectionCreateTime{i}, nil
375 }
376
377 // Inst returns the underlying metric instrument.
378 func (m ClientConnectionCreateTime) Inst() metric.Float64Histogram {
379 return m.Float64Histogram
380 }
381
382 // Name returns the semantic convention name of the instrument.
383 func (ClientConnectionCreateTime) Name() string {
384 return "db.client.connection.create_time"
385 }
386
387 // Unit returns the semantic convention unit of the instrument
388 func (ClientConnectionCreateTime) Unit() string {
389 return "s"
390 }
391
392 // Description returns the semantic convention description of the instrument
393 func (ClientConnectionCreateTime) Description() string {
394 return "The time it took to create a new connection."
395 }
396
397 // Record records val to the current distribution for attrs.
398 //
399 // The clientConnectionPoolName is the the name of the connection pool; unique
400 // within the instrumented application. In case the connection pool
401 // implementation doesn't provide a name, instrumentation SHOULD use a
402 // combination of parameters that would make the name unique, for example,
403 // combining attributes `server.address`, `server.port`, and `db.namespace`,
404 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
405 // generate connection pool name following different patterns SHOULD document it.
406 func (m ClientConnectionCreateTime) Record(
407 ctx context.Context,
408 val float64,
409 clientConnectionPoolName string,
410 attrs ...attribute.KeyValue,
411 ) {
412 if len(attrs) == 0 {
413 m.Float64Histogram.Record(ctx, val)
414 return
415 }
416
417 o := recOptPool.Get().(*[]metric.RecordOption)
418 defer func() {
419 *o = (*o)[:0]
420 recOptPool.Put(o)
421 }()
422
423 *o = append(
424 *o,
425 metric.WithAttributes(
426 append(
427 attrs,
428 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
429 )...,
430 ),
431 )
432
433 m.Float64Histogram.Record(ctx, val, *o...)
434 }
435
436 // RecordSet records val to the current distribution for set.
437 func (m ClientConnectionCreateTime) RecordSet(ctx context.Context, val float64, set attribute.Set) {
438 if set.Len() == 0 {
439 m.Float64Histogram.Record(ctx, val)
440 return
441 }
442
443 o := recOptPool.Get().(*[]metric.RecordOption)
444 defer func() {
445 *o = (*o)[:0]
446 recOptPool.Put(o)
447 }()
448
449 *o = append(*o, metric.WithAttributeSet(set))
450 m.Float64Histogram.Record(ctx, val, *o...)
451 }
452
453 // ClientConnectionIdleMax is an instrument used to record metric values
454 // conforming to the "db.client.connection.idle.max" semantic conventions. It
455 // represents the maximum number of idle open connections allowed.
456 type ClientConnectionIdleMax struct {
457 metric.Int64UpDownCounter
458 }
459
460 var newClientConnectionIdleMaxOpts = []metric.Int64UpDownCounterOption{
461 metric.WithDescription("The maximum number of idle open connections allowed."),
462 metric.WithUnit("{connection}"),
463 }
464
465 // NewClientConnectionIdleMax returns a new ClientConnectionIdleMax instrument.
466 func NewClientConnectionIdleMax(
467 m metric.Meter,
468 opt ...metric.Int64UpDownCounterOption,
469 ) (ClientConnectionIdleMax, error) {
470 // Check if the meter is nil.
471 if m == nil {
472 return ClientConnectionIdleMax{noop.Int64UpDownCounter{}}, nil
473 }
474
475 if len(opt) == 0 {
476 opt = newClientConnectionIdleMaxOpts
477 } else {
478 opt = append(opt, newClientConnectionIdleMaxOpts...)
479 }
480
481 i, err := m.Int64UpDownCounter(
482 "db.client.connection.idle.max",
483 opt...,
484 )
485 if err != nil {
486 return ClientConnectionIdleMax{noop.Int64UpDownCounter{}}, err
487 }
488 return ClientConnectionIdleMax{i}, nil
489 }
490
491 // Inst returns the underlying metric instrument.
492 func (m ClientConnectionIdleMax) Inst() metric.Int64UpDownCounter {
493 return m.Int64UpDownCounter
494 }
495
496 // Name returns the semantic convention name of the instrument.
497 func (ClientConnectionIdleMax) Name() string {
498 return "db.client.connection.idle.max"
499 }
500
501 // Unit returns the semantic convention unit of the instrument
502 func (ClientConnectionIdleMax) Unit() string {
503 return "{connection}"
504 }
505
506 // Description returns the semantic convention description of the instrument
507 func (ClientConnectionIdleMax) Description() string {
508 return "The maximum number of idle open connections allowed."
509 }
510
511 // Add adds incr to the existing count for attrs.
512 //
513 // The clientConnectionPoolName is the the name of the connection pool; unique
514 // within the instrumented application. In case the connection pool
515 // implementation doesn't provide a name, instrumentation SHOULD use a
516 // combination of parameters that would make the name unique, for example,
517 // combining attributes `server.address`, `server.port`, and `db.namespace`,
518 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
519 // generate connection pool name following different patterns SHOULD document it.
520 func (m ClientConnectionIdleMax) Add(
521 ctx context.Context,
522 incr int64,
523 clientConnectionPoolName string,
524 attrs ...attribute.KeyValue,
525 ) {
526 if len(attrs) == 0 {
527 m.Int64UpDownCounter.Add(ctx, incr)
528 return
529 }
530
531 o := addOptPool.Get().(*[]metric.AddOption)
532 defer func() {
533 *o = (*o)[:0]
534 addOptPool.Put(o)
535 }()
536
537 *o = append(
538 *o,
539 metric.WithAttributes(
540 append(
541 attrs,
542 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
543 )...,
544 ),
545 )
546
547 m.Int64UpDownCounter.Add(ctx, incr, *o...)
548 }
549
550 // AddSet adds incr to the existing count for set.
551 func (m ClientConnectionIdleMax) AddSet(ctx context.Context, incr int64, set attribute.Set) {
552 if set.Len() == 0 {
553 m.Int64UpDownCounter.Add(ctx, incr)
554 return
555 }
556
557 o := addOptPool.Get().(*[]metric.AddOption)
558 defer func() {
559 *o = (*o)[:0]
560 addOptPool.Put(o)
561 }()
562
563 *o = append(*o, metric.WithAttributeSet(set))
564 m.Int64UpDownCounter.Add(ctx, incr, *o...)
565 }
566
567 // ClientConnectionIdleMin is an instrument used to record metric values
568 // conforming to the "db.client.connection.idle.min" semantic conventions. It
569 // represents the minimum number of idle open connections allowed.
570 type ClientConnectionIdleMin struct {
571 metric.Int64UpDownCounter
572 }
573
574 var newClientConnectionIdleMinOpts = []metric.Int64UpDownCounterOption{
575 metric.WithDescription("The minimum number of idle open connections allowed."),
576 metric.WithUnit("{connection}"),
577 }
578
579 // NewClientConnectionIdleMin returns a new ClientConnectionIdleMin instrument.
580 func NewClientConnectionIdleMin(
581 m metric.Meter,
582 opt ...metric.Int64UpDownCounterOption,
583 ) (ClientConnectionIdleMin, error) {
584 // Check if the meter is nil.
585 if m == nil {
586 return ClientConnectionIdleMin{noop.Int64UpDownCounter{}}, nil
587 }
588
589 if len(opt) == 0 {
590 opt = newClientConnectionIdleMinOpts
591 } else {
592 opt = append(opt, newClientConnectionIdleMinOpts...)
593 }
594
595 i, err := m.Int64UpDownCounter(
596 "db.client.connection.idle.min",
597 opt...,
598 )
599 if err != nil {
600 return ClientConnectionIdleMin{noop.Int64UpDownCounter{}}, err
601 }
602 return ClientConnectionIdleMin{i}, nil
603 }
604
605 // Inst returns the underlying metric instrument.
606 func (m ClientConnectionIdleMin) Inst() metric.Int64UpDownCounter {
607 return m.Int64UpDownCounter
608 }
609
610 // Name returns the semantic convention name of the instrument.
611 func (ClientConnectionIdleMin) Name() string {
612 return "db.client.connection.idle.min"
613 }
614
615 // Unit returns the semantic convention unit of the instrument
616 func (ClientConnectionIdleMin) Unit() string {
617 return "{connection}"
618 }
619
620 // Description returns the semantic convention description of the instrument
621 func (ClientConnectionIdleMin) Description() string {
622 return "The minimum number of idle open connections allowed."
623 }
624
625 // Add adds incr to the existing count for attrs.
626 //
627 // The clientConnectionPoolName is the the name of the connection pool; unique
628 // within the instrumented application. In case the connection pool
629 // implementation doesn't provide a name, instrumentation SHOULD use a
630 // combination of parameters that would make the name unique, for example,
631 // combining attributes `server.address`, `server.port`, and `db.namespace`,
632 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
633 // generate connection pool name following different patterns SHOULD document it.
634 func (m ClientConnectionIdleMin) Add(
635 ctx context.Context,
636 incr int64,
637 clientConnectionPoolName string,
638 attrs ...attribute.KeyValue,
639 ) {
640 if len(attrs) == 0 {
641 m.Int64UpDownCounter.Add(ctx, incr)
642 return
643 }
644
645 o := addOptPool.Get().(*[]metric.AddOption)
646 defer func() {
647 *o = (*o)[:0]
648 addOptPool.Put(o)
649 }()
650
651 *o = append(
652 *o,
653 metric.WithAttributes(
654 append(
655 attrs,
656 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
657 )...,
658 ),
659 )
660
661 m.Int64UpDownCounter.Add(ctx, incr, *o...)
662 }
663
664 // AddSet adds incr to the existing count for set.
665 func (m ClientConnectionIdleMin) AddSet(ctx context.Context, incr int64, set attribute.Set) {
666 if set.Len() == 0 {
667 m.Int64UpDownCounter.Add(ctx, incr)
668 return
669 }
670
671 o := addOptPool.Get().(*[]metric.AddOption)
672 defer func() {
673 *o = (*o)[:0]
674 addOptPool.Put(o)
675 }()
676
677 *o = append(*o, metric.WithAttributeSet(set))
678 m.Int64UpDownCounter.Add(ctx, incr, *o...)
679 }
680
681 // ClientConnectionMax is an instrument used to record metric values conforming
682 // to the "db.client.connection.max" semantic conventions. It represents the
683 // maximum number of open connections allowed.
684 type ClientConnectionMax struct {
685 metric.Int64UpDownCounter
686 }
687
688 var newClientConnectionMaxOpts = []metric.Int64UpDownCounterOption{
689 metric.WithDescription("The maximum number of open connections allowed."),
690 metric.WithUnit("{connection}"),
691 }
692
693 // NewClientConnectionMax returns a new ClientConnectionMax instrument.
694 func NewClientConnectionMax(
695 m metric.Meter,
696 opt ...metric.Int64UpDownCounterOption,
697 ) (ClientConnectionMax, error) {
698 // Check if the meter is nil.
699 if m == nil {
700 return ClientConnectionMax{noop.Int64UpDownCounter{}}, nil
701 }
702
703 if len(opt) == 0 {
704 opt = newClientConnectionMaxOpts
705 } else {
706 opt = append(opt, newClientConnectionMaxOpts...)
707 }
708
709 i, err := m.Int64UpDownCounter(
710 "db.client.connection.max",
711 opt...,
712 )
713 if err != nil {
714 return ClientConnectionMax{noop.Int64UpDownCounter{}}, err
715 }
716 return ClientConnectionMax{i}, nil
717 }
718
719 // Inst returns the underlying metric instrument.
720 func (m ClientConnectionMax) Inst() metric.Int64UpDownCounter {
721 return m.Int64UpDownCounter
722 }
723
724 // Name returns the semantic convention name of the instrument.
725 func (ClientConnectionMax) Name() string {
726 return "db.client.connection.max"
727 }
728
729 // Unit returns the semantic convention unit of the instrument
730 func (ClientConnectionMax) Unit() string {
731 return "{connection}"
732 }
733
734 // Description returns the semantic convention description of the instrument
735 func (ClientConnectionMax) Description() string {
736 return "The maximum number of open connections allowed."
737 }
738
739 // Add adds incr to the existing count for attrs.
740 //
741 // The clientConnectionPoolName is the the name of the connection pool; unique
742 // within the instrumented application. In case the connection pool
743 // implementation doesn't provide a name, instrumentation SHOULD use a
744 // combination of parameters that would make the name unique, for example,
745 // combining attributes `server.address`, `server.port`, and `db.namespace`,
746 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
747 // generate connection pool name following different patterns SHOULD document it.
748 func (m ClientConnectionMax) Add(
749 ctx context.Context,
750 incr int64,
751 clientConnectionPoolName string,
752 attrs ...attribute.KeyValue,
753 ) {
754 if len(attrs) == 0 {
755 m.Int64UpDownCounter.Add(ctx, incr)
756 return
757 }
758
759 o := addOptPool.Get().(*[]metric.AddOption)
760 defer func() {
761 *o = (*o)[:0]
762 addOptPool.Put(o)
763 }()
764
765 *o = append(
766 *o,
767 metric.WithAttributes(
768 append(
769 attrs,
770 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
771 )...,
772 ),
773 )
774
775 m.Int64UpDownCounter.Add(ctx, incr, *o...)
776 }
777
778 // AddSet adds incr to the existing count for set.
779 func (m ClientConnectionMax) AddSet(ctx context.Context, incr int64, set attribute.Set) {
780 if set.Len() == 0 {
781 m.Int64UpDownCounter.Add(ctx, incr)
782 return
783 }
784
785 o := addOptPool.Get().(*[]metric.AddOption)
786 defer func() {
787 *o = (*o)[:0]
788 addOptPool.Put(o)
789 }()
790
791 *o = append(*o, metric.WithAttributeSet(set))
792 m.Int64UpDownCounter.Add(ctx, incr, *o...)
793 }
794
795 // ClientConnectionPendingRequests is an instrument used to record metric values
796 // conforming to the "db.client.connection.pending_requests" semantic
797 // conventions. It represents the number of current pending requests for an open
798 // connection.
799 type ClientConnectionPendingRequests struct {
800 metric.Int64UpDownCounter
801 }
802
803 var newClientConnectionPendingRequestsOpts = []metric.Int64UpDownCounterOption{
804 metric.WithDescription("The number of current pending requests for an open connection."),
805 metric.WithUnit("{request}"),
806 }
807
808 // NewClientConnectionPendingRequests returns a new
809 // ClientConnectionPendingRequests instrument.
810 func NewClientConnectionPendingRequests(
811 m metric.Meter,
812 opt ...metric.Int64UpDownCounterOption,
813 ) (ClientConnectionPendingRequests, error) {
814 // Check if the meter is nil.
815 if m == nil {
816 return ClientConnectionPendingRequests{noop.Int64UpDownCounter{}}, nil
817 }
818
819 if len(opt) == 0 {
820 opt = newClientConnectionPendingRequestsOpts
821 } else {
822 opt = append(opt, newClientConnectionPendingRequestsOpts...)
823 }
824
825 i, err := m.Int64UpDownCounter(
826 "db.client.connection.pending_requests",
827 opt...,
828 )
829 if err != nil {
830 return ClientConnectionPendingRequests{noop.Int64UpDownCounter{}}, err
831 }
832 return ClientConnectionPendingRequests{i}, nil
833 }
834
835 // Inst returns the underlying metric instrument.
836 func (m ClientConnectionPendingRequests) Inst() metric.Int64UpDownCounter {
837 return m.Int64UpDownCounter
838 }
839
840 // Name returns the semantic convention name of the instrument.
841 func (ClientConnectionPendingRequests) Name() string {
842 return "db.client.connection.pending_requests"
843 }
844
845 // Unit returns the semantic convention unit of the instrument
846 func (ClientConnectionPendingRequests) Unit() string {
847 return "{request}"
848 }
849
850 // Description returns the semantic convention description of the instrument
851 func (ClientConnectionPendingRequests) Description() string {
852 return "The number of current pending requests for an open connection."
853 }
854
855 // Add adds incr to the existing count for attrs.
856 //
857 // The clientConnectionPoolName is the the name of the connection pool; unique
858 // within the instrumented application. In case the connection pool
859 // implementation doesn't provide a name, instrumentation SHOULD use a
860 // combination of parameters that would make the name unique, for example,
861 // combining attributes `server.address`, `server.port`, and `db.namespace`,
862 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
863 // generate connection pool name following different patterns SHOULD document it.
864 func (m ClientConnectionPendingRequests) Add(
865 ctx context.Context,
866 incr int64,
867 clientConnectionPoolName string,
868 attrs ...attribute.KeyValue,
869 ) {
870 if len(attrs) == 0 {
871 m.Int64UpDownCounter.Add(ctx, incr)
872 return
873 }
874
875 o := addOptPool.Get().(*[]metric.AddOption)
876 defer func() {
877 *o = (*o)[:0]
878 addOptPool.Put(o)
879 }()
880
881 *o = append(
882 *o,
883 metric.WithAttributes(
884 append(
885 attrs,
886 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
887 )...,
888 ),
889 )
890
891 m.Int64UpDownCounter.Add(ctx, incr, *o...)
892 }
893
894 // AddSet adds incr to the existing count for set.
895 func (m ClientConnectionPendingRequests) AddSet(ctx context.Context, incr int64, set attribute.Set) {
896 if set.Len() == 0 {
897 m.Int64UpDownCounter.Add(ctx, incr)
898 return
899 }
900
901 o := addOptPool.Get().(*[]metric.AddOption)
902 defer func() {
903 *o = (*o)[:0]
904 addOptPool.Put(o)
905 }()
906
907 *o = append(*o, metric.WithAttributeSet(set))
908 m.Int64UpDownCounter.Add(ctx, incr, *o...)
909 }
910
911 // ClientConnectionTimeouts is an instrument used to record metric values
912 // conforming to the "db.client.connection.timeouts" semantic conventions. It
913 // represents the number of connection timeouts that have occurred trying to
914 // obtain a connection from the pool.
915 type ClientConnectionTimeouts struct {
916 metric.Int64Counter
917 }
918
919 var newClientConnectionTimeoutsOpts = []metric.Int64CounterOption{
920 metric.WithDescription("The number of connection timeouts that have occurred trying to obtain a connection from the pool."),
921 metric.WithUnit("{timeout}"),
922 }
923
924 // NewClientConnectionTimeouts returns a new ClientConnectionTimeouts instrument.
925 func NewClientConnectionTimeouts(
926 m metric.Meter,
927 opt ...metric.Int64CounterOption,
928 ) (ClientConnectionTimeouts, error) {
929 // Check if the meter is nil.
930 if m == nil {
931 return ClientConnectionTimeouts{noop.Int64Counter{}}, nil
932 }
933
934 if len(opt) == 0 {
935 opt = newClientConnectionTimeoutsOpts
936 } else {
937 opt = append(opt, newClientConnectionTimeoutsOpts...)
938 }
939
940 i, err := m.Int64Counter(
941 "db.client.connection.timeouts",
942 opt...,
943 )
944 if err != nil {
945 return ClientConnectionTimeouts{noop.Int64Counter{}}, err
946 }
947 return ClientConnectionTimeouts{i}, nil
948 }
949
950 // Inst returns the underlying metric instrument.
951 func (m ClientConnectionTimeouts) Inst() metric.Int64Counter {
952 return m.Int64Counter
953 }
954
955 // Name returns the semantic convention name of the instrument.
956 func (ClientConnectionTimeouts) Name() string {
957 return "db.client.connection.timeouts"
958 }
959
960 // Unit returns the semantic convention unit of the instrument
961 func (ClientConnectionTimeouts) Unit() string {
962 return "{timeout}"
963 }
964
965 // Description returns the semantic convention description of the instrument
966 func (ClientConnectionTimeouts) Description() string {
967 return "The number of connection timeouts that have occurred trying to obtain a connection from the pool."
968 }
969
970 // Add adds incr to the existing count for attrs.
971 //
972 // The clientConnectionPoolName is the the name of the connection pool; unique
973 // within the instrumented application. In case the connection pool
974 // implementation doesn't provide a name, instrumentation SHOULD use a
975 // combination of parameters that would make the name unique, for example,
976 // combining attributes `server.address`, `server.port`, and `db.namespace`,
977 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
978 // generate connection pool name following different patterns SHOULD document it.
979 func (m ClientConnectionTimeouts) Add(
980 ctx context.Context,
981 incr int64,
982 clientConnectionPoolName string,
983 attrs ...attribute.KeyValue,
984 ) {
985 if len(attrs) == 0 {
986 m.Int64Counter.Add(ctx, incr)
987 return
988 }
989
990 o := addOptPool.Get().(*[]metric.AddOption)
991 defer func() {
992 *o = (*o)[:0]
993 addOptPool.Put(o)
994 }()
995
996 *o = append(
997 *o,
998 metric.WithAttributes(
999 append(
1000 attrs,
1001 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
1002 )...,
1003 ),
1004 )
1005
1006 m.Int64Counter.Add(ctx, incr, *o...)
1007 }
1008
1009 // AddSet adds incr to the existing count for set.
1010 func (m ClientConnectionTimeouts) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1011 if set.Len() == 0 {
1012 m.Int64Counter.Add(ctx, incr)
1013 return
1014 }
1015
1016 o := addOptPool.Get().(*[]metric.AddOption)
1017 defer func() {
1018 *o = (*o)[:0]
1019 addOptPool.Put(o)
1020 }()
1021
1022 *o = append(*o, metric.WithAttributeSet(set))
1023 m.Int64Counter.Add(ctx, incr, *o...)
1024 }
1025
1026 // ClientConnectionUseTime is an instrument used to record metric values
1027 // conforming to the "db.client.connection.use_time" semantic conventions. It
1028 // represents the time between borrowing a connection and returning it to the
1029 // pool.
1030 type ClientConnectionUseTime struct {
1031 metric.Float64Histogram
1032 }
1033
1034 var newClientConnectionUseTimeOpts = []metric.Float64HistogramOption{
1035 metric.WithDescription("The time between borrowing a connection and returning it to the pool."),
1036 metric.WithUnit("s"),
1037 }
1038
1039 // NewClientConnectionUseTime returns a new ClientConnectionUseTime instrument.
1040 func NewClientConnectionUseTime(
1041 m metric.Meter,
1042 opt ...metric.Float64HistogramOption,
1043 ) (ClientConnectionUseTime, error) {
1044 // Check if the meter is nil.
1045 if m == nil {
1046 return ClientConnectionUseTime{noop.Float64Histogram{}}, nil
1047 }
1048
1049 if len(opt) == 0 {
1050 opt = newClientConnectionUseTimeOpts
1051 } else {
1052 opt = append(opt, newClientConnectionUseTimeOpts...)
1053 }
1054
1055 i, err := m.Float64Histogram(
1056 "db.client.connection.use_time",
1057 opt...,
1058 )
1059 if err != nil {
1060 return ClientConnectionUseTime{noop.Float64Histogram{}}, err
1061 }
1062 return ClientConnectionUseTime{i}, nil
1063 }
1064
1065 // Inst returns the underlying metric instrument.
1066 func (m ClientConnectionUseTime) Inst() metric.Float64Histogram {
1067 return m.Float64Histogram
1068 }
1069
1070 // Name returns the semantic convention name of the instrument.
1071 func (ClientConnectionUseTime) Name() string {
1072 return "db.client.connection.use_time"
1073 }
1074
1075 // Unit returns the semantic convention unit of the instrument
1076 func (ClientConnectionUseTime) Unit() string {
1077 return "s"
1078 }
1079
1080 // Description returns the semantic convention description of the instrument
1081 func (ClientConnectionUseTime) Description() string {
1082 return "The time between borrowing a connection and returning it to the pool."
1083 }
1084
1085 // Record records val to the current distribution for attrs.
1086 //
1087 // The clientConnectionPoolName is the the name of the connection pool; unique
1088 // within the instrumented application. In case the connection pool
1089 // implementation doesn't provide a name, instrumentation SHOULD use a
1090 // combination of parameters that would make the name unique, for example,
1091 // combining attributes `server.address`, `server.port`, and `db.namespace`,
1092 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
1093 // generate connection pool name following different patterns SHOULD document it.
1094 func (m ClientConnectionUseTime) Record(
1095 ctx context.Context,
1096 val float64,
1097 clientConnectionPoolName string,
1098 attrs ...attribute.KeyValue,
1099 ) {
1100 if len(attrs) == 0 {
1101 m.Float64Histogram.Record(ctx, val)
1102 return
1103 }
1104
1105 o := recOptPool.Get().(*[]metric.RecordOption)
1106 defer func() {
1107 *o = (*o)[:0]
1108 recOptPool.Put(o)
1109 }()
1110
1111 *o = append(
1112 *o,
1113 metric.WithAttributes(
1114 append(
1115 attrs,
1116 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
1117 )...,
1118 ),
1119 )
1120
1121 m.Float64Histogram.Record(ctx, val, *o...)
1122 }
1123
1124 // RecordSet records val to the current distribution for set.
1125 func (m ClientConnectionUseTime) RecordSet(ctx context.Context, val float64, set attribute.Set) {
1126 if set.Len() == 0 {
1127 m.Float64Histogram.Record(ctx, val)
1128 return
1129 }
1130
1131 o := recOptPool.Get().(*[]metric.RecordOption)
1132 defer func() {
1133 *o = (*o)[:0]
1134 recOptPool.Put(o)
1135 }()
1136
1137 *o = append(*o, metric.WithAttributeSet(set))
1138 m.Float64Histogram.Record(ctx, val, *o...)
1139 }
1140
1141 // ClientConnectionWaitTime is an instrument used to record metric values
1142 // conforming to the "db.client.connection.wait_time" semantic conventions. It
1143 // represents the time it took to obtain an open connection from the pool.
1144 type ClientConnectionWaitTime struct {
1145 metric.Float64Histogram
1146 }
1147
1148 var newClientConnectionWaitTimeOpts = []metric.Float64HistogramOption{
1149 metric.WithDescription("The time it took to obtain an open connection from the pool."),
1150 metric.WithUnit("s"),
1151 }
1152
1153 // NewClientConnectionWaitTime returns a new ClientConnectionWaitTime instrument.
1154 func NewClientConnectionWaitTime(
1155 m metric.Meter,
1156 opt ...metric.Float64HistogramOption,
1157 ) (ClientConnectionWaitTime, error) {
1158 // Check if the meter is nil.
1159 if m == nil {
1160 return ClientConnectionWaitTime{noop.Float64Histogram{}}, nil
1161 }
1162
1163 if len(opt) == 0 {
1164 opt = newClientConnectionWaitTimeOpts
1165 } else {
1166 opt = append(opt, newClientConnectionWaitTimeOpts...)
1167 }
1168
1169 i, err := m.Float64Histogram(
1170 "db.client.connection.wait_time",
1171 opt...,
1172 )
1173 if err != nil {
1174 return ClientConnectionWaitTime{noop.Float64Histogram{}}, err
1175 }
1176 return ClientConnectionWaitTime{i}, nil
1177 }
1178
1179 // Inst returns the underlying metric instrument.
1180 func (m ClientConnectionWaitTime) Inst() metric.Float64Histogram {
1181 return m.Float64Histogram
1182 }
1183
1184 // Name returns the semantic convention name of the instrument.
1185 func (ClientConnectionWaitTime) Name() string {
1186 return "db.client.connection.wait_time"
1187 }
1188
1189 // Unit returns the semantic convention unit of the instrument
1190 func (ClientConnectionWaitTime) Unit() string {
1191 return "s"
1192 }
1193
1194 // Description returns the semantic convention description of the instrument
1195 func (ClientConnectionWaitTime) Description() string {
1196 return "The time it took to obtain an open connection from the pool."
1197 }
1198
1199 // Record records val to the current distribution for attrs.
1200 //
1201 // The clientConnectionPoolName is the the name of the connection pool; unique
1202 // within the instrumented application. In case the connection pool
1203 // implementation doesn't provide a name, instrumentation SHOULD use a
1204 // combination of parameters that would make the name unique, for example,
1205 // combining attributes `server.address`, `server.port`, and `db.namespace`,
1206 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
1207 // generate connection pool name following different patterns SHOULD document it.
1208 func (m ClientConnectionWaitTime) Record(
1209 ctx context.Context,
1210 val float64,
1211 clientConnectionPoolName string,
1212 attrs ...attribute.KeyValue,
1213 ) {
1214 if len(attrs) == 0 {
1215 m.Float64Histogram.Record(ctx, val)
1216 return
1217 }
1218
1219 o := recOptPool.Get().(*[]metric.RecordOption)
1220 defer func() {
1221 *o = (*o)[:0]
1222 recOptPool.Put(o)
1223 }()
1224
1225 *o = append(
1226 *o,
1227 metric.WithAttributes(
1228 append(
1229 attrs,
1230 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
1231 )...,
1232 ),
1233 )
1234
1235 m.Float64Histogram.Record(ctx, val, *o...)
1236 }
1237
1238 // RecordSet records val to the current distribution for set.
1239 func (m ClientConnectionWaitTime) RecordSet(ctx context.Context, val float64, set attribute.Set) {
1240 if set.Len() == 0 {
1241 m.Float64Histogram.Record(ctx, val)
1242 return
1243 }
1244
1245 o := recOptPool.Get().(*[]metric.RecordOption)
1246 defer func() {
1247 *o = (*o)[:0]
1248 recOptPool.Put(o)
1249 }()
1250
1251 *o = append(*o, metric.WithAttributeSet(set))
1252 m.Float64Histogram.Record(ctx, val, *o...)
1253 }
1254
1255 // ClientOperationDuration is an instrument used to record metric values
1256 // conforming to the "db.client.operation.duration" semantic conventions. It
1257 // represents the duration of database client operations.
1258 type ClientOperationDuration struct {
1259 metric.Float64Histogram
1260 }
1261
1262 var newClientOperationDurationOpts = []metric.Float64HistogramOption{
1263 metric.WithDescription("Duration of database client operations."),
1264 metric.WithUnit("s"),
1265 }
1266
1267 // NewClientOperationDuration returns a new ClientOperationDuration instrument.
1268 func NewClientOperationDuration(
1269 m metric.Meter,
1270 opt ...metric.Float64HistogramOption,
1271 ) (ClientOperationDuration, error) {
1272 // Check if the meter is nil.
1273 if m == nil {
1274 return ClientOperationDuration{noop.Float64Histogram{}}, nil
1275 }
1276
1277 if len(opt) == 0 {
1278 opt = newClientOperationDurationOpts
1279 } else {
1280 opt = append(opt, newClientOperationDurationOpts...)
1281 }
1282
1283 i, err := m.Float64Histogram(
1284 "db.client.operation.duration",
1285 opt...,
1286 )
1287 if err != nil {
1288 return ClientOperationDuration{noop.Float64Histogram{}}, err
1289 }
1290 return ClientOperationDuration{i}, nil
1291 }
1292
1293 // Inst returns the underlying metric instrument.
1294 func (m ClientOperationDuration) Inst() metric.Float64Histogram {
1295 return m.Float64Histogram
1296 }
1297
1298 // Name returns the semantic convention name of the instrument.
1299 func (ClientOperationDuration) Name() string {
1300 return "db.client.operation.duration"
1301 }
1302
1303 // Unit returns the semantic convention unit of the instrument
1304 func (ClientOperationDuration) Unit() string {
1305 return "s"
1306 }
1307
1308 // Description returns the semantic convention description of the instrument
1309 func (ClientOperationDuration) Description() string {
1310 return "Duration of database client operations."
1311 }
1312
1313 // Record records val to the current distribution for attrs.
1314 //
1315 // The systemName is the the database management system (DBMS) product as
1316 // identified by the client instrumentation.
1317 //
1318 // All additional attrs passed are included in the recorded value.
1319 //
1320 // Batch operations SHOULD be recorded as a single operation.
1321 func (m ClientOperationDuration) Record(
1322 ctx context.Context,
1323 val float64,
1324 systemName SystemNameAttr,
1325 attrs ...attribute.KeyValue,
1326 ) {
1327 if len(attrs) == 0 {
1328 m.Float64Histogram.Record(ctx, val)
1329 return
1330 }
1331
1332 o := recOptPool.Get().(*[]metric.RecordOption)
1333 defer func() {
1334 *o = (*o)[:0]
1335 recOptPool.Put(o)
1336 }()
1337
1338 *o = append(
1339 *o,
1340 metric.WithAttributes(
1341 append(
1342 attrs,
1343 attribute.String("db.system.name", string(systemName)),
1344 )...,
1345 ),
1346 )
1347
1348 m.Float64Histogram.Record(ctx, val, *o...)
1349 }
1350
1351 // RecordSet records val to the current distribution for set.
1352 //
1353 // Batch operations SHOULD be recorded as a single operation.
1354 func (m ClientOperationDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
1355 if set.Len() == 0 {
1356 m.Float64Histogram.Record(ctx, val)
1357 return
1358 }
1359
1360 o := recOptPool.Get().(*[]metric.RecordOption)
1361 defer func() {
1362 *o = (*o)[:0]
1363 recOptPool.Put(o)
1364 }()
1365
1366 *o = append(*o, metric.WithAttributeSet(set))
1367 m.Float64Histogram.Record(ctx, val, *o...)
1368 }
1369
1370 // AttrCollectionName returns an optional attribute for the "db.collection.name"
1371 // semantic convention. It represents the name of a collection (table, container)
1372 // within the database.
1373 func (ClientOperationDuration) AttrCollectionName(val string) attribute.KeyValue {
1374 return attribute.String("db.collection.name", val)
1375 }
1376
1377 // AttrNamespace returns an optional attribute for the "db.namespace" semantic
1378 // convention. It represents the name of the database, fully qualified within the
1379 // server address and port.
1380 func (ClientOperationDuration) AttrNamespace(val string) attribute.KeyValue {
1381 return attribute.String("db.namespace", val)
1382 }
1383
1384 // AttrOperationName returns an optional attribute for the "db.operation.name"
1385 // semantic convention. It represents the name of the operation or command being
1386 // executed.
1387 func (ClientOperationDuration) AttrOperationName(val string) attribute.KeyValue {
1388 return attribute.String("db.operation.name", val)
1389 }
1390
1391 // AttrResponseStatusCode returns an optional attribute for the
1392 // "db.response.status_code" semantic convention. It represents the database
1393 // response status code.
1394 func (ClientOperationDuration) AttrResponseStatusCode(val string) attribute.KeyValue {
1395 return attribute.String("db.response.status_code", val)
1396 }
1397
1398 // AttrErrorType returns an optional attribute for the "error.type" semantic
1399 // convention. It represents the describes a class of error the operation ended
1400 // with.
1401 func (ClientOperationDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1402 return attribute.String("error.type", string(val))
1403 }
1404
1405 // AttrServerPort returns an optional attribute for the "server.port" semantic
1406 // convention. It represents the server port number.
1407 func (ClientOperationDuration) AttrServerPort(val int) attribute.KeyValue {
1408 return attribute.Int("server.port", val)
1409 }
1410
1411 // AttrQuerySummary returns an optional attribute for the "db.query.summary"
1412 // semantic convention. It represents the low cardinality summary of a database
1413 // query.
1414 func (ClientOperationDuration) AttrQuerySummary(val string) attribute.KeyValue {
1415 return attribute.String("db.query.summary", val)
1416 }
1417
1418 // AttrStoredProcedureName returns an optional attribute for the
1419 // "db.stored_procedure.name" semantic convention. It represents the name of a
1420 // stored procedure within the database.
1421 func (ClientOperationDuration) AttrStoredProcedureName(val string) attribute.KeyValue {
1422 return attribute.String("db.stored_procedure.name", val)
1423 }
1424
1425 // AttrNetworkPeerAddress returns an optional attribute for the
1426 // "network.peer.address" semantic convention. It represents the peer address of
1427 // the database node where the operation was performed.
1428 func (ClientOperationDuration) AttrNetworkPeerAddress(val string) attribute.KeyValue {
1429 return attribute.String("network.peer.address", val)
1430 }
1431
1432 // AttrNetworkPeerPort returns an optional attribute for the "network.peer.port"
1433 // semantic convention. It represents the peer port number of the network
1434 // connection.
1435 func (ClientOperationDuration) AttrNetworkPeerPort(val int) attribute.KeyValue {
1436 return attribute.Int("network.peer.port", val)
1437 }
1438
1439 // AttrServerAddress returns an optional attribute for the "server.address"
1440 // semantic convention. It represents the name of the database host.
1441 func (ClientOperationDuration) AttrServerAddress(val string) attribute.KeyValue {
1442 return attribute.String("server.address", val)
1443 }
1444
1445 // AttrQueryText returns an optional attribute for the "db.query.text" semantic
1446 // convention. It represents the database query being executed.
1447 func (ClientOperationDuration) AttrQueryText(val string) attribute.KeyValue {
1448 return attribute.String("db.query.text", val)
1449 }
1450
1451 // ClientResponseReturnedRows is an instrument used to record metric values
1452 // conforming to the "db.client.response.returned_rows" semantic conventions. It
1453 // represents the actual number of records returned by the database operation.
1454 type ClientResponseReturnedRows struct {
1455 metric.Int64Histogram
1456 }
1457
1458 var newClientResponseReturnedRowsOpts = []metric.Int64HistogramOption{
1459 metric.WithDescription("The actual number of records returned by the database operation."),
1460 metric.WithUnit("{row}"),
1461 }
1462
1463 // NewClientResponseReturnedRows returns a new ClientResponseReturnedRows
1464 // instrument.
1465 func NewClientResponseReturnedRows(
1466 m metric.Meter,
1467 opt ...metric.Int64HistogramOption,
1468 ) (ClientResponseReturnedRows, error) {
1469 // Check if the meter is nil.
1470 if m == nil {
1471 return ClientResponseReturnedRows{noop.Int64Histogram{}}, nil
1472 }
1473
1474 if len(opt) == 0 {
1475 opt = newClientResponseReturnedRowsOpts
1476 } else {
1477 opt = append(opt, newClientResponseReturnedRowsOpts...)
1478 }
1479
1480 i, err := m.Int64Histogram(
1481 "db.client.response.returned_rows",
1482 opt...,
1483 )
1484 if err != nil {
1485 return ClientResponseReturnedRows{noop.Int64Histogram{}}, err
1486 }
1487 return ClientResponseReturnedRows{i}, nil
1488 }
1489
1490 // Inst returns the underlying metric instrument.
1491 func (m ClientResponseReturnedRows) Inst() metric.Int64Histogram {
1492 return m.Int64Histogram
1493 }
1494
1495 // Name returns the semantic convention name of the instrument.
1496 func (ClientResponseReturnedRows) Name() string {
1497 return "db.client.response.returned_rows"
1498 }
1499
1500 // Unit returns the semantic convention unit of the instrument
1501 func (ClientResponseReturnedRows) Unit() string {
1502 return "{row}"
1503 }
1504
1505 // Description returns the semantic convention description of the instrument
1506 func (ClientResponseReturnedRows) Description() string {
1507 return "The actual number of records returned by the database operation."
1508 }
1509
1510 // Record records val to the current distribution for attrs.
1511 //
1512 // The systemName is the the database management system (DBMS) product as
1513 // identified by the client instrumentation.
1514 //
1515 // All additional attrs passed are included in the recorded value.
1516 func (m ClientResponseReturnedRows) Record(
1517 ctx context.Context,
1518 val int64,
1519 systemName SystemNameAttr,
1520 attrs ...attribute.KeyValue,
1521 ) {
1522 if len(attrs) == 0 {
1523 m.Int64Histogram.Record(ctx, val)
1524 return
1525 }
1526
1527 o := recOptPool.Get().(*[]metric.RecordOption)
1528 defer func() {
1529 *o = (*o)[:0]
1530 recOptPool.Put(o)
1531 }()
1532
1533 *o = append(
1534 *o,
1535 metric.WithAttributes(
1536 append(
1537 attrs,
1538 attribute.String("db.system.name", string(systemName)),
1539 )...,
1540 ),
1541 )
1542
1543 m.Int64Histogram.Record(ctx, val, *o...)
1544 }
1545
1546 // RecordSet records val to the current distribution for set.
1547 func (m ClientResponseReturnedRows) RecordSet(ctx context.Context, val int64, set attribute.Set) {
1548 if set.Len() == 0 {
1549 m.Int64Histogram.Record(ctx, val)
1550 return
1551 }
1552
1553 o := recOptPool.Get().(*[]metric.RecordOption)
1554 defer func() {
1555 *o = (*o)[:0]
1556 recOptPool.Put(o)
1557 }()
1558
1559 *o = append(*o, metric.WithAttributeSet(set))
1560 m.Int64Histogram.Record(ctx, val, *o...)
1561 }
1562
1563 // AttrCollectionName returns an optional attribute for the "db.collection.name"
1564 // semantic convention. It represents the name of a collection (table, container)
1565 // within the database.
1566 func (ClientResponseReturnedRows) AttrCollectionName(val string) attribute.KeyValue {
1567 return attribute.String("db.collection.name", val)
1568 }
1569
1570 // AttrNamespace returns an optional attribute for the "db.namespace" semantic
1571 // convention. It represents the name of the database, fully qualified within the
1572 // server address and port.
1573 func (ClientResponseReturnedRows) AttrNamespace(val string) attribute.KeyValue {
1574 return attribute.String("db.namespace", val)
1575 }
1576
1577 // AttrOperationName returns an optional attribute for the "db.operation.name"
1578 // semantic convention. It represents the name of the operation or command being
1579 // executed.
1580 func (ClientResponseReturnedRows) AttrOperationName(val string) attribute.KeyValue {
1581 return attribute.String("db.operation.name", val)
1582 }
1583
1584 // AttrResponseStatusCode returns an optional attribute for the
1585 // "db.response.status_code" semantic convention. It represents the database
1586 // response status code.
1587 func (ClientResponseReturnedRows) AttrResponseStatusCode(val string) attribute.KeyValue {
1588 return attribute.String("db.response.status_code", val)
1589 }
1590
1591 // AttrErrorType returns an optional attribute for the "error.type" semantic
1592 // convention. It represents the describes a class of error the operation ended
1593 // with.
1594 func (ClientResponseReturnedRows) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1595 return attribute.String("error.type", string(val))
1596 }
1597
1598 // AttrServerPort returns an optional attribute for the "server.port" semantic
1599 // convention. It represents the server port number.
1600 func (ClientResponseReturnedRows) AttrServerPort(val int) attribute.KeyValue {
1601 return attribute.Int("server.port", val)
1602 }
1603
1604 // AttrQuerySummary returns an optional attribute for the "db.query.summary"
1605 // semantic convention. It represents the low cardinality summary of a database
1606 // query.
1607 func (ClientResponseReturnedRows) AttrQuerySummary(val string) attribute.KeyValue {
1608 return attribute.String("db.query.summary", val)
1609 }
1610
1611 // AttrNetworkPeerAddress returns an optional attribute for the
1612 // "network.peer.address" semantic convention. It represents the peer address of
1613 // the database node where the operation was performed.
1614 func (ClientResponseReturnedRows) AttrNetworkPeerAddress(val string) attribute.KeyValue {
1615 return attribute.String("network.peer.address", val)
1616 }
1617
1618 // AttrNetworkPeerPort returns an optional attribute for the "network.peer.port"
1619 // semantic convention. It represents the peer port number of the network
1620 // connection.
1621 func (ClientResponseReturnedRows) AttrNetworkPeerPort(val int) attribute.KeyValue {
1622 return attribute.Int("network.peer.port", val)
1623 }
1624
1625 // AttrServerAddress returns an optional attribute for the "server.address"
1626 // semantic convention. It represents the name of the database host.
1627 func (ClientResponseReturnedRows) AttrServerAddress(val string) attribute.KeyValue {
1628 return attribute.String("server.address", val)
1629 }
1630
1631 // AttrQueryText returns an optional attribute for the "db.query.text" semantic
1632 // convention. It represents the database query being executed.
1633 func (ClientResponseReturnedRows) AttrQueryText(val string) attribute.KeyValue {
1634 return attribute.String("db.query.text", val)
1635 }