-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add readme entry for OpenTelemetry hook
Signed-off-by: Federico Bond <[email protected]>
- Loading branch information
1 parent
5f1f4d5
commit 37d025c
Showing
1 changed file
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,37 @@ | ||
# OpenFeature Python Hooks | ||
Hooks are a mechanism whereby application developers can add arbitrary behavior to flag evaluation. | ||
They operate similarly to middleware in many web frameworks. Please see the | ||
[spec]("https://github.com/open-feature/spec/blob/main/specification/sections/04-hooks.md") for more details. | ||
Hooks are a mechanism whereby application developers can add arbitrary behavior to flag evaluation. | ||
They operate similarly to middleware in many web frameworks. Please see the | ||
[spec]("https://github.com/open-feature/spec/blob/main/specification/sections/04-hooks.md") for more details. | ||
|
||
## OpenTelemetry Hook | ||
|
||
The OpenTelemetry tracing hook for OpenFeature provides a [spec compliant][otel-spec] way to automatically add a feature flag evaluation to a span as a span event. Since feature flags are dynamic and affect runtime behavior, it’s important to collect relevant feature flag telemetry signals. This can be used to determine the impact a feature has on a request, enabling enhanced observability use cases, such as A/B testing or progressive feature releases. | ||
|
||
### Usage | ||
|
||
OpenFeature provides various ways to register hooks. The location that a hook is registered affects when the hook is run. It's recommended to register the `TracingHook` globally in most situations but it's possible to only enable the hook on specific clients. You should **never** register the `TracingHook` globally and on a client. | ||
|
||
More information on hooks can be found in the [OpenFeature documentation][hook-concept]. | ||
|
||
#### Register Globally | ||
|
||
The `TracingHook` can be set on the OpenFeature singleton. This will ensure that every flag evaluation will always create a span event, if am active span is available. | ||
|
||
```python | ||
from openfeature import api | ||
from openfeature.contrib.hooks.otel import TracingHook | ||
|
||
api.add_hooks(TracingHook()) | ||
``` | ||
|
||
#### Register Per Client | ||
|
||
The `TracingHook` can be set on an individual client. This should only be done if it wasn't set globally and other clients shouldn't use this hook. Setting the hook on the client will ensure that every flag evaluation performed by this client will always create a span event, if an active span is available. | ||
|
||
```python | ||
from openfeature import api | ||
from openfeature.contrib.hooks.otel import TracingHook | ||
|
||
client = api.get_client("my-app") | ||
client.add_hooks(TracingHook()) | ||
``` |