Conversation
ncipollina
left a comment
There was a problem hiding this comment.
🎉 First of all, love this implementation!!! I think this is exactly what we need for next version of this. That being said, I did leave some commentary on some suggested changes. I would prefer to not add any additional packages to the project and just use the System.Diagnostics.DiagnosticSource package that is already included. I've left a couple options for how this could be implemented.
As to your question regarding the DI for OTEL, I would prefer to add that as a separate project, that can be deployed to nuget separately. If you would like to include that, or add as an additional issue/PR, by all means, go for it!
|
What version prefix should this change use? |
If you keep the interface, we would bump the version to |
ncipollina
left a comment
There was a problem hiding this comment.
💰 I left a comment on how you can test if you use the static approach. You asked a question around version. If you leave it as you have it with the breaking change, make it 2.0.0. If you decide to go the static approach, then it would be 1.2.0. Let me know what you decide and commit the version there.
…koffRetryPolicy that don't take the lock interface to preserve backwards compatibility
|
I realized that I was probably overthinking things. If there are two constructors, that is a backwards compatible change, so we get nice unit testing, as well as a sensible static default from In the case of people wanting to do something really custom like skipping |
…cy.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…or.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR implements comprehensive metrics collection for distributed lock operations using System.Diagnostics.Metrics. The implementation includes counters for successful/failed lock acquisition and release, retry attempts, and timers for operation durations, with low-overhead collection that only activates when listeners are present.
- Adds metrics infrastructure with
ILockMetricsinterface andLockMetricsimplementation - Updates lock operations to emit metrics for acquisition, release, retry attempts, and timing
- Integrates metrics into the service collection registration for DI support
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/DynamoDb.DistributedLock/Metrics/ | New metrics infrastructure with interface, implementation, and metric name constants |
| src/DynamoDb.DistributedLock/DynamoDbDistributedLock.cs | Added metrics tracking to lock acquisition and release operations |
| src/DynamoDb.DistributedLock/Retry/ExponentialBackoffRetryPolicy.cs | Added retry metrics tracking and ILockMetrics dependency |
| src/DynamoDb.DistributedLock/Extensions/ServiceCollectionExtensions.cs | Registered default LockMetrics instance in DI container |
| test/ | Comprehensive test infrastructure and updates for metrics validation |
| README.md | Added telemetry documentation with OpenTelemetry configuration examples |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
ncipollina
left a comment
There was a problem hiding this comment.
🎉 Excellent work!!!!
|
Thanks! I want you to know that I am now jealous of your copilot pr bot setup when I am working in enterprise GitHub. At first I wasn't sure about it's usefulness, but it does seem to have a decent rate of catching real issues. |
🚀 Pull Request
📋 Summary
This PR implements metric collection for various actions when taking locks. It uses
System.Diagnostics.MetricsMeters to collect the metrics in a way that is consumable by many different telemetry systems.The design of
System.Diagnostics.Metricsis focused on being low cost if you don't opt in to the metrics being collected, so if there are no listeners to a meter, or the instrument such as a specific count metric, then the overhead is a low cost if statement inside the instrument.I have tested this by sending the metrics to an instance of the .Net Aspire dashboard:

✅ Checklist
🧪 Related Issues or PRs
Closes #26
💬 Notes for Reviewers
I think that I implemented the test setup in a reasonable way, but any feedback is appreciated.
This change doesn't include any traces, which could be expanded upon using activities, but I don't currently intend to use traces at the moment, so I didn't add something I wasn't going to verify is useful myself.
One thing I would have loved to add would be extensions on
IServiceCollectionto configure things inside ofAddOpenTelemetryin a condensed way for certain scenarios, but because the metric collection is separate from producing them, it would be bad to add a dependency just for one type. Maybe a second nugetDynamoDb.DistributedLock.Telemetry.OpenTelemetrywould be the way to do that 🙂.