|
15 | 15 |
|
16 | 16 | --- |
17 | 17 |
|
18 | | -## 📦 Package |
| 18 | +## 📦 Packages |
19 | 19 |
|
20 | 20 | | Package | Build | NuGet | Downloads | |
21 | 21 | |----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| |
22 | 22 | | **DynamoDb.DistributedLock** | [](https://github.com/LayeredCraft/dynamodb-distributed-lock/actions/workflows/build.yaml) | [](https://www.nuget.org/packages/DynamoDb.DistributedLock) | [](https://www.nuget.org/packages/DynamoDb.DistributedLock) | |
| 23 | +| **DynamoDb.DistributedLock.Observability** | [](https://github.com/LayeredCraft/dynamodb-distributed-lock/actions/workflows/build.yaml) | [](https://www.nuget.org/packages/DynamoDb.DistributedLock.Observability) | [](https://www.nuget.org/packages/DynamoDb.DistributedLock.Observability) | |
23 | 24 |
|
24 | 25 | --- |
25 | 26 |
|
@@ -225,32 +226,66 @@ However, the partition and sort key attribute names are fully configurable via ` |
225 | 226 |
|
226 | 227 | --- |
227 | 228 |
|
228 | | -## 📈 Telemetry |
| 229 | +## 📈 Observability |
229 | 230 |
|
230 | | -This library uses [System.Diagnostics.Metrics](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/metrics) `Meter`s to collect metrics. These metrics can be opted in to be exported to your preferred telemetry system (e.g., OpenTelemetry, console output) using standard dotnet telemetry exporters. |
| 231 | +This library uses [System.Diagnostics.Metrics](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/metrics) to collect telemetry data. These metrics can be exported to your preferred observability system (e.g., OpenTelemetry, Prometheus, console output) using standard .NET telemetry exporters. |
231 | 232 |
|
232 | 233 | A full list of metric names can be found in the [MetricNames](src/DynamoDb.DistributedLock/Metrics/MetricNames.cs) class. |
233 | 234 |
|
234 | | -By default no metrics are exported to your collector, but you can enable them by configuring the `Meter` in your application: |
| 235 | +### 📦 Observability Package (Recommended) |
| 236 | + |
| 237 | +For simplified OpenTelemetry integration, install the observability package: |
| 238 | + |
| 239 | +```bash |
| 240 | +dotnet add package DynamoDb.DistributedLock.Observability |
| 241 | +``` |
| 242 | + |
| 243 | +Then configure metrics collection with a single method call: |
| 244 | + |
| 245 | +```csharp |
| 246 | +using DynamoDb.DistributedLock.Observability; |
| 247 | + |
| 248 | +services.AddOpenTelemetry() |
| 249 | + .WithMetrics(metrics => |
| 250 | + metrics |
| 251 | + // Automatically registers the DynamoDB distributed lock meter |
| 252 | + .AddDynamoDbDistributedLock() |
| 253 | + // Configure your preferred exporter, e.g., OpenTelemetry Protocol (OTLP) |
| 254 | + .AddOtlpExporter(options => options.Endpoint = otlpEndpoint) |
| 255 | + ); |
| 256 | +``` |
| 257 | + |
| 258 | +### 🔧 Manual Configuration |
| 259 | + |
| 260 | +If you prefer manual configuration without the observability package: |
235 | 261 |
|
236 | | -[OpenTelemetry](https://opentelemetry.io/docs/languages/dotnet/) |
237 | 262 | ```csharp |
238 | 263 | services.AddOpenTelemetry() |
239 | 264 | .WithMetrics(metrics => |
240 | 265 | metrics |
241 | | - // There is only one meter used by this library |
242 | | - // and this constant value refers to its name |
243 | | - // this causes the telemetry system to collect metrics emitted during lock operations |
| 266 | + // Register the meter name manually |
244 | 267 | .AddMeter(DynamoDb.DistributedLock.Metrics.MetricNames.MeterName) |
245 | | - // Views can be used to filter out any metrics you do not want to collect |
246 | | - // while still collecting all metrics from the Meter |
| 268 | + // Views can be used to filter out specific metrics |
247 | 269 | .AddView(DynamoDb.DistributedLock.Metrics.MetricNames.LockReleaseTimer, MetricStreamConfiguration.Drop) |
248 | | - // Configure your preferred exporter, e.g., OpenTelemetry Protocol (OTLP) |
| 270 | + // Configure your preferred exporter |
249 | 271 | .AddOtlpExporter(options => options.Endpoint = otlpEndpoint) |
250 | 272 | ); |
251 | 273 | ``` |
252 | 274 |
|
253 | | -Other options for collection of metrics are available, including local development options such as [dotnet-counters](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-counters) or the [.Net Aspire standalone dashboard](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/standalone) |
| 275 | +### 🔍 Available Metrics |
| 276 | + |
| 277 | +The library emits the following metrics for observability: |
| 278 | + |
| 279 | +- **Lock acquisition counters**: Track successful and failed lock acquisitions |
| 280 | +- **Lock release counters**: Track successful and failed lock releases |
| 281 | +- **Retry counters**: Track retry attempts and exhausted retries |
| 282 | +- **Timing histograms**: Measure lock acquisition and release durations |
| 283 | + |
| 284 | +### 🧪 Local Development |
| 285 | + |
| 286 | +Other options for metrics collection during development: |
| 287 | +- [dotnet-counters](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-counters) for real-time metrics viewing |
| 288 | +- [.NET Aspire dashboard](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/standalone) for local observability |
254 | 289 |
|
255 | 290 | --- |
256 | 291 |
|
|
0 commit comments