diff --git a/docs/index.md b/docs/index.md index 4ea14d5..afcc87a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -142,13 +142,22 @@ def clientWithHook(client: FeatureClient[IO]) = ```scala mdoc import cats.effect.IO import org.typelevel.otel4s.trace.Tracer -import io.cardell.openfeature.FeatureClient -import io.cardell.openfeature.otel4s.TraceHooks +import io.cardell.openfeature.provider.EvaluationProvider +import io.cardell.openfeature.otel4s.TracedProvider + +def tracedProvider( + provider: EvaluationProvider[IO] +)(implicit T: Tracer[IO]) = + new TracedProvider[IO](provider) + +// or + +import io.cardell.openfeature.otel4s.syntax._ -def tracedClient( - client: FeatureClient[IO] -)(implicit T: Tracer[IO]) = TraceHooks.ioLocal - .map(hooks => client.withHooks(hooks)) +def tracedProvider( + provider: EvaluationProvider[IO] +)(implicit T: Tracer[IO]) = + provider.withTracing ``` ### Variants diff --git a/openfeature/sdk-otel4s/src/main/scala/io/cardell/openfeature/otel4s/TracedProvider.scala b/openfeature/sdk-otel4s/src/main/scala/io/cardell/openfeature/otel4s/TracedProvider.scala index 24d3e5f..5d212dd 100644 --- a/openfeature/sdk-otel4s/src/main/scala/io/cardell/openfeature/otel4s/TracedProvider.scala +++ b/openfeature/sdk-otel4s/src/main/scala/io/cardell/openfeature/otel4s/TracedProvider.scala @@ -28,12 +28,11 @@ import io.cardell.openfeature.otel4s.FeatureFlagAttributes.FeatureFlagKey import io.cardell.openfeature.otel4s.FeatureFlagAttributes.FeatureFlagProviderName import io.cardell.openfeature.otel4s.FeatureFlagAttributes.FeatureFlagVariant import io.cardell.openfeature.provider.EvaluationProvider -import io.cardell.openfeature.provider.Provider import io.cardell.openfeature.provider.ProviderMetadata import io.cardell.openfeature.provider.ResolutionDetails class TracedProvider[F[_]: Tracer: MonadThrow]( - provider: Provider[F] + provider: EvaluationProvider[F] ) extends EvaluationProvider[F] { override def metadata: ProviderMetadata = provider.metadata diff --git a/openfeature/sdk-otel4s/src/main/scala/io/cardell/openfeature/otel4s/syntax/EvaluationProviderSyntax.scala b/openfeature/sdk-otel4s/src/main/scala/io/cardell/openfeature/otel4s/syntax/EvaluationProviderSyntax.scala new file mode 100644 index 0000000..429237b --- /dev/null +++ b/openfeature/sdk-otel4s/src/main/scala/io/cardell/openfeature/otel4s/syntax/EvaluationProviderSyntax.scala @@ -0,0 +1,37 @@ +/* + * Copyright 2023 Alex Cardell + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.cardell.openfeature.otel4s.syntax + +import cats.MonadThrow +import org.typelevel.otel4s.trace.Tracer + +import io.cardell.openfeature.otel4s.TracedProvider +import io.cardell.openfeature.provider.EvaluationProvider + +class EvaluationProviderOps[F[_]: Tracer: MonadThrow]( + provider: EvaluationProvider[F] +) { + def withTracing: EvaluationProvider[F] = new TracedProvider[F](provider) +} + +trait EvaluationProviderSyntax { + + implicit def ops[F[_]: Tracer: MonadThrow]( + provider: EvaluationProvider[F] + ): EvaluationProviderOps[F] = new EvaluationProviderOps[F](provider) + +} diff --git a/openfeature/sdk-otel4s/src/main/scala/io/cardell/openfeature/otel4s/syntax/package.scala b/openfeature/sdk-otel4s/src/main/scala/io/cardell/openfeature/otel4s/syntax/package.scala new file mode 100644 index 0000000..5391aba --- /dev/null +++ b/openfeature/sdk-otel4s/src/main/scala/io/cardell/openfeature/otel4s/syntax/package.scala @@ -0,0 +1,19 @@ +/* + * Copyright 2023 Alex Cardell + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.cardell.openfeature.otel4s + +package object syntax extends EvaluationProviderSyntax