Skip to content

Commit

Permalink
Add tracing syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcardell committed Oct 5, 2024
1 parent 55f5fa3 commit 97074cb
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 8 deletions.
21 changes: 15 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)

}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 97074cb

Please sign in to comment.