Skip to content

Commit 0a8a6ff

Browse files
committed
feat: tracking
Signed-off-by: Todd Baert <[email protected]>
1 parent 464bd02 commit 0a8a6ff

File tree

5 files changed

+165
-32
lines changed

5 files changed

+165
-32
lines changed

specification.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,13 @@
508508
"RFC 2119 keyword": "MAY",
509509
"children": []
510510
},
511+
{
512+
"id": "Condition 2.7.1",
513+
"machine_id": "condition_2_7_1",
514+
"content": "The `provider` MAY define a function for tracking the occurrence of a particular user action or application state, with parameters `occurrence key` (string, required), `evaluation context` (optional) and `occurrence details` (optional) which returns nothing.",
515+
"RFC 2119 keyword": "MAY",
516+
"children": []
517+
},
511518
{
512519
"id": "Requirement 3.1.1",
513520
"machine_id": "requirement_3_1_1",
@@ -1044,6 +1051,43 @@
10441051
"content": "If the provider emits an event, the value of the client's `provider status` MUST be updated accordingly.",
10451052
"RFC 2119 keyword": "MUST",
10461053
"children": []
1054+
},
1055+
{
1056+
"id": "Condition 6.1.1",
1057+
"machine_id": "condition_6_1_1",
1058+
"content": "The implementation uses the dynamic-context paradigm.",
1059+
"RFC 2119 keyword": null,
1060+
"children": [
1061+
{
1062+
"id": "Conditional Requirement 6.1.1.1",
1063+
"machine_id": "conditional_requirement_6_1_1_1",
1064+
"content": "The `client` MUST define a function for tracking the occurrence of a particular action or application state, with parameters `occurrence key` (string, required), `evaluation context` (optional) and `occurrence details` (optional) which returns nothing.",
1065+
"RFC 2119 keyword": "MUST",
1066+
"children": []
1067+
}
1068+
]
1069+
},
1070+
{
1071+
"id": "Condition 6.1.2",
1072+
"machine_id": "condition_6_1_2",
1073+
"content": "The implementation uses the static-context paradigm.",
1074+
"RFC 2119 keyword": null,
1075+
"children": [
1076+
{
1077+
"id": "Conditional Requirement 6.1.2.1",
1078+
"machine_id": "conditional_requirement_6_1_2_1",
1079+
"content": "The `client` MUST define a function for tracking the occurrence of a particular action or application state, with parameters `occurrence key` (string, required) and `occurrence details` (optional) which returns nothing.",
1080+
"RFC 2119 keyword": "MUST",
1081+
"children": []
1082+
}
1083+
]
1084+
},
1085+
{
1086+
"id": "Requirement 6.1.3",
1087+
"machine_id": "requirement_6_1_3",
1088+
"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.",
1089+
"RFC 2119 keyword": "MUST",
1090+
"children": []
10471091
}
10481092
]
10491093
}

specification/glossary.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ This document defines some terms that are used across this specification.
4545
- [Targeting Key](#targeting-key)
4646
- [Fractional Evaluation](#fractional-evaluation)
4747
- [Rule](#rule)
48+
- [Tracking Occurrence](#tracking-occurrence)
4849
- [SDK Paradigms](#sdk-paradigms)
4950
- [Dynamic-Context Paradigm](#dynamic-context-paradigm)
5051
- [Static-Context Paradigm](#static-context-paradigm)
@@ -195,6 +196,10 @@ Pseudorandomly resolve flag values using a context property, such as a targeting
195196

196197
A rule is some criteria that's used to determine which variant a particular context should be mapped to.
197198

199+
### Tracking Occurrence
200+
201+
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).
202+
198203
## SDK Paradigms
199204

200205
Feature flag frameworks have SDKs which operate in two distinct paradigms: those designed for use with a single user client application (e.g. mobile phones, single-page web apps), and those designed for multi-user applications, such as web server applications. Some parts of the OpenFeature specification diverge depending on the paradigm.

specification/sections/02-providers.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,34 @@ class MyProvider implements Provider {
256256
Providers may maintain remote connections, timers, threads or other constructs that need to be appropriately disposed of.
257257
Provider authors may implement a `shutdown` function to perform relevant clean-up actions.
258258
Alternatively, implementations might leverage language idioms such as auto-disposable interfaces or some means of cancellation signal propagation to allow for graceful shutdown.
259+
260+
### 2.7. Tracking Support
261+
262+
[![experimental](https://img.shields.io/static/v1?label=Status&message=experimental&color=orange)](https://github.com/open-feature/spec/tree/main/specification#experimental)
263+
264+
Some flag management systems support tracking functionality, which associates feature flag evaluations with subsequent user actions or application state.
265+
266+
See [tracking](./06-tracking.md).
267+
268+
#### Condition 2.7.1
269+
270+
> The `provider` **MAY** define a function for tracking the occurrence of a particular user action or application state, with parameters `occurrence key` (string, required), `evaluation context` (optional) and `occurrence details` (optional) which returns nothing.
271+
272+
```java
273+
class MyProvider implements Tracking {
274+
//...
275+
276+
/**
277+
* Record a tracking occurrence.
278+
*/
279+
void track(String occurrenceKey, OccurrenceDetails details, EvaluationContext context): void;
280+
281+
//...
282+
}
283+
```
284+
285+
The track function is a void function (function returning nothing).
286+
The track function performs side effects required to record the `occurrence` in question, which may include network activity or other I/O; this I/O should not block the function call.
287+
Providers should be careful to complete any communication or flush any relevant uncommitted tracking data before they shut down.
288+
289+
See [shutdown](#25-shutdown).

specification/sections/06-tracking.md

Lines changed: 77 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,80 @@ toc_max_heading_level: 4
1010

1111
## Overview
1212

13-
Experimentation is a primary use case for feature flags.
14-
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.
15-
Vendors and custom solutions often support a _tracking_ or _goal measuring_ API to facilitate the measurement of these business objectives.
16-
17-
### Goals
18-
19-
- Develop official terminology to support consistent implementation
20-
- Specify a flexible API widely compatible with basic vendor functionality
21-
- Define tracking event payload
22-
- Define tracking event identifier
23-
- Support A/B testing and experimentation use-cases
24-
- Support client and server paradigms
25-
- Provide recommendations around:
26-
- Async vs sync
27-
- Flushing mechanisms
28-
- Event batching
29-
30-
### Non-goals
31-
32-
- Creating an experimentation platform
33-
- Covering every user-tracking use case
34-
- We will not define any data aggregation mechanisms
35-
- We will not focus on "metrics", but instead, "facts"
36-
37-
### Design Principles
38-
39-
We value the following:
40-
41-
- Adherence to, and compatibility with OpenFeature semantics
42-
- Maximum compatibility and ease-of-adoption for existing solutions
43-
- Minimum traffic and payload size
44-
- Ease-of-use for application authors, integrators, and provider authors (in that order)
13+
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.
14+
15+
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.
16+
17+
```mermaid
18+
sequenceDiagram
19+
Evaluation API->>+Tracking Hook: evaluate
20+
Tracking Hook->>Analytics Platform: before
21+
Tracking Hook->>Analytics Platform: after
22+
Tracking Hook->>-Evaluation API: evaluate
23+
Evaluation API->>Analytics Platform: track
24+
```
25+
26+
### 6.1. Tracking API
27+
28+
#### Condition 6.1.1
29+
30+
> The implementation uses the dynamic-context paradigm.
31+
32+
see: [dynamic-context paradigm](../glossary.md#dynamic-context-paradigm)
33+
34+
##### Conditional Requirement 6.1.1.1
35+
36+
> The `client` **MUST** define a function for tracking the occurrence of a particular action or application state, with parameters `occurrence key` (string, required), `evaluation context` (optional) and `occurrence details` (optional) which returns nothing.
37+
38+
```java
39+
// example tracking occurrence recording that a subject reached a page associated with a business goal
40+
client.track("visited-promo-page", evaluationContext);
41+
42+
// example tracking occurrence recording that a subject performed an action associated with a business goal, with the occurrence details having a particular numeric value
43+
client.track("clicked-checkout", evaluationContext, new OccurrenceDetails(99.77)): void;
44+
```
45+
46+
See [evaluation context](../types.md#evaluation-context), [occurrence details](#62-occurrence-details).
47+
48+
#### Condition 6.1.2
49+
50+
[![experimental](https://img.shields.io/static/v1?label=Status&message=experimental&color=orange)](https://github.com/open-feature/spec/tree/main/specification#experimental)
51+
52+
> The implementation uses the static-context paradigm.
53+
54+
see: [static-context paradigm](../glossary.md#static-context-paradigm)
55+
56+
##### Conditional Requirement 6.1.2.1
57+
58+
> The `client` **MUST** define a function for tracking the occurrence of a particular action or application state, with parameters `occurrence key` (string, required) and `occurrence details` (optional) which returns nothing.
59+
60+
The track function is a void function (function returning nothing).
61+
Though it may be associated with network activity or other I/O, it need not be awaited by application authors.
62+
63+
```java
64+
// example tracking occurrence recording that a subject reached a page associated with a business goal
65+
client.track("visited-promo-page");
66+
67+
// example tracking occurrence recording that a subject performed an action associated with a business goal, with the occurrence details having a particular numeric value
68+
client.track("clicked-checkout", new OccurrenceDetails(99.77)): void;
69+
```
70+
71+
#### Requirement 6.1.3
72+
73+
> If the client's `track` function is called and the associated provider does not implement tracking, the client's `track` function **MUST** no-op.
74+
75+
## 6.2. Occurrence Details
76+
77+
The `occurrence details` structure defines optional data pertinent to a particular `occurrence`.
78+
79+
### Requirement 6.2.1
80+
81+
> The `occurrence details` structure **MUST** define an optional numeric `value`, associating a scalar quality with an `occurrence`.
82+
83+
`Value` is a well-defined field which some providers may map to equivalent numeric values in their API.
84+
85+
See [provider tracking support](./02-providers.md#27-tracking-support).
86+
87+
### Requirement 6.2.2
88+
89+
> The `occurrence details` **MUST** support the inclusion of custom fields, having keys of type `string`, and values of type `boolean | string | number`.

specification/types.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ An enumerated error code represented idiomatically in the implementation languag
113113
| PROVIDER_FATAL | The provider has entered an irrecoverable error state. |
114114
| GENERAL | The error was for a reason not enumerated above. |
115115

116+
### Evaluation Context
117+
118+
See [evaluation context](./sections/03-evaluation-context.md).
119+
116120
### Evaluation Options
117121

118122
A structure containing the following fields:
@@ -184,3 +188,7 @@ An enumeration of provider events.
184188

185189
A function or method which can be associated with a `provider event`, and runs when that event occurs.
186190
It declares an `event details` parameter.
191+
192+
### Occurrence Details
193+
194+
See [occurrence details](./sections/06-tracking.md#62-occurrence-details).\

0 commit comments

Comments
 (0)