Skip to content

Commit 36d884f

Browse files
committed
Add OpenTelemetry integration documentation
Document the ActivitySource and Meter names, available span attributes, opt-in sensitive attributes, and available metrics with their types and semantic convention references.
1 parent 7402540 commit 36d884f

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

docs/otel.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# OpenTelemetry Integration
2+
3+
The Firebird ADO.NET provider includes built-in support for [OpenTelemetry](https://opentelemetry.io/) distributed tracing and metrics using the native .NET `System.Diagnostics` APIs. No dependency on the OpenTelemetry SDK is required in the provider itself — your application opts in by configuring the appropriate listeners.
4+
5+
## Distributed Tracing
6+
7+
The provider emits `Activity` spans for database command execution using `System.Diagnostics.ActivitySource`.
8+
9+
### Enabling Traces
10+
11+
```csharp
12+
using OpenTelemetry.Trace;
13+
14+
var tracerProvider = Sdk.CreateTracerProviderBuilder()
15+
.AddSource(FirebirdSql.Data.FirebirdClient.FbTelemetry.ActivitySourceName)
16+
.AddConsoleExporter() // or any other exporter
17+
.Build();
18+
```
19+
20+
The `ActivitySource` name is `"FirebirdSql.Data"`, also available as the constant `FbTelemetry.ActivitySourceName`.
21+
22+
### Span Attributes
23+
24+
Spans follow the [OTel Database Client Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/database/database-spans/):
25+
26+
| Attribute | Description |
27+
|-----------|-------------|
28+
| `db.system.name` | Always `"firebirdsql"` |
29+
| `db.namespace` | The database name from the connection |
30+
| `db.operation.name` | The SQL verb (`SELECT`, `INSERT`, etc.) or `EXECUTE PROCEDURE` |
31+
| `db.collection.name` | The table name (for `TableDirect` commands) |
32+
| `db.stored_procedure.name` | The stored procedure name (for `StoredProcedure` commands) |
33+
| `db.query.summary` | A low-cardinality summary of the operation |
34+
| `db.query.text` | The full SQL text (**opt-in**, see below) |
35+
| `db.query.parameter.*` | Parameter values (**opt-in**, see below) |
36+
| `server.address` | The database server hostname |
37+
| `server.port` | The database server port (only when non-default, i.e. != 3050) |
38+
| `error.type` | The SQLSTATE code (for `FbException`) or exception type name |
39+
40+
### Opt-In Sensitive Attributes
41+
42+
By default, `db.query.text` and `db.query.parameter.*` are **not** collected, as they may contain sensitive data. Enable them explicitly:
43+
44+
```csharp
45+
using FirebirdSql.Data.Logging;
46+
47+
// Enable SQL text in traces
48+
FbLogManager.EnableQueryTextTracing();
49+
50+
// Enable parameter values in traces (and logs)
51+
FbLogManager.EnableParameterLogging();
52+
```
53+
54+
## Metrics
55+
56+
The provider emits metrics via `System.Diagnostics.Metrics.Meter`.
57+
58+
### Enabling Metrics
59+
60+
```csharp
61+
using OpenTelemetry.Metrics;
62+
63+
var meterProvider = Sdk.CreateMeterProviderBuilder()
64+
.AddMeter(FirebirdSql.Data.FirebirdClient.FbTelemetry.MeterName)
65+
.AddConsoleExporter() // or any other exporter
66+
.Build();
67+
```
68+
69+
The `Meter` name is `"FirebirdSql.Data"`, also available as the constant `FbTelemetry.MeterName`.
70+
71+
### Available Metrics
72+
73+
Metrics follow the [OTel Database Client Metrics Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/database/database-metrics/):
74+
75+
| Metric | Type | Unit | Description |
76+
|--------|------|------|-------------|
77+
| `db.client.operation.duration` | Histogram | `s` | Duration of database client operations |
78+
| `db.client.connection.create_time` | Histogram | `s` | Time to create a new connection |
79+
| `db.client.connection.count` | ObservableUpDownCounter | `{connection}` | Current connection count by state (`idle`/`used`) |
80+
| `db.client.connection.max` | ObservableUpDownCounter | `{connection}` | Maximum number of open connections allowed |

0 commit comments

Comments
 (0)