Skip to content

Commit

Permalink
Merge branch 'main' into add-mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
beeme1mr authored Oct 17, 2024
2 parents 0ce8ec0 + cd99c35 commit 9aaf1f3
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 32 deletions.
65 changes: 65 additions & 0 deletions specification.json
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,13 @@
"RFC 2119 keyword": "MAY",
"children": []
},
{
"id": "Condition 2.7.1",
"machine_id": "condition_2_7_1",
"content": "The `provider` MAY define a function for tracking the occurrence of a particular user action or application state, with parameters `tracking event name` (string, required), `evaluation context` (optional) and `tracking event details` (optional) which returns nothing.",
"RFC 2119 keyword": "MAY",
"children": []
},
{
"id": "Requirement 3.1.1",
"machine_id": "requirement_3_1_1",
Expand Down Expand Up @@ -1044,6 +1051,64 @@
"content": "If the provider emits an event, the value of the client's `provider status` MUST be updated accordingly.",
"RFC 2119 keyword": "MUST",
"children": []
},
{
"id": "Condition 6.1.1",
"machine_id": "condition_6_1_1",
"content": "The implementation uses the dynamic-context paradigm.",
"RFC 2119 keyword": null,
"children": [
{
"id": "Conditional Requirement 6.1.1.1",
"machine_id": "conditional_requirement_6_1_1_1",
"content": "The `client` MUST define a function for tracking the occurrence of a particular action or application state, with parameters `tracking event name` (string, required), `evaluation context` (optional) and `tracking event details` (optional), which returns nothing.",
"RFC 2119 keyword": "MUST",
"children": []
}
]
},
{
"id": "Condition 6.1.2",
"machine_id": "condition_6_1_2",
"content": "The implementation uses the static-context paradigm.",
"RFC 2119 keyword": null,
"children": [
{
"id": "Conditional Requirement 6.1.2.1",
"machine_id": "conditional_requirement_6_1_2_1",
"content": "The `client` MUST define a function for tracking the occurrence of a particular action or application state, with parameters `tracking event name` (string, required) and `tracking event details` (optional), which returns nothing.",
"RFC 2119 keyword": "MUST",
"children": []
}
]
},
{
"id": "Requirement 6.1.3",
"machine_id": "requirement_6_1_3",
"content": "The evaluation context passed to the provider's track function MUST be merged in the order: API (global; lowest precedence) - transaction - client - invocation (highest precedence), with duplicate values being overwritten.",
"RFC 2119 keyword": "MUST",
"children": []
},
{
"id": "Requirement 6.1.4",
"machine_id": "requirement_6_1_4",
"content": "If the client's `track` function is called and the associated provider does not implement tracking, the client's `track` function MUST no-op.",
"RFC 2119 keyword": "MUST",
"children": []
},
{
"id": "Requirement 6.2.1",
"machine_id": "requirement_6_2_1",
"content": "The `tracking event details` structure MUST define an optional numeric `value`, associating a scalar quality with an `tracking event`.",
"RFC 2119 keyword": "MUST",
"children": []
},
{
"id": "Requirement 6.2.2",
"machine_id": "requirement_6_2_2",
"content": "The `tracking event details` MUST support the inclusion of custom fields, having keys of type `string`, and values of type `boolean | string | number | structure`.",
"RFC 2119 keyword": "MUST",
"children": []
}
]
}
5 changes: 5 additions & 0 deletions specification/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This document defines some terms that are used across this specification.
- [Transaction Context Propagator](#transaction-context-propagator)
- [Evaluating Flag Values](#evaluating-flag-values)
- [Resolving Flag Values](#resolving-flag-values)
- [Tracking Event](#tracking-event)
- [Flagging specifics](#flagging-specifics)
- [Flag](#flag)
- [Flag Set](#flag-set)
Expand Down Expand Up @@ -148,6 +149,10 @@ The process of retrieving a feature flag value in it's entirety, including:

The process of a provider retrieving a feature flag value from it's particular source-of-truth.

### Tracking Event

A particular user action or application state representing a business objective or outcome, identified by a unique string, and recorded using the [tracking API](./sections/06-tracking.md).

## Flagging specifics

```mermaid
Expand Down
31 changes: 31 additions & 0 deletions specification/sections/02-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,34 @@ class MyProvider implements Provider {
Providers may maintain remote connections, timers, threads or other constructs that need to be appropriately disposed of.
Provider authors may implement a `shutdown` function to perform relevant clean-up actions.
Alternatively, implementations might leverage language idioms such as auto-disposable interfaces or some means of cancellation signal propagation to allow for graceful shutdown.
### 2.7. Tracking Support
[![experimental](https://img.shields.io/static/v1?label=Status&message=experimental&color=orange)](https://github.com/open-feature/spec/tree/main/specification#experimental)
Some flag management systems support tracking functionality, which can be used to associate feature flag evaluations with subsequent user actions or application state.
See [tracking](./06-tracking.md).
#### Condition 2.7.1
> The `provider` **MAY** define a function for tracking the occurrence of a particular user action or application state, with parameters `tracking event name` (string, required), `evaluation context` (optional) and `tracking event details` (optional) which returns nothing.
```java
class MyProvider implements Tracking {
//...
/**
* Record a tracking event.
*/
void track(String trackingEventName, EvaluationContext context, TrackingEventDetails details): void;
//...
}
```
The track function is a void function (function returning nothing).
The track function performs side effects required to record the `tracking event` in question, which may include network activity or other I/O; this I/O should not block the function call.
Providers should be careful to complete any communication or flush any relevant uncommitted tracking data before they shut down.
See [shutdown](#25-shutdown).
127 changes: 95 additions & 32 deletions specification/sections/06-tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,98 @@ toc_max_heading_level: 4

## Overview

Experimentation is a primary use case for feature flags.
In practice, this often means flag variants are assigned to users at random or in accordance with a business rule, while the impact of the assigned variant on some business objective is measured.
Vendors and custom solutions often support a _tracking_ or _goal measuring_ API to facilitate the measurement of these business objectives.

### Goals

- Develop official terminology to support consistent implementation
- Specify a flexible API widely compatible with basic vendor functionality
- Define tracking event payload
- Define tracking event identifier
- Support A/B testing and experimentation use-cases
- Support client and server paradigms
- Provide recommendations around:
- Async vs sync
- Flushing mechanisms
- Event batching

### Non-goals

- Creating an experimentation platform
- Covering every user-tracking use case
- We will not define any data aggregation mechanisms
- We will not focus on "metrics", but instead, "facts"

### Design Principles

We value the following:

- Adherence to, and compatibility with OpenFeature semantics
- Maximum compatibility and ease-of-adoption for existing solutions
- Minimum traffic and payload size
- Ease-of-use for application authors, integrators, and provider authors (in that order)
The `tracking API` enables the association of feature flag evaluations with subsequent actions or application states, in order to facilitate experimentation and analysis of the impact of feature flags on business objectives.

Combined with hooks which report feature flag evaluations to the analytics platform in question, tracking can allow for robust experimentation even for flag management systems that don't support tracking directly.

```mermaid
sequenceDiagram
Evaluation API->>+Tracking Hook: evaluate
Tracking Hook->>Analytics Platform: before
Tracking Hook->>Analytics Platform: after
Tracking Hook->>-Evaluation API: evaluate
Evaluation API->>Analytics Platform: track
```

### 6.1. Tracking API

#### Condition 6.1.1

> The implementation uses the dynamic-context paradigm.
see: [dynamic-context paradigm](../glossary.md#dynamic-context-paradigm)

##### Conditional Requirement 6.1.1.1

> The `client` **MUST** define a function for tracking the occurrence of a particular action or application state, with parameters `tracking event name` (string, required), `evaluation context` (optional) and `tracking event details` (optional), which returns nothing.
```java
// example tracking event recording that a subject reached a page associated with a business goal
client.track("visited-promo-page", evaluationContext);

// example tracking event recording that a subject performed an action associated with a business goal, with the tracking event details having a particular numeric value
client.track("clicked-checkout", evaluationContext, new TrackingEventDetails(99.77));

// example tracking event recording that a subject performed an action associated with a business goal, with the tracking event details having a particular numeric value
client.track("clicked-checkout", evaluationContext, new TrackingEventDetails(99.77).add("currencyCode", "USD"));
```

See [evaluation context](../types.md#evaluation-context), [tracking event details](#62-tracking-event-details).

#### Condition 6.1.2

[![experimental](https://img.shields.io/static/v1?label=Status&message=experimental&color=orange)](https://github.com/open-feature/spec/tree/main/specification#experimental)

> The implementation uses the static-context paradigm.
see: [static-context paradigm](../glossary.md#static-context-paradigm)

##### Conditional Requirement 6.1.2.1

> The `client` **MUST** define a function for tracking the occurrence of a particular action or application state, with parameters `tracking event name` (string, required) and `tracking event details` (optional), which returns nothing.
The track function is a void function (function returning nothing).
Though it may be associated with network activity or other I/O, it need not be awaited by application authors.

```java
// example tracking event recording that a subject reached a page associated with a business goal
client.track("visited-promo-page");

// example tracking event recording that a subject performed an action associated with a business goal, with the tracking event details having a particular numeric value
client.track("clicked-checkout", new TrackingEventDetails(99.77));

// example tracking event recording that a subject performed an action associated with a business goal, with the tracking event details having a particular numeric and some additional details
client.track("clicked-checkout", new TrackingEventDetails(99.77).add("currencyCode", "USD"));
```

#### Requirement 6.1.3

> The evaluation context passed to the provider's track function **MUST** be merged in the order: API (global; lowest precedence) -> transaction -> client -> invocation (highest precedence), with duplicate values being overwritten.
The SDK passes a merged evaluation context to the provider's track function similarly to the manner it does in resolvers.

See: [context levels and merging](./03-evaluation-context.md#32-context-levels-and-merging).

#### Requirement 6.1.4

> If the client's `track` function is called and the associated provider does not implement tracking, the client's `track` function **MUST** no-op.
### 6.2. Tracking Event Details

The `tracking event details` structure defines optional data pertinent to a particular `tracking event`.

#### Requirement 6.2.1

> The `tracking event details` structure **MUST** define an optional numeric `value`, associating a scalar quality with an `tracking event`.
`Value` is a well-defined field which some providers may map to equivalent numeric values in their API.

See [provider tracking support](./02-providers.md#27-tracking-support).

#### Requirement 6.2.2

> The `tracking event details` **MUST** support the inclusion of custom fields, having keys of type `string`, and values of type `boolean | string | number | structure`.
The `tracking event details` supports the addition of arbitrary fields, including nested objects, similar to the `evaluation context` and object-typed flag values.

See [structure](../types.md#structure), [evaluation context](.//03-evaluation-context.md).
10 changes: 10 additions & 0 deletions specification/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ An enumerated error code represented idiomatically in the implementation languag
| PROVIDER_FATAL | The provider has entered an irrecoverable error state. |
| GENERAL | The error was for a reason not enumerated above. |

### Evaluation Context

See [evaluation context](./sections/03-evaluation-context.md).

### Evaluation Options

A structure containing the following fields:
Expand Down Expand Up @@ -184,3 +188,9 @@ An enumeration of provider events.

A function or method which can be associated with a `provider event`, and runs when that event occurs.
It declares an `event details` parameter.

### Tracking Event Details

A structure which supports definition of arbitrary properties, including nested objects, similar to the `evaluation context` and object-typed flag values.

See [tracking event details](./sections/06-tracking.md#62-tracking-event-details), [evaluation context](#evaluation-context).

0 comments on commit 9aaf1f3

Please sign in to comment.