Skip to content

Commit bcb8cf1

Browse files
authored
feat: logging requirements and logging hook (#269)
As discussed in recent meetings, we've had complaints about this from multiple sources. This PR adds a stipulation that no logging is done by the SDK during flag evaluation. It also defines a very simple `logging hook` concept as an included utility. These should be very simple to write and will provide all the needed logging but give authors more control than built in log statements. It will also be a very nice intro to the hooks concept for users. Here's the Java implementation: open-feature/java-sdk#1084 --------- Signed-off-by: Todd Baert <[email protected]>
1 parent 464bd02 commit bcb8cf1

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

specification.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@
233233
{
234234
"id": "Requirement 1.4.11",
235235
"machine_id": "requirement_1_4_11",
236-
"content": "In the case of abnormal execution, the client SHOULD log an informative error message.",
237-
"RFC 2119 keyword": "SHOULD",
236+
"content": "Methods, functions, or operations on the client SHOULD NOT write log messages.",
237+
"RFC 2119 keyword": "SHOULD NOT",
238238
"children": []
239239
},
240240
{

specification/appendix-a-included-utilities.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This document contains requirements for auxiliary utilities provided by the SDK,
1111

1212
## In-memory provider
1313

14-
> Language-specific OpenFeature SDK implementations **SHOULD** expose an in-memory provider built into the SDK.
14+
> OpenFeature SDK implementations **SHOULD** provide an `in-memory provider`.
1515
1616
The in-memory provider is intended to be used for testing; SDK consumers may use it for their use cases.
1717
Hence, the packaging, naming, and access modifiers must be set appropriately.
@@ -360,3 +360,24 @@ Providers can contain metadata. The Multi-Provider will make that metadata avail
360360
},
361361
}
362362
```
363+
364+
## Logging Hook
365+
366+
> OpenFeature SDK implementations **SHOULD** provide a `logging hook`.
367+
368+
The logging hook is a hook which logs messages during the flag evaluation life-cycle as described below:
369+
370+
| Stage | Logged data |
371+
| ------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
372+
| before | `stage`, `domain`, `provider_name`, `flag_key`, `default_value` and `evaluation_context` (serialized, opt-in) |
373+
| after | `stage`, `domain`, `provider_name`, `flag_key`, `default_value`, `evaluation_context` (serialized, opt-in), `reason`, `variant` and `value` |
374+
| error | `stage`, `domain`, `provider_name`, `flag_key`, `default_value`, `evaluation_context` (serialized, opt-in), `error code`, and `error_message` |
375+
| finally | N/A |
376+
377+
> The evaluation context **SHOULD** only be logged if an associated option indicates so.
378+
379+
The can be a constructor option or similar, for example: `boolean printContext`.
380+
381+
> If logging the evaluation context is enabled, it **MUST** be printed in such a way that it's human readable.
382+
383+
> If the logger abstraction in the SDK supports a log level concept, the appropriate log level **SHOULD** be used for each stage (before/after: info, error: error).

specification/sections/01-flag-evaluation.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,15 @@ Configuration code includes code to set the provider, instantiate providers, and
353353

354354
#### Requirement 1.4.11
355355

356-
> In the case of abnormal execution, the client **SHOULD** log an informative error message.
356+
> Methods, functions, or operations on the client **SHOULD NOT** write log messages.
357357
358-
Implementations may define a standard logging interface that can be supplied as an optional argument to the client creation function, which may wrap standard logging functionality of the implementation language.
358+
The client methods (particularly the evaluation methods) run in hot code paths.
359+
Logging (even at error level) can cause a huge volume of log entries.
360+
For example, in a circumstance in which an application expecting a particular flag to exist is deployed in advance of that flag's being defined in the management system, logs can become inundated with `FLAG_NOT_FOUND` messages and related stack traces.
361+
Logging in these code paths is highly discouraged.
362+
Application authors can attach a [logging hook](../appendix-a-included-utilities.md#logging-hook) or author their own custom logging hook(s) to help with debugging or satisfy their particular logging needs.
363+
364+
Logging is encouraged in functions to do with configuration, initialization, shutdown, etc.
359365

360366
#### Requirement 1.4.12
361367

0 commit comments

Comments
 (0)