Debian Codegraph @

semconv/v1.36.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 // NewClientConnectionCount returns a new ClientConnectionCount instrument.
228 func NewClientConnectionCount(
229 m metric.Meter,
230 opt ...metric.Int64UpDownCounterOption,
231 ) (ClientConnectionCount, error) {
232 // Check if the meter is nil.
233 if m == nil {
234 return ClientConnectionCount{noop.Int64UpDownCounter{}}, nil
235 }
236
237 i, err := m.Int64UpDownCounter(
238 "db.client.connection.count",
239 append([]metric.Int64UpDownCounterOption{
240 metric.WithDescription("The number of connections that are currently in state described by the `state` attribute"),
241 metric.WithUnit("{connection}"),
242 }, opt...)...,
243 )
244 if err != nil {
245 return ClientConnectionCount{noop.Int64UpDownCounter{}}, err
246 }
247 return ClientConnectionCount{i}, nil
248 }
249
250 // Inst returns the underlying metric instrument.
251 func (m ClientConnectionCount) Inst() metric.Int64UpDownCounter {
252 return m.Int64UpDownCounter
253 }
254
255 // Name returns the semantic convention name of the instrument.
256 func (ClientConnectionCount) Name() string {
257 return "db.client.connection.count"
258 }
259
260 // Unit returns the semantic convention unit of the instrument
261 func (ClientConnectionCount) Unit() string {
262 return "{connection}"
263 }
264
265 // Description returns the semantic convention description of the instrument
266 func (ClientConnectionCount) Description() string {
267 return "The number of connections that are currently in state described by the `state` attribute"
268 }
269
270 // Add adds incr to the existing count for attrs.
271 //
272 // The clientConnectionPoolName is the the name of the connection pool; unique
273 // within the instrumented application. In case the connection pool
274 // implementation doesn't provide a name, instrumentation SHOULD use a
275 // combination of parameters that would make the name unique, for example,
276 // combining attributes `server.address`, `server.port`, and `db.namespace`,
277 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
278 // generate connection pool name following different patterns SHOULD document it.
279 //
280 // The clientConnectionState is the the state of a connection in the pool
281 func (m ClientConnectionCount) Add(
282 ctx context.Context,
283 incr int64,
284 clientConnectionPoolName string,
285 clientConnectionState ClientConnectionStateAttr,
286 attrs ...attribute.KeyValue,
287 ) {
288 if len(attrs) == 0 {
289 m.Int64UpDownCounter.Add(ctx, incr)
290 return
291 }
292
293 o := addOptPool.Get().(*[]metric.AddOption)
294 defer func() {
295 *o = (*o)[:0]
296 addOptPool.Put(o)
297 }()
298
299 *o = append(
300 *o,
301 metric.WithAttributes(
302 append(
303 attrs,
304 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
305 attribute.String("db.client.connection.state", string(clientConnectionState)),
306 )...,
307 ),
308 )
309
310 m.Int64UpDownCounter.Add(ctx, incr, *o...)
311 }
312
313 // AddSet adds incr to the existing count for set.
314 func (m ClientConnectionCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
315 if set.Len() == 0 {
316 m.Int64UpDownCounter.Add(ctx, incr)
317 return
318 }
319
320 o := addOptPool.Get().(*[]metric.AddOption)
321 defer func() {
322 *o = (*o)[:0]
323 addOptPool.Put(o)
324 }()
325
326 *o = append(*o, metric.WithAttributeSet(set))
327 m.Int64UpDownCounter.Add(ctx, incr, *o...)
328 }
329
330 // ClientConnectionCreateTime is an instrument used to record metric values
331 // conforming to the "db.client.connection.create_time" semantic conventions. It
332 // represents the time it took to create a new connection.
333 type ClientConnectionCreateTime struct {
334 metric.Float64Histogram
335 }
336
337 // NewClientConnectionCreateTime returns a new ClientConnectionCreateTime
338 // instrument.
339 func NewClientConnectionCreateTime(
340 m metric.Meter,
341 opt ...metric.Float64HistogramOption,
342 ) (ClientConnectionCreateTime, error) {
343 // Check if the meter is nil.
344 if m == nil {
345 return ClientConnectionCreateTime{noop.Float64Histogram{}}, nil
346 }
347
348 i, err := m.Float64Histogram(
349 "db.client.connection.create_time",
350 append([]metric.Float64HistogramOption{
351 metric.WithDescription("The time it took to create a new connection"),
352 metric.WithUnit("s"),
353 }, opt...)...,
354 )
355 if err != nil {
356 return ClientConnectionCreateTime{noop.Float64Histogram{}}, err
357 }
358 return ClientConnectionCreateTime{i}, nil
359 }
360
361 // Inst returns the underlying metric instrument.
362 func (m ClientConnectionCreateTime) Inst() metric.Float64Histogram {
363 return m.Float64Histogram
364 }
365
366 // Name returns the semantic convention name of the instrument.
367 func (ClientConnectionCreateTime) Name() string {
368 return "db.client.connection.create_time"
369 }
370
371 // Unit returns the semantic convention unit of the instrument
372 func (ClientConnectionCreateTime) Unit() string {
373 return "s"
374 }
375
376 // Description returns the semantic convention description of the instrument
377 func (ClientConnectionCreateTime) Description() string {
378 return "The time it took to create a new connection"
379 }
380
381 // Record records val to the current distribution for attrs.
382 //
383 // The clientConnectionPoolName is the the name of the connection pool; unique
384 // within the instrumented application. In case the connection pool
385 // implementation doesn't provide a name, instrumentation SHOULD use a
386 // combination of parameters that would make the name unique, for example,
387 // combining attributes `server.address`, `server.port`, and `db.namespace`,
388 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
389 // generate connection pool name following different patterns SHOULD document it.
390 func (m ClientConnectionCreateTime) Record(
391 ctx context.Context,
392 val float64,
393 clientConnectionPoolName string,
394 attrs ...attribute.KeyValue,
395 ) {
396 if len(attrs) == 0 {
397 m.Float64Histogram.Record(ctx, val)
398 return
399 }
400
401 o := recOptPool.Get().(*[]metric.RecordOption)
402 defer func() {
403 *o = (*o)[:0]
404 recOptPool.Put(o)
405 }()
406
407 *o = append(
408 *o,
409 metric.WithAttributes(
410 append(
411 attrs,
412 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
413 )...,
414 ),
415 )
416
417 m.Float64Histogram.Record(ctx, val, *o...)
418 }
419
420 // RecordSet records val to the current distribution for set.
421 func (m ClientConnectionCreateTime) RecordSet(ctx context.Context, val float64, set attribute.Set) {
422 if set.Len() == 0 {
423 m.Float64Histogram.Record(ctx, val)
424 return
425 }
426
427 o := recOptPool.Get().(*[]metric.RecordOption)
428 defer func() {
429 *o = (*o)[:0]
430 recOptPool.Put(o)
431 }()
432
433 *o = append(*o, metric.WithAttributeSet(set))
434 m.Float64Histogram.Record(ctx, val, *o...)
435 }
436
437 // ClientConnectionIdleMax is an instrument used to record metric values
438 // conforming to the "db.client.connection.idle.max" semantic conventions. It
439 // represents the maximum number of idle open connections allowed.
440 type ClientConnectionIdleMax struct {
441 metric.Int64UpDownCounter
442 }
443
444 // NewClientConnectionIdleMax returns a new ClientConnectionIdleMax instrument.
445 func NewClientConnectionIdleMax(
446 m metric.Meter,
447 opt ...metric.Int64UpDownCounterOption,
448 ) (ClientConnectionIdleMax, error) {
449 // Check if the meter is nil.
450 if m == nil {
451 return ClientConnectionIdleMax{noop.Int64UpDownCounter{}}, nil
452 }
453
454 i, err := m.Int64UpDownCounter(
455 "db.client.connection.idle.max",
456 append([]metric.Int64UpDownCounterOption{
457 metric.WithDescription("The maximum number of idle open connections allowed"),
458 metric.WithUnit("{connection}"),
459 }, opt...)...,
460 )
461 if err != nil {
462 return ClientConnectionIdleMax{noop.Int64UpDownCounter{}}, err
463 }
464 return ClientConnectionIdleMax{i}, nil
465 }
466
467 // Inst returns the underlying metric instrument.
468 func (m ClientConnectionIdleMax) Inst() metric.Int64UpDownCounter {
469 return m.Int64UpDownCounter
470 }
471
472 // Name returns the semantic convention name of the instrument.
473 func (ClientConnectionIdleMax) Name() string {
474 return "db.client.connection.idle.max"
475 }
476
477 // Unit returns the semantic convention unit of the instrument
478 func (ClientConnectionIdleMax) Unit() string {
479 return "{connection}"
480 }
481
482 // Description returns the semantic convention description of the instrument
483 func (ClientConnectionIdleMax) Description() string {
484 return "The maximum number of idle open connections allowed"
485 }
486
487 // Add adds incr to the existing count for attrs.
488 //
489 // The clientConnectionPoolName is the the name of the connection pool; unique
490 // within the instrumented application. In case the connection pool
491 // implementation doesn't provide a name, instrumentation SHOULD use a
492 // combination of parameters that would make the name unique, for example,
493 // combining attributes `server.address`, `server.port`, and `db.namespace`,
494 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
495 // generate connection pool name following different patterns SHOULD document it.
496 func (m ClientConnectionIdleMax) Add(
497 ctx context.Context,
498 incr int64,
499 clientConnectionPoolName string,
500 attrs ...attribute.KeyValue,
501 ) {
502 if len(attrs) == 0 {
503 m.Int64UpDownCounter.Add(ctx, incr)
504 return
505 }
506
507 o := addOptPool.Get().(*[]metric.AddOption)
508 defer func() {
509 *o = (*o)[:0]
510 addOptPool.Put(o)
511 }()
512
513 *o = append(
514 *o,
515 metric.WithAttributes(
516 append(
517 attrs,
518 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
519 )...,
520 ),
521 )
522
523 m.Int64UpDownCounter.Add(ctx, incr, *o...)
524 }
525
526 // AddSet adds incr to the existing count for set.
527 func (m ClientConnectionIdleMax) AddSet(ctx context.Context, incr int64, set attribute.Set) {
528 if set.Len() == 0 {
529 m.Int64UpDownCounter.Add(ctx, incr)
530 return
531 }
532
533 o := addOptPool.Get().(*[]metric.AddOption)
534 defer func() {
535 *o = (*o)[:0]
536 addOptPool.Put(o)
537 }()
538
539 *o = append(*o, metric.WithAttributeSet(set))
540 m.Int64UpDownCounter.Add(ctx, incr, *o...)
541 }
542
543 // ClientConnectionIdleMin is an instrument used to record metric values
544 // conforming to the "db.client.connection.idle.min" semantic conventions. It
545 // represents the minimum number of idle open connections allowed.
546 type ClientConnectionIdleMin struct {
547 metric.Int64UpDownCounter
548 }
549
550 // NewClientConnectionIdleMin returns a new ClientConnectionIdleMin instrument.
551 func NewClientConnectionIdleMin(
552 m metric.Meter,
553 opt ...metric.Int64UpDownCounterOption,
554 ) (ClientConnectionIdleMin, error) {
555 // Check if the meter is nil.
556 if m == nil {
557 return ClientConnectionIdleMin{noop.Int64UpDownCounter{}}, nil
558 }
559
560 i, err := m.Int64UpDownCounter(
561 "db.client.connection.idle.min",
562 append([]metric.Int64UpDownCounterOption{
563 metric.WithDescription("The minimum number of idle open connections allowed"),
564 metric.WithUnit("{connection}"),
565 }, opt...)...,
566 )
567 if err != nil {
568 return ClientConnectionIdleMin{noop.Int64UpDownCounter{}}, err
569 }
570 return ClientConnectionIdleMin{i}, nil
571 }
572
573 // Inst returns the underlying metric instrument.
574 func (m ClientConnectionIdleMin) Inst() metric.Int64UpDownCounter {
575 return m.Int64UpDownCounter
576 }
577
578 // Name returns the semantic convention name of the instrument.
579 func (ClientConnectionIdleMin) Name() string {
580 return "db.client.connection.idle.min"
581 }
582
583 // Unit returns the semantic convention unit of the instrument
584 func (ClientConnectionIdleMin) Unit() string {
585 return "{connection}"
586 }
587
588 // Description returns the semantic convention description of the instrument
589 func (ClientConnectionIdleMin) Description() string {
590 return "The minimum number of idle open connections allowed"
591 }
592
593 // Add adds incr to the existing count for attrs.
594 //
595 // The clientConnectionPoolName is the the name of the connection pool; unique
596 // within the instrumented application. In case the connection pool
597 // implementation doesn't provide a name, instrumentation SHOULD use a
598 // combination of parameters that would make the name unique, for example,
599 // combining attributes `server.address`, `server.port`, and `db.namespace`,
600 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
601 // generate connection pool name following different patterns SHOULD document it.
602 func (m ClientConnectionIdleMin) Add(
603 ctx context.Context,
604 incr int64,
605 clientConnectionPoolName string,
606 attrs ...attribute.KeyValue,
607 ) {
608 if len(attrs) == 0 {
609 m.Int64UpDownCounter.Add(ctx, incr)
610 return
611 }
612
613 o := addOptPool.Get().(*[]metric.AddOption)
614 defer func() {
615 *o = (*o)[:0]
616 addOptPool.Put(o)
617 }()
618
619 *o = append(
620 *o,
621 metric.WithAttributes(
622 append(
623 attrs,
624 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
625 )...,
626 ),
627 )
628
629 m.Int64UpDownCounter.Add(ctx, incr, *o...)
630 }
631
632 // AddSet adds incr to the existing count for set.
633 func (m ClientConnectionIdleMin) AddSet(ctx context.Context, incr int64, set attribute.Set) {
634 if set.Len() == 0 {
635 m.Int64UpDownCounter.Add(ctx, incr)
636 return
637 }
638
639 o := addOptPool.Get().(*[]metric.AddOption)
640 defer func() {
641 *o = (*o)[:0]
642 addOptPool.Put(o)
643 }()
644
645 *o = append(*o, metric.WithAttributeSet(set))
646 m.Int64UpDownCounter.Add(ctx, incr, *o...)
647 }
648
649 // ClientConnectionMax is an instrument used to record metric values conforming
650 // to the "db.client.connection.max" semantic conventions. It represents the
651 // maximum number of open connections allowed.
652 type ClientConnectionMax struct {
653 metric.Int64UpDownCounter
654 }
655
656 // NewClientConnectionMax returns a new ClientConnectionMax instrument.
657 func NewClientConnectionMax(
658 m metric.Meter,
659 opt ...metric.Int64UpDownCounterOption,
660 ) (ClientConnectionMax, error) {
661 // Check if the meter is nil.
662 if m == nil {
663 return ClientConnectionMax{noop.Int64UpDownCounter{}}, nil
664 }
665
666 i, err := m.Int64UpDownCounter(
667 "db.client.connection.max",
668 append([]metric.Int64UpDownCounterOption{
669 metric.WithDescription("The maximum number of open connections allowed"),
670 metric.WithUnit("{connection}"),
671 }, opt...)...,
672 )
673 if err != nil {
674 return ClientConnectionMax{noop.Int64UpDownCounter{}}, err
675 }
676 return ClientConnectionMax{i}, nil
677 }
678
679 // Inst returns the underlying metric instrument.
680 func (m ClientConnectionMax) Inst() metric.Int64UpDownCounter {
681 return m.Int64UpDownCounter
682 }
683
684 // Name returns the semantic convention name of the instrument.
685 func (ClientConnectionMax) Name() string {
686 return "db.client.connection.max"
687 }
688
689 // Unit returns the semantic convention unit of the instrument
690 func (ClientConnectionMax) Unit() string {
691 return "{connection}"
692 }
693
694 // Description returns the semantic convention description of the instrument
695 func (ClientConnectionMax) Description() string {
696 return "The maximum number of open connections allowed"
697 }
698
699 // Add adds incr to the existing count for attrs.
700 //
701 // The clientConnectionPoolName is the the name of the connection pool; unique
702 // within the instrumented application. In case the connection pool
703 // implementation doesn't provide a name, instrumentation SHOULD use a
704 // combination of parameters that would make the name unique, for example,
705 // combining attributes `server.address`, `server.port`, and `db.namespace`,
706 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
707 // generate connection pool name following different patterns SHOULD document it.
708 func (m ClientConnectionMax) Add(
709 ctx context.Context,
710 incr int64,
711 clientConnectionPoolName string,
712 attrs ...attribute.KeyValue,
713 ) {
714 if len(attrs) == 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(
726 *o,
727 metric.WithAttributes(
728 append(
729 attrs,
730 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
731 )...,
732 ),
733 )
734
735 m.Int64UpDownCounter.Add(ctx, incr, *o...)
736 }
737
738 // AddSet adds incr to the existing count for set.
739 func (m ClientConnectionMax) AddSet(ctx context.Context, incr int64, set attribute.Set) {
740 if set.Len() == 0 {
741 m.Int64UpDownCounter.Add(ctx, incr)
742 return
743 }
744
745 o := addOptPool.Get().(*[]metric.AddOption)
746 defer func() {
747 *o = (*o)[:0]
748 addOptPool.Put(o)
749 }()
750
751 *o = append(*o, metric.WithAttributeSet(set))
752 m.Int64UpDownCounter.Add(ctx, incr, *o...)
753 }
754
755 // ClientConnectionPendingRequests is an instrument used to record metric values
756 // conforming to the "db.client.connection.pending_requests" semantic
757 // conventions. It represents the number of current pending requests for an open
758 // connection.
759 type ClientConnectionPendingRequests struct {
760 metric.Int64UpDownCounter
761 }
762
763 // NewClientConnectionPendingRequests returns a new
764 // ClientConnectionPendingRequests instrument.
765 func NewClientConnectionPendingRequests(
766 m metric.Meter,
767 opt ...metric.Int64UpDownCounterOption,
768 ) (ClientConnectionPendingRequests, error) {
769 // Check if the meter is nil.
770 if m == nil {
771 return ClientConnectionPendingRequests{noop.Int64UpDownCounter{}}, nil
772 }
773
774 i, err := m.Int64UpDownCounter(
775 "db.client.connection.pending_requests",
776 append([]metric.Int64UpDownCounterOption{
777 metric.WithDescription("The number of current pending requests for an open connection"),
778 metric.WithUnit("{request}"),
779 }, opt...)...,
780 )
781 if err != nil {
782 return ClientConnectionPendingRequests{noop.Int64UpDownCounter{}}, err
783 }
784 return ClientConnectionPendingRequests{i}, nil
785 }
786
787 // Inst returns the underlying metric instrument.
788 func (m ClientConnectionPendingRequests) Inst() metric.Int64UpDownCounter {
789 return m.Int64UpDownCounter
790 }
791
792 // Name returns the semantic convention name of the instrument.
793 func (ClientConnectionPendingRequests) Name() string {
794 return "db.client.connection.pending_requests"
795 }
796
797 // Unit returns the semantic convention unit of the instrument
798 func (ClientConnectionPendingRequests) Unit() string {
799 return "{request}"
800 }
801
802 // Description returns the semantic convention description of the instrument
803 func (ClientConnectionPendingRequests) Description() string {
804 return "The number of current pending requests for an open connection"
805 }
806
807 // Add adds incr to the existing count for attrs.
808 //
809 // The clientConnectionPoolName is the the name of the connection pool; unique
810 // within the instrumented application. In case the connection pool
811 // implementation doesn't provide a name, instrumentation SHOULD use a
812 // combination of parameters that would make the name unique, for example,
813 // combining attributes `server.address`, `server.port`, and `db.namespace`,
814 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
815 // generate connection pool name following different patterns SHOULD document it.
816 func (m ClientConnectionPendingRequests) Add(
817 ctx context.Context,
818 incr int64,
819 clientConnectionPoolName string,
820 attrs ...attribute.KeyValue,
821 ) {
822 if len(attrs) == 0 {
823 m.Int64UpDownCounter.Add(ctx, incr)
824 return
825 }
826
827 o := addOptPool.Get().(*[]metric.AddOption)
828 defer func() {
829 *o = (*o)[:0]
830 addOptPool.Put(o)
831 }()
832
833 *o = append(
834 *o,
835 metric.WithAttributes(
836 append(
837 attrs,
838 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
839 )...,
840 ),
841 )
842
843 m.Int64UpDownCounter.Add(ctx, incr, *o...)
844 }
845
846 // AddSet adds incr to the existing count for set.
847 func (m ClientConnectionPendingRequests) AddSet(ctx context.Context, incr int64, set attribute.Set) {
848 if set.Len() == 0 {
849 m.Int64UpDownCounter.Add(ctx, incr)
850 return
851 }
852
853 o := addOptPool.Get().(*[]metric.AddOption)
854 defer func() {
855 *o = (*o)[:0]
856 addOptPool.Put(o)
857 }()
858
859 *o = append(*o, metric.WithAttributeSet(set))
860 m.Int64UpDownCounter.Add(ctx, incr, *o...)
861 }
862
863 // ClientConnectionTimeouts is an instrument used to record metric values
864 // conforming to the "db.client.connection.timeouts" semantic conventions. It
865 // represents the number of connection timeouts that have occurred trying to
866 // obtain a connection from the pool.
867 type ClientConnectionTimeouts struct {
868 metric.Int64Counter
869 }
870
871 // NewClientConnectionTimeouts returns a new ClientConnectionTimeouts instrument.
872 func NewClientConnectionTimeouts(
873 m metric.Meter,
874 opt ...metric.Int64CounterOption,
875 ) (ClientConnectionTimeouts, error) {
876 // Check if the meter is nil.
877 if m == nil {
878 return ClientConnectionTimeouts{noop.Int64Counter{}}, nil
879 }
880
881 i, err := m.Int64Counter(
882 "db.client.connection.timeouts",
883 append([]metric.Int64CounterOption{
884 metric.WithDescription("The number of connection timeouts that have occurred trying to obtain a connection from the pool"),
885 metric.WithUnit("{timeout}"),
886 }, opt...)...,
887 )
888 if err != nil {
889 return ClientConnectionTimeouts{noop.Int64Counter{}}, err
890 }
891 return ClientConnectionTimeouts{i}, nil
892 }
893
894 // Inst returns the underlying metric instrument.
895 func (m ClientConnectionTimeouts) Inst() metric.Int64Counter {
896 return m.Int64Counter
897 }
898
899 // Name returns the semantic convention name of the instrument.
900 func (ClientConnectionTimeouts) Name() string {
901 return "db.client.connection.timeouts"
902 }
903
904 // Unit returns the semantic convention unit of the instrument
905 func (ClientConnectionTimeouts) Unit() string {
906 return "{timeout}"
907 }
908
909 // Description returns the semantic convention description of the instrument
910 func (ClientConnectionTimeouts) Description() string {
911 return "The number of connection timeouts that have occurred trying to obtain a connection from the pool"
912 }
913
914 // Add adds incr to the existing count for attrs.
915 //
916 // The clientConnectionPoolName is the the name of the connection pool; unique
917 // within the instrumented application. In case the connection pool
918 // implementation doesn't provide a name, instrumentation SHOULD use a
919 // combination of parameters that would make the name unique, for example,
920 // combining attributes `server.address`, `server.port`, and `db.namespace`,
921 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
922 // generate connection pool name following different patterns SHOULD document it.
923 func (m ClientConnectionTimeouts) Add(
924 ctx context.Context,
925 incr int64,
926 clientConnectionPoolName string,
927 attrs ...attribute.KeyValue,
928 ) {
929 if len(attrs) == 0 {
930 m.Int64Counter.Add(ctx, incr)
931 return
932 }
933
934 o := addOptPool.Get().(*[]metric.AddOption)
935 defer func() {
936 *o = (*o)[:0]
937 addOptPool.Put(o)
938 }()
939
940 *o = append(
941 *o,
942 metric.WithAttributes(
943 append(
944 attrs,
945 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
946 )...,
947 ),
948 )
949
950 m.Int64Counter.Add(ctx, incr, *o...)
951 }
952
953 // AddSet adds incr to the existing count for set.
954 func (m ClientConnectionTimeouts) AddSet(ctx context.Context, incr int64, set attribute.Set) {
955 if set.Len() == 0 {
956 m.Int64Counter.Add(ctx, incr)
957 return
958 }
959
960 o := addOptPool.Get().(*[]metric.AddOption)
961 defer func() {
962 *o = (*o)[:0]
963 addOptPool.Put(o)
964 }()
965
966 *o = append(*o, metric.WithAttributeSet(set))
967 m.Int64Counter.Add(ctx, incr, *o...)
968 }
969
970 // ClientConnectionUseTime is an instrument used to record metric values
971 // conforming to the "db.client.connection.use_time" semantic conventions. It
972 // represents the time between borrowing a connection and returning it to the
973 // pool.
974 type ClientConnectionUseTime struct {
975 metric.Float64Histogram
976 }
977
978 // NewClientConnectionUseTime returns a new ClientConnectionUseTime instrument.
979 func NewClientConnectionUseTime(
980 m metric.Meter,
981 opt ...metric.Float64HistogramOption,
982 ) (ClientConnectionUseTime, error) {
983 // Check if the meter is nil.
984 if m == nil {
985 return ClientConnectionUseTime{noop.Float64Histogram{}}, nil
986 }
987
988 i, err := m.Float64Histogram(
989 "db.client.connection.use_time",
990 append([]metric.Float64HistogramOption{
991 metric.WithDescription("The time between borrowing a connection and returning it to the pool"),
992 metric.WithUnit("s"),
993 }, opt...)...,
994 )
995 if err != nil {
996 return ClientConnectionUseTime{noop.Float64Histogram{}}, err
997 }
998 return ClientConnectionUseTime{i}, nil
999 }
1000
1001 // Inst returns the underlying metric instrument.
1002 func (m ClientConnectionUseTime) Inst() metric.Float64Histogram {
1003 return m.Float64Histogram
1004 }
1005
1006 // Name returns the semantic convention name of the instrument.
1007 func (ClientConnectionUseTime) Name() string {
1008 return "db.client.connection.use_time"
1009 }
1010
1011 // Unit returns the semantic convention unit of the instrument
1012 func (ClientConnectionUseTime) Unit() string {
1013 return "s"
1014 }
1015
1016 // Description returns the semantic convention description of the instrument
1017 func (ClientConnectionUseTime) Description() string {
1018 return "The time between borrowing a connection and returning it to the pool"
1019 }
1020
1021 // Record records val to the current distribution for attrs.
1022 //
1023 // The clientConnectionPoolName is the the name of the connection pool; unique
1024 // within the instrumented application. In case the connection pool
1025 // implementation doesn't provide a name, instrumentation SHOULD use a
1026 // combination of parameters that would make the name unique, for example,
1027 // combining attributes `server.address`, `server.port`, and `db.namespace`,
1028 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
1029 // generate connection pool name following different patterns SHOULD document it.
1030 func (m ClientConnectionUseTime) Record(
1031 ctx context.Context,
1032 val float64,
1033 clientConnectionPoolName string,
1034 attrs ...attribute.KeyValue,
1035 ) {
1036 if len(attrs) == 0 {
1037 m.Float64Histogram.Record(ctx, val)
1038 return
1039 }
1040
1041 o := recOptPool.Get().(*[]metric.RecordOption)
1042 defer func() {
1043 *o = (*o)[:0]
1044 recOptPool.Put(o)
1045 }()
1046
1047 *o = append(
1048 *o,
1049 metric.WithAttributes(
1050 append(
1051 attrs,
1052 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
1053 )...,
1054 ),
1055 )
1056
1057 m.Float64Histogram.Record(ctx, val, *o...)
1058 }
1059
1060 // RecordSet records val to the current distribution for set.
1061 func (m ClientConnectionUseTime) RecordSet(ctx context.Context, val float64, set attribute.Set) {
1062 if set.Len() == 0 {
1063 m.Float64Histogram.Record(ctx, val)
1064 return
1065 }
1066
1067 o := recOptPool.Get().(*[]metric.RecordOption)
1068 defer func() {
1069 *o = (*o)[:0]
1070 recOptPool.Put(o)
1071 }()
1072
1073 *o = append(*o, metric.WithAttributeSet(set))
1074 m.Float64Histogram.Record(ctx, val, *o...)
1075 }
1076
1077 // ClientConnectionWaitTime is an instrument used to record metric values
1078 // conforming to the "db.client.connection.wait_time" semantic conventions. It
1079 // represents the time it took to obtain an open connection from the pool.
1080 type ClientConnectionWaitTime struct {
1081 metric.Float64Histogram
1082 }
1083
1084 // NewClientConnectionWaitTime returns a new ClientConnectionWaitTime instrument.
1085 func NewClientConnectionWaitTime(
1086 m metric.Meter,
1087 opt ...metric.Float64HistogramOption,
1088 ) (ClientConnectionWaitTime, error) {
1089 // Check if the meter is nil.
1090 if m == nil {
1091 return ClientConnectionWaitTime{noop.Float64Histogram{}}, nil
1092 }
1093
1094 i, err := m.Float64Histogram(
1095 "db.client.connection.wait_time",
1096 append([]metric.Float64HistogramOption{
1097 metric.WithDescription("The time it took to obtain an open connection from the pool"),
1098 metric.WithUnit("s"),
1099 }, opt...)...,
1100 )
1101 if err != nil {
1102 return ClientConnectionWaitTime{noop.Float64Histogram{}}, err
1103 }
1104 return ClientConnectionWaitTime{i}, nil
1105 }
1106
1107 // Inst returns the underlying metric instrument.
1108 func (m ClientConnectionWaitTime) Inst() metric.Float64Histogram {
1109 return m.Float64Histogram
1110 }
1111
1112 // Name returns the semantic convention name of the instrument.
1113 func (ClientConnectionWaitTime) Name() string {
1114 return "db.client.connection.wait_time"
1115 }
1116
1117 // Unit returns the semantic convention unit of the instrument
1118 func (ClientConnectionWaitTime) Unit() string {
1119 return "s"
1120 }
1121
1122 // Description returns the semantic convention description of the instrument
1123 func (ClientConnectionWaitTime) Description() string {
1124 return "The time it took to obtain an open connection from the pool"
1125 }
1126
1127 // Record records val to the current distribution for attrs.
1128 //
1129 // The clientConnectionPoolName is the the name of the connection pool; unique
1130 // within the instrumented application. In case the connection pool
1131 // implementation doesn't provide a name, instrumentation SHOULD use a
1132 // combination of parameters that would make the name unique, for example,
1133 // combining attributes `server.address`, `server.port`, and `db.namespace`,
1134 // formatted as `server.address:server.port/db.namespace`. Instrumentations that
1135 // generate connection pool name following different patterns SHOULD document it.
1136 func (m ClientConnectionWaitTime) Record(
1137 ctx context.Context,
1138 val float64,
1139 clientConnectionPoolName string,
1140 attrs ...attribute.KeyValue,
1141 ) {
1142 if len(attrs) == 0 {
1143 m.Float64Histogram.Record(ctx, val)
1144 return
1145 }
1146
1147 o := recOptPool.Get().(*[]metric.RecordOption)
1148 defer func() {
1149 *o = (*o)[:0]
1150 recOptPool.Put(o)
1151 }()
1152
1153 *o = append(
1154 *o,
1155 metric.WithAttributes(
1156 append(
1157 attrs,
1158 attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
1159 )...,
1160 ),
1161 )
1162
1163 m.Float64Histogram.Record(ctx, val, *o...)
1164 }
1165
1166 // RecordSet records val to the current distribution for set.
1167 func (m ClientConnectionWaitTime) RecordSet(ctx context.Context, val float64, set attribute.Set) {
1168 if set.Len() == 0 {
1169 m.Float64Histogram.Record(ctx, val)
1170 return
1171 }
1172
1173 o := recOptPool.Get().(*[]metric.RecordOption)
1174 defer func() {
1175 *o = (*o)[:0]
1176 recOptPool.Put(o)
1177 }()
1178
1179 *o = append(*o, metric.WithAttributeSet(set))
1180 m.Float64Histogram.Record(ctx, val, *o...)
1181 }
1182
1183 // ClientOperationDuration is an instrument used to record metric values
1184 // conforming to the "db.client.operation.duration" semantic conventions. It
1185 // represents the duration of database client operations.
1186 type ClientOperationDuration struct {
1187 metric.Float64Histogram
1188 }
1189
1190 // NewClientOperationDuration returns a new ClientOperationDuration instrument.
1191 func NewClientOperationDuration(
1192 m metric.Meter,
1193 opt ...metric.Float64HistogramOption,
1194 ) (ClientOperationDuration, error) {
1195 // Check if the meter is nil.
1196 if m == nil {
1197 return ClientOperationDuration{noop.Float64Histogram{}}, nil
1198 }
1199
1200 i, err := m.Float64Histogram(
1201 "db.client.operation.duration",
1202 append([]metric.Float64HistogramOption{
1203 metric.WithDescription("Duration of database client operations."),
1204 metric.WithUnit("s"),
1205 }, opt...)...,
1206 )
1207 if err != nil {
1208 return ClientOperationDuration{noop.Float64Histogram{}}, err
1209 }
1210 return ClientOperationDuration{i}, nil
1211 }
1212
1213 // Inst returns the underlying metric instrument.
1214 func (m ClientOperationDuration) Inst() metric.Float64Histogram {
1215 return m.Float64Histogram
1216 }
1217
1218 // Name returns the semantic convention name of the instrument.
1219 func (ClientOperationDuration) Name() string {
1220 return "db.client.operation.duration"
1221 }
1222
1223 // Unit returns the semantic convention unit of the instrument
1224 func (ClientOperationDuration) Unit() string {
1225 return "s"
1226 }
1227
1228 // Description returns the semantic convention description of the instrument
1229 func (ClientOperationDuration) Description() string {
1230 return "Duration of database client operations."
1231 }
1232
1233 // Record records val to the current distribution for attrs.
1234 //
1235 // The systemName is the the database management system (DBMS) product as
1236 // identified by the client instrumentation.
1237 //
1238 // All additional attrs passed are included in the recorded value.
1239 //
1240 // Batch operations SHOULD be recorded as a single operation.
1241 func (m ClientOperationDuration) Record(
1242 ctx context.Context,
1243 val float64,
1244 systemName SystemNameAttr,
1245 attrs ...attribute.KeyValue,
1246 ) {
1247 if len(attrs) == 0 {
1248 m.Float64Histogram.Record(ctx, val)
1249 return
1250 }
1251
1252 o := recOptPool.Get().(*[]metric.RecordOption)
1253 defer func() {
1254 *o = (*o)[:0]
1255 recOptPool.Put(o)
1256 }()
1257
1258 *o = append(
1259 *o,
1260 metric.WithAttributes(
1261 append(
1262 attrs,
1263 attribute.String("db.system.name", string(systemName)),
1264 )...,
1265 ),
1266 )
1267
1268 m.Float64Histogram.Record(ctx, val, *o...)
1269 }
1270
1271 // RecordSet records val to the current distribution for set.
1272 //
1273 // Batch operations SHOULD be recorded as a single operation.
1274 func (m ClientOperationDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
1275 if set.Len() == 0 {
1276 m.Float64Histogram.Record(ctx, val)
1277 return
1278 }
1279
1280 o := recOptPool.Get().(*[]metric.RecordOption)
1281 defer func() {
1282 *o = (*o)[:0]
1283 recOptPool.Put(o)
1284 }()
1285
1286 *o = append(*o, metric.WithAttributeSet(set))
1287 m.Float64Histogram.Record(ctx, val, *o...)
1288 }
1289
1290 // AttrCollectionName returns an optional attribute for the "db.collection.name"
1291 // semantic convention. It represents the name of a collection (table, container)
1292 // within the database.
1293 func (ClientOperationDuration) AttrCollectionName(val string) attribute.KeyValue {
1294 return attribute.String("db.collection.name", val)
1295 }
1296
1297 // AttrNamespace returns an optional attribute for the "db.namespace" semantic
1298 // convention. It represents the name of the database, fully qualified within the
1299 // server address and port.
1300 func (ClientOperationDuration) AttrNamespace(val string) attribute.KeyValue {
1301 return attribute.String("db.namespace", val)
1302 }
1303
1304 // AttrOperationName returns an optional attribute for the "db.operation.name"
1305 // semantic convention. It represents the name of the operation or command being
1306 // executed.
1307 func (ClientOperationDuration) AttrOperationName(val string) attribute.KeyValue {
1308 return attribute.String("db.operation.name", val)
1309 }
1310
1311 // AttrResponseStatusCode returns an optional attribute for the
1312 // "db.response.status_code" semantic convention. It represents the database
1313 // response status code.
1314 func (ClientOperationDuration) AttrResponseStatusCode(val string) attribute.KeyValue {
1315 return attribute.String("db.response.status_code", val)
1316 }
1317
1318 // AttrErrorType returns an optional attribute for the "error.type" semantic
1319 // convention. It represents the describes a class of error the operation ended
1320 // with.
1321 func (ClientOperationDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1322 return attribute.String("error.type", string(val))
1323 }
1324
1325 // AttrServerPort returns an optional attribute for the "server.port" semantic
1326 // convention. It represents the server port number.
1327 func (ClientOperationDuration) AttrServerPort(val int) attribute.KeyValue {
1328 return attribute.Int("server.port", val)
1329 }
1330
1331 // AttrQuerySummary returns an optional attribute for the "db.query.summary"
1332 // semantic convention. It represents the low cardinality summary of a database
1333 // query.
1334 func (ClientOperationDuration) AttrQuerySummary(val string) attribute.KeyValue {
1335 return attribute.String("db.query.summary", val)
1336 }
1337
1338 // AttrStoredProcedureName returns an optional attribute for the
1339 // "db.stored_procedure.name" semantic convention. It represents the name of a
1340 // stored procedure within the database.
1341 func (ClientOperationDuration) AttrStoredProcedureName(val string) attribute.KeyValue {
1342 return attribute.String("db.stored_procedure.name", val)
1343 }
1344
1345 // AttrNetworkPeerAddress returns an optional attribute for the
1346 // "network.peer.address" semantic convention. It represents the peer address of
1347 // the database node where the operation was performed.
1348 func (ClientOperationDuration) AttrNetworkPeerAddress(val string) attribute.KeyValue {
1349 return attribute.String("network.peer.address", val)
1350 }
1351
1352 // AttrNetworkPeerPort returns an optional attribute for the "network.peer.port"
1353 // semantic convention. It represents the peer port number of the network
1354 // connection.
1355 func (ClientOperationDuration) AttrNetworkPeerPort(val int) attribute.KeyValue {
1356 return attribute.Int("network.peer.port", val)
1357 }
1358
1359 // AttrServerAddress returns an optional attribute for the "server.address"
1360 // semantic convention. It represents the name of the database host.
1361 func (ClientOperationDuration) AttrServerAddress(val string) attribute.KeyValue {
1362 return attribute.String("server.address", val)
1363 }
1364
1365 // AttrQueryText returns an optional attribute for the "db.query.text" semantic
1366 // convention. It represents the database query being executed.
1367 func (ClientOperationDuration) AttrQueryText(val string) attribute.KeyValue {
1368 return attribute.String("db.query.text", val)
1369 }
1370
1371 // ClientResponseReturnedRows is an instrument used to record metric values
1372 // conforming to the "db.client.response.returned_rows" semantic conventions. It
1373 // represents the actual number of records returned by the database operation.
1374 type ClientResponseReturnedRows struct {
1375 metric.Int64Histogram
1376 }
1377
1378 // NewClientResponseReturnedRows returns a new ClientResponseReturnedRows
1379 // instrument.
1380 func NewClientResponseReturnedRows(
1381 m metric.Meter,
1382 opt ...metric.Int64HistogramOption,
1383 ) (ClientResponseReturnedRows, error) {
1384 // Check if the meter is nil.
1385 if m == nil {
1386 return ClientResponseReturnedRows{noop.Int64Histogram{}}, nil
1387 }
1388
1389 i, err := m.Int64Histogram(
1390 "db.client.response.returned_rows",
1391 append([]metric.Int64HistogramOption{
1392 metric.WithDescription("The actual number of records returned by the database operation."),
1393 metric.WithUnit("{row}"),
1394 }, opt...)...,
1395 )
1396 if err != nil {
1397 return ClientResponseReturnedRows{noop.Int64Histogram{}}, err
1398 }
1399 return ClientResponseReturnedRows{i}, nil
1400 }
1401
1402 // Inst returns the underlying metric instrument.
1403 func (m ClientResponseReturnedRows) Inst() metric.Int64Histogram {
1404 return m.Int64Histogram
1405 }
1406
1407 // Name returns the semantic convention name of the instrument.
1408 func (ClientResponseReturnedRows) Name() string {
1409 return "db.client.response.returned_rows"
1410 }
1411
1412 // Unit returns the semantic convention unit of the instrument
1413 func (ClientResponseReturnedRows) Unit() string {
1414 return "{row}"
1415 }
1416
1417 // Description returns the semantic convention description of the instrument
1418 func (ClientResponseReturnedRows) Description() string {
1419 return "The actual number of records returned by the database operation."
1420 }
1421
1422 // Record records val to the current distribution for attrs.
1423 //
1424 // The systemName is the the database management system (DBMS) product as
1425 // identified by the client instrumentation.
1426 //
1427 // All additional attrs passed are included in the recorded value.
1428 func (m ClientResponseReturnedRows) Record(
1429 ctx context.Context,
1430 val int64,
1431 systemName SystemNameAttr,
1432 attrs ...attribute.KeyValue,
1433 ) {
1434 if len(attrs) == 0 {
1435 m.Int64Histogram.Record(ctx, val)
1436 return
1437 }
1438
1439 o := recOptPool.Get().(*[]metric.RecordOption)
1440 defer func() {
1441 *o = (*o)[:0]
1442 recOptPool.Put(o)
1443 }()
1444
1445 *o = append(
1446 *o,
1447 metric.WithAttributes(
1448 append(
1449 attrs,
1450 attribute.String("db.system.name", string(systemName)),
1451 )...,
1452 ),
1453 )
1454
1455 m.Int64Histogram.Record(ctx, val, *o...)
1456 }
1457
1458 // RecordSet records val to the current distribution for set.
1459 func (m ClientResponseReturnedRows) RecordSet(ctx context.Context, val int64, set attribute.Set) {
1460 if set.Len() == 0 {
1461 m.Int64Histogram.Record(ctx, val)
1462 return
1463 }
1464
1465 o := recOptPool.Get().(*[]metric.RecordOption)
1466 defer func() {
1467 *o = (*o)[:0]
1468 recOptPool.Put(o)
1469 }()
1470
1471 *o = append(*o, metric.WithAttributeSet(set))
1472 m.Int64Histogram.Record(ctx, val, *o...)
1473 }
1474
1475 // AttrCollectionName returns an optional attribute for the "db.collection.name"
1476 // semantic convention. It represents the name of a collection (table, container)
1477 // within the database.
1478 func (ClientResponseReturnedRows) AttrCollectionName(val string) attribute.KeyValue {
1479 return attribute.String("db.collection.name", val)
1480 }
1481
1482 // AttrNamespace returns an optional attribute for the "db.namespace" semantic
1483 // convention. It represents the name of the database, fully qualified within the
1484 // server address and port.
1485 func (ClientResponseReturnedRows) AttrNamespace(val string) attribute.KeyValue {
1486 return attribute.String("db.namespace", val)
1487 }
1488
1489 // AttrOperationName returns an optional attribute for the "db.operation.name"
1490 // semantic convention. It represents the name of the operation or command being
1491 // executed.
1492 func (ClientResponseReturnedRows) AttrOperationName(val string) attribute.KeyValue {
1493 return attribute.String("db.operation.name", val)
1494 }
1495
1496 // AttrResponseStatusCode returns an optional attribute for the
1497 // "db.response.status_code" semantic convention. It represents the database
1498 // response status code.
1499 func (ClientResponseReturnedRows) AttrResponseStatusCode(val string) attribute.KeyValue {
1500 return attribute.String("db.response.status_code", val)
1501 }
1502
1503 // AttrErrorType returns an optional attribute for the "error.type" semantic
1504 // convention. It represents the describes a class of error the operation ended
1505 // with.
1506 func (ClientResponseReturnedRows) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1507 return attribute.String("error.type", string(val))
1508 }
1509
1510 // AttrServerPort returns an optional attribute for the "server.port" semantic
1511 // convention. It represents the server port number.
1512 func (ClientResponseReturnedRows) AttrServerPort(val int) attribute.KeyValue {
1513 return attribute.Int("server.port", val)
1514 }
1515
1516 // AttrQuerySummary returns an optional attribute for the "db.query.summary"
1517 // semantic convention. It represents the low cardinality summary of a database
1518 // query.
1519 func (ClientResponseReturnedRows) AttrQuerySummary(val string) attribute.KeyValue {
1520 return attribute.String("db.query.summary", val)
1521 }
1522
1523 // AttrNetworkPeerAddress returns an optional attribute for the
1524 // "network.peer.address" semantic convention. It represents the peer address of
1525 // the database node where the operation was performed.
1526 func (ClientResponseReturnedRows) AttrNetworkPeerAddress(val string) attribute.KeyValue {
1527 return attribute.String("network.peer.address", val)
1528 }
1529
1530 // AttrNetworkPeerPort returns an optional attribute for the "network.peer.port"
1531 // semantic convention. It represents the peer port number of the network
1532 // connection.
1533 func (ClientResponseReturnedRows) AttrNetworkPeerPort(val int) attribute.KeyValue {
1534 return attribute.Int("network.peer.port", val)
1535 }
1536
1537 // AttrServerAddress returns an optional attribute for the "server.address"
1538 // semantic convention. It represents the name of the database host.
1539 func (ClientResponseReturnedRows) AttrServerAddress(val string) attribute.KeyValue {
1540 return attribute.String("server.address", val)
1541 }
1542
1543 // AttrQueryText returns an optional attribute for the "db.query.text" semantic
1544 // convention. It represents the database query being executed.
1545 func (ClientResponseReturnedRows) AttrQueryText(val string) attribute.KeyValue {
1546 return attribute.String("db.query.text", val)
1547 }