open-feature / python-sdk-contrib

Community contributions for hooks and reference providers in python
https://openfeature.dev
11 stars 11 forks source link

Add OTel Hook #7

Closed toddbaert closed 1 year ago

toddbaert commented 1 year ago

Now that OTel 2529 is merged, we should implement the Open Telemetry hook.

Basically, this would entail creating a hook which:

In pseudocode, this looks something like:

class OTelHook implements Hook {
  after(context, details) {
    var currentTrace = trace.getActiveSpan();
    currentTrace.addEvent("feature_flag", { "feature_flag.key": details.key, /*  other props */ } );
  }

  error(err) {
    var currentTrace = trace.getActiveSpan();
    currentTrace.recordException(err);
  }
}

See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/feature-flags.md