Skip to content

Commit

Permalink
Add hook and otel4s docs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcardell committed Sep 21, 2024
1 parent 2603f23 commit a7cc6bc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ lazy val docs = project
.dependsOn(
`openfeature-sdk`.jvm,
`openfeature-sdk-circe`.jvm,
`openfeature-sdk-otel4s`.jvm,
`openfeature-provider-java`.jvm,
`openfeature-provider-flipt`.jvm
)
Expand Down
34 changes: 34 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,40 @@ def program(features: FeatureClient[IO])(
Hooks are work-in-progress. All four OpenFeature [hook types](https://openfeature.dev/specification/sections/hooks)
are supported but only on the `FeatureClient` and `Provider` interfaces.

```scala mdoc
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)
}

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

```scala mdoc
import cats.effect.IO
import org.typelevel.otel4s.trace.Tracer
import io.cardell.openfeature.FeatureClient
import io.cardell.openfeature.otel4s.TraceHooks

def tracedClient(
client: FeatureClient[IO]
)(implicit T: Tracer[IO]) = TraceHooks.ioLocal
.map(hooks => client.withHooks(hooks))
```

### Variants

Providers offer resolving a particular variant, using a Structure type. Typically this is JSON defined on the server side.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ trait FeatureClient[F[_]] {

def withHook(hook: Hook[F]): FeatureClient[F]

def withHooks(hooks: List[Hook[F]]): FeatureClient[F] =
hooks.foldLeft(this)(_ withHook _)

def getBooleanValue(flagKey: String, default: Boolean): F[Boolean]

def getBooleanValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import io.cardell.openfeature.Hook

trait Provider[F[_]] extends EvaluationProvider[F] {
def withHook(hook: Hook[F]): Provider[F]
// def withHooks(hooks: List[Hook[F]]): Provider[F]

def withHooks(hooks: List[Hook[F]]): Provider[F] =
hooks.foldLeft(this)(_ withHook _)

}

0 comments on commit a7cc6bc

Please sign in to comment.