Add provider timing metrics - #73
Open
hosom wants to merge 3 commits into
Open
Conversation
Emit structured, monotonic timing records around initialization, provider reads, calculations, writes, and audit operations so deployment latency can be attributed by phase and provider. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d92ba3d2-77c4-461f-8d6f-25c3228476d1
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Ruby 3.0 syntax incompatibilities and a secondary logging failure can prevent or alter application execution.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Balanced
Findings: 1
New issues introduced by this change (2)
| Severity | Finding |
|---|---|
lib/entitlements.rb — These omitted keyword values require Ruby 3.1+, but the gem still declares Ruby >= 3.0.0… |
|
lib/entitlements.rb — If metric logging fails and STDERR is unavailable (for example, a closed log stream), warn raises… |
What changed in this PR
Adds structured duration metrics around Entitlements provider and auditing operations.
Changes:
- Introduces monotonic timing and JSON metric logging.
- Instruments calculation, application, people-source, and auditing phases.
- Adds unit coverage for metric success and failure behavior.
| File | Description |
|---|---|
lib/entitlements.rb |
Implements and applies timing instrumentation. |
spec/unit/entitlements_spec.rb |
Tests timing metrics and updates provider doubles. |
Suppressed comments (3)
lib/entitlements.rb:431
- The
provider:value-omission syntax requires Ruby 3.1+, while this gem supports Ruby 3.0 (entitlements-app.gemspec:17). On Ruby 3.0 the entire file is a syntax error, so use the explicit keyword value.
timed_operation(phase: "calculate", provider:, target: group_name) { obj.calculate }
lib/entitlements.rb:477
- The shorthand
provider:argument was introduced in Ruby 3.1, but the gem's supported range includes Ruby 3.0 (entitlements-app.gemspec:17). This makes the file unparseable for those consumers; useprovider: provider.
timed_operation(phase: "apply", provider:, target: action.ou) do
lib/entitlements.rb:470
- This omitted keyword value is not valid syntax on supported Ruby 3.0 (
entitlements-app.gemspec:17), causing the application to fail while loading this file. Pass the local variable explicitly.
timed_operation(phase: "preapply", provider:, target: group_name) { obj.preapply }
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Add run correlation, parent and concurrent span semantics, operation counts, and metric documentation so provider service time cannot be confused with deployment wall time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d92ba3d2-77c4-461f-8d6f-25c3228476d1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Add datadog metrics to keep track of how long each deployment phase takes.
Ignore this slop
## SummaryAdd structured timing metrics around the shared Entitlements execution boundaries so deployment time can be attributed to a phase, provider, and configured target.
The emitted JSON records measure:
All durations use a monotonic clock. Successful and failed operations are recorded, and a metrics logging failure cannot replace an application or provider result.
Top-level calculation and execution records are marked as parent spans for wall-clock analysis. Individual records indicate whether they can overlap, preventing parallel prefetch timings from being incorrectly summed. Every record also contains a run identifier, which can be supplied through
ENTITLEMENTS_RUN_IDto match the surrounding deployment.Example:
Raw action identifiers are intentionally excluded because actions can identify individual users and would create an unbounded field. Provider and target fields are sufficient to separate production and testing backends while aggregating deployment latency.
The record schema and aggregation semantics are documented in
docs/metrics.md.Why
Current deployment telemetry reports only total runtime. Calculation logs expose a few broad boundaries, but they cannot reliably distinguish provider reads and diff calculation from provider writes. This makes it impossible to identify whether a long deployment is dominated by AAD, GitHub, LDAP, Stafftools, or audit persistence.
Test plan
bundle exec rspec spec/unitbundle exec rubocop -c .rubocop.yml lib/entitlements.rb spec/unit/entitlements_spec.rb