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