[FFL-1945] Add flag evaluation metrics via OpenFeature hook#5599
[FFL-1945] Add flag evaluation metrics via OpenFeature hook#5599
Conversation
Typing analysisNote: Ignored files are excluded from the next sections. Untyped methodsThis PR introduces 2 partially typed methods, and clears 1 partially typed method. It increases the percentage of typed methods from 61.38% to 61.64% (+0.26%). Partially typed methods (+2-1)❌ Introduced:If you believe a method or an attribute is rightfully untyped or partially typed, you can add |
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: e269408 | Docs | Datadog PR Page | Give us feedback! |
8a1f290 to
46c5c56
Compare
BenchmarksBenchmark execution time: 2026-04-30 21:20:50 Comparing candidate commit e269408 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 45 metrics, 1 unstable metrics.
|
a0d96ae to
dca0c3d
Compare
dca0c3d to
576c7e4
Compare
58fbef9 to
ae9c63f
Compare
ae9c63f to
60aa06e
Compare
Cache the DD_METRICS_OTEL_ENABLED config value once at initialization rather than checking it on every record() call.
vpellan
left a comment
There was a problem hiding this comment.
LGTM after applying the suggestions from other reviewers
Co-authored-by: Sergey Fedorov <oni.strech@gmail.com>
Co-authored-by: Sergey Fedorov <oni.strech@gmail.com>
Co-authored-by: Sergey Fedorov <oni.strech@gmail.com>
Co-authored-by: Sergey Fedorov <oni.strech@gmail.com>
Co-authored-by: Sergey Fedorov <oni.strech@gmail.com>
Match other SDKs (Go, Python, Java) by creating the hook once at initialization time instead of lazily. This removes the retry-on-nil behavior and simplifies the code.
| 'PROVIDER_FATAL' => DEFAULT_ERROR_TYPE, | ||
| 'UNKNOWN_TYPE' => DEFAULT_ERROR_TYPE, |
There was a problem hiding this comment.
minor: is there any reason we don't handle these two?
There was a problem hiding this comment.
This map serves as an allowlist of known error codes and lowercases them per the spec
The error.type and feature_flag.result.reason enumerations use a lowercase 'snake_case' convention (see OpenTelemetry feature-flag event records).
PROVIDER_FATAL is actually among the known error codes, so actually that can be handled. UNKNOWN_TYPE mapping to 'general' makes sense because it's not from the OpenFeature spec and acts as a catch-all. For comparison, in dd-trace-go we could lowercase the error code directly (no map required) because we used the OpenFeature error codes directly.
There was a problem hiding this comment.
oh, makes sense. I confused reason and error code (UNKNOWN is a pre-defined reason but not error code).
Shall we remove it from the map here as it only causes confusion? (We still have defaulting to DEFAULT_ERROR_TYPE in normalize_error_type.)
PROVIDER_FATAL is a standard OpenFeature error code and should map to its lowercase form 'provider_fatal' per the telemetry spec, not 'general'. Cross-SDK comparison: - Go: strings.ToLower() → 'provider_fatal' - Python: .lower() → 'provider_fatal' - .NET: explicit switch → 'provider_fatal' - Ruby (before): ERROR_TYPE_MAP → 'general' (incorrect) - Ruby (after): ERROR_TYPE_MAP → 'provider_fatal' (correct) UNKNOWN_TYPE remains mapped to 'general' since it's a Datadog-specific error code (not in OpenFeature spec) used for unknown flag types.
# What does this PR do? Add `__dd_allocation_key` metadata to `ResolutionDetails`. # Motivation Follow-up from DataDog/dd-trace-rb#5599 (comment) # Additional Notes # How to test the change? Co-authored-by: oleksii.shmalko <oleksii.shmalko@datadoghq.com>
What does this PR do?
Adds
feature_flag.evaluationscounter metric via OpenTelemetry to track flag evaluations.Motivation:
Enable observability of feature flag usage through standardized OTel metrics.
Change log entry
Yes. Add flag evaluation metrics (
feature_flag.evaluations) via OpenTelemetry for OpenFeature provider.Additional Notes:
feature_flag.key,feature_flag.result.variant,feature_flag.result.reasonfeature_flag.result.allocation_key,error.typeDD_METRICS_OTEL_ENABLED=trueto enable metrics (consistent with the other dd-trace-* SDKs)openfeature-sdk>= 0.5.1 for provider hooks supportHow to test the change?
bundle exec rspec spec/datadog/open_feature/metrics/ spec/datadog/open_feature/hooks/bundle exec steep check lib/datadog/open_feature/metrics lib/datadog/open_feature/hooksEnvironment variables: