From 5f78e785e5716a7ec87e5454b83db965f9a65341 Mon Sep 17 00:00:00 2001 From: alexcardell Date: Sun, 6 Oct 2024 11:15:49 +0000 Subject: [PATCH] deploy: a12deb127dc31bd91951a8c3f9e218fd68542967 --- index.html | 63 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index 795365b..003ba6a 100644 --- a/index.html +++ b/index.html @@ -86,6 +86,7 @@ + @@ -109,14 +110,14 @@

<

Installing

-
libraryDependencies += "io.cardell" %%% "flipt-sdk-server" % "0.3.0"
+        
libraryDependencies += "io.cardell" %%% "flipt-sdk-server" % "0.4.0"
 // or
 libraryDependencies ++= Seq(
-    "io.cardell" %%% "openfeature-sdk" % "0.3.0",
+    "io.cardell" %%% "openfeature-sdk" % "0.4.0",
     // for circe json variant types
-    "io.cardell" %%% "openfeature-sdk-circe" % "0.3.0",
+    "io.cardell" %%% "openfeature-sdk-circe" % "0.4.0",
     // to use flipt as a backend
-    "io.cardell" %%% "openfeature-provider-flipt" % "0.3.0"
+    "io.cardell" %%% "openfeature-provider-flipt" % "0.4.0"
 )

OpenFeature Compatibility

@@ -171,8 +172,8 @@

Installation

Using Flagd as an example:

libraryDependencies ++= Seq(
-    "io.cardell" %%% "openfeature-sdk" % "0.3.0",
-    "io.cardell" %%% "openfeature-provider-java" % "0.3.0",
+    "io.cardell" %%% "openfeature-sdk" % "0.4.0",
+    "io.cardell" %%% "openfeature-provider-java" % "0.4.0",
     "dev.openfeature.contrib.providers" % "flagd" % "0.8.9",
 )
import cats.effect.IO
@@ -221,6 +222,50 @@ 

Hooks

Hooks are work-in-progress. All four OpenFeature hook types are supported but only on the FeatureClient and Provider interfaces.

+

Hook types:

+
    +
  • BeforeHook (can optionally manipulate EvaluationContext)
  • +
  • AfterHook
  • +
  • ErrorHook
  • +
  • FinallyHook
  • +
+
import cats.effect.IO
+import io.cardell.openfeature.FeatureClient
+import io.cardell.openfeature.BeforeHook
+import io.cardell.openfeature.provider.Provider
+
+val hook = BeforeHook[IO] { case (context, hints @ _) => 
+    IO.println(s"I'm about to evaluate ${context.flagKey}").as(None)
+}
+// hook: BeforeHook[IO] = io.cardell.openfeature.BeforeHook$$anon$1@78feb6ed
+
+def providerWithHook(provider: Provider[IO]) = 
+    provider.withHook(hook)
+
+// and similarly for `client`
+def clientWithHook(client: FeatureClient[IO]) = 
+    client.withHook(hook)
+ +

otel4s

+

otel4s trace integration is provided, offering a set of trace hooks

+
import cats.effect.IO
+import org.typelevel.otel4s.trace.Tracer
+import io.cardell.openfeature.provider.EvaluationProvider
+import io.cardell.openfeature.otel4s.TracedProvider
+
+def traceExample(
+    provider: EvaluationProvider[IO]
+)(implicit T: Tracer[IO]) =
+    new TracedProvider[IO](provider)
+
+// or
+
+import io.cardell.openfeature.otel4s.syntax._
+
+def tracedProviderSyntax(
+    provider: EvaluationProvider[IO]
+)(implicit T: Tracer[IO]) =
+    provider.withTracing

Variants

Providers offer resolving a particular variant, using a Structure type. Typically this is JSON defined on the server side.

@@ -295,9 +340,9 @@

// resource: cats.effect.kernel.Resource[IO, FliptApi[IO]] = Bind( // source = Bind( // source = Eval(fa = Pure(value = ())), -// fs = org.http4s.ember.client.EmberClientBuilder$$Lambda$14099/0x000000080390f040@6ced02a9 +// fs = org.http4s.ember.client.EmberClientBuilder$$Lambda$14688/0x0000000803b3c840@6f8624b5 // ), -// fs = cats.effect.kernel.Resource$$Lambda$14100/0x000000080390e040@103ecd3d +// fs = cats.effect.kernel.Resource$$Lambda$14689/0x0000000803b3b840@1da7a299 // ) resource.use { flipt => @@ -315,7 +360,7 @@

// res3: IO[Boolean] = FlatMap( // ioe = Pure(value = ()), -// f = cats.effect.kernel.Resource$$Lambda$14102/0x000000080390c840@10ced6df, +// f = cats.effect.kernel.Resource$$Lambda$14691/0x0000000803b3a040@24effb5b, // event = cats.effect.tracing.TracingEvent$StackTrace // )