Skip to content

Commit 395a907

Browse files
committed
Add InstrumentAdvice with histogram bucket boundaries on .NET 9+
Suggest default histogram bucket boundaries for operation duration and connection create time histograms, improving out-of-the-box resolution. Guarded by NET9_0_OR_GREATER since InstrumentAdvice is a .NET 9 API.
1 parent 425ae5a commit 395a907

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

src/FirebirdSql.Data.FirebirdClient/Metrics/FbMetricsStore.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,20 @@ internal static class FbMetricsStore
2424

2525
static FbMetricsStore()
2626
{
27-
// Reference: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-spans.md
27+
#if NET9_0_OR_GREATER
28+
var durationAdvice = new InstrumentAdvice<double>
29+
{
30+
HistogramBucketBoundaries = [0.001, 0.005, 0.01, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
31+
};
32+
#endif
2833

2934
OperationDuration = Source.CreateHistogram<double>(
3035
"db.client.operation.duration",
3136
unit: "s",
3237
description: "Duration of database client operations."
38+
#if NET9_0_OR_GREATER
39+
, advice: durationAdvice
40+
#endif
3341
);
3442

3543
Source.CreateObservableUpDownCounter(
@@ -39,29 +47,20 @@ static FbMetricsStore()
3947
description: "The number of connections that are currently in state described by the 'state' attribute."
4048
);
4149

42-
// db.client.connection.idle.max
43-
// The maximum number of idle open connections allowed
44-
45-
// db.client.connection.idle.min
46-
// The minimum number of idle open connections allowed
47-
4850
Source.CreateObservableUpDownCounter(
4951
"db.client.connection.max",
5052
GetConnectionMax,
5153
unit: "{connection}",
5254
description: "The maximum number of open connections allowed."
5355
);
5456

55-
// db.client.connection.pending_requests
56-
// The number of current pending requests for an open connection
57-
58-
// db.client.connection.timeouts
59-
// The number of connection timeouts that have occurred trying to obtain a connection from the pool
60-
6157
ConnectionCreateTime = Source.CreateHistogram<double>(
6258
"db.client.connection.create_time",
6359
unit: "s",
6460
description: "The time it took to create a new connection."
61+
#if NET9_0_OR_GREATER
62+
, advice: durationAdvice
63+
#endif
6564
);
6665

6766
// db.client.connection.wait_time

0 commit comments

Comments
 (0)