Skip to content

Commit

Permalink
fixup: update readme
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <[email protected]>
  • Loading branch information
toddbaert committed Jul 12, 2023
1 parent 3f214a2 commit 85f4ba0
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions libs/hooks/open-telemetry/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpenTelemetry Hook
TODO: all of this.
The OpenTelemetry 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.

The OpenTelemetry hooks for OpenFeature provide a [spec compliant][otel-spec] way to automatically add a feature flag evaluation information to traces and metrics. Since feature flags are dynamic and affect runtime behavior, it’s important to collect relevant feature flag telemetry signals. These can be used to determine the impact a feature has on application behavior, enabling enhanced observability use cases, such as A/B testing or progressive feature releases.

## Installation

Expand All @@ -16,33 +16,48 @@ Confirm that the following peer dependencies are installed.
$ npm install @openfeature/js-sdk @opentelemetry/api
```

## Hooks

### TracingHook

This hook adds a [span event](https://opentelemetry.io/docs/concepts/signals/traces/#span-events) for each feature flag evaluation.

### MetricsHook

This hook performs metric collection by tapping into various hook stages. Below are the metrics are extracted by this hook:

- `feature_flag.evaluation_requests_total`
- `feature_flag.evaluation_success_total`
- `feature_flag.evaluation_error_total`
- `feature_flag.evaluation_active_count`

## 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 `OpenTelemetryHook` globally in most situations but it's possible to only enable the hook on specific clients. You should **never** register the `OpenTelemetryHook` globally and on a client.
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 both the `TracingHook` and `MetricsHook` globally in most situations, but it's possible to only enable the hook on specific clients. You should **never** register these hooks both globally and on a client.

More information on hooks can be found in the [OpenFeature documentation][hook-concept].

### Register Globally

The `OpenTelemetryHook` 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.
The `TracingHook` and `MetricsHook` can both be set on the OpenFeature singleton. This will ensure that every flag evaluation will always generate the applicable telemetry signals.

```typescript
import { OpenFeature } from '@openfeature/js-sdk';
import { OpenTelemetryHook } from '@openfeature/open-telemetry-hook';
import { TracingHook } from '@openfeature/open-telemetry-hooks';

OpenFeature.addHooks(new OpenTelemetryHook());
OpenFeature.addHooks(new TracingHook());
```

### Register Per Client

The `OpenTelemetryHook` 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 am active span is available.
The `TracingHook` and `MetricsHook` can both 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 generate the applicable telemetry signals.

```typescript
import { OpenFeature } from '@openfeature/js-sdk';
import { OpenTelemetryHook } from '@openfeature/open-telemetry-hook';
import { MetricsHook } from '@openfeature/open-telemetry-hooks';

const client = OpenFeature.getClient('my-app');
client.addHooks(new OpenTelemetryHook());
client.addHooks(new MetricsHook());
```

## Development
Expand Down

0 comments on commit 85f4ba0

Please sign in to comment.