Skip to content

Commit

Permalink
Add feature flag key attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcardell committed Sep 21, 2024
1 parent 393c8e2 commit be92fbe
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ jobs:

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: mkdir -p openfeature/provider-flipt/.jvm/target openfeature/provider-memory/.js/target flipt/sdk-server/native/target flipt/sdk-server/js/target openfeature/sdk-circe/.native/target openfeature/provider-memory/.native/target openfeature/sdk-circe/.jvm/target openfeature/provider-flipt/.native/target openfeature/sdk-circe/.js/target openfeature/sdk/.native/target openfeature/provider-memory/.jvm/target openfeature/provider-java/.jvm/target openfeature/provider-flipt/.js/target openfeature/sdk/.jvm/target openfeature/sdk/.js/target flipt/sdk-server/jvm/target project/target
run: mkdir -p openfeature/provider-flipt/.jvm/target openfeature/provider-memory/.js/target flipt/sdk-server/native/target openfeature/sdk-otel4s/.js/target flipt/sdk-server/js/target openfeature/sdk-circe/.native/target openfeature/provider-memory/.native/target openfeature/sdk-otel4s/.jvm/target openfeature/sdk-circe/.jvm/target openfeature/provider-flipt/.native/target openfeature/sdk-otel4s/.native/target openfeature/sdk-circe/.js/target openfeature/sdk/.native/target openfeature/provider-memory/.jvm/target openfeature/provider-java/.jvm/target openfeature/provider-flipt/.js/target openfeature/sdk/.jvm/target openfeature/sdk/.js/target flipt/sdk-server/jvm/target project/target

- name: Compress target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: tar cf targets.tar openfeature/provider-flipt/.jvm/target openfeature/provider-memory/.js/target flipt/sdk-server/native/target flipt/sdk-server/js/target openfeature/sdk-circe/.native/target openfeature/provider-memory/.native/target openfeature/sdk-circe/.jvm/target openfeature/provider-flipt/.native/target openfeature/sdk-circe/.js/target openfeature/sdk/.native/target openfeature/provider-memory/.jvm/target openfeature/provider-java/.jvm/target openfeature/provider-flipt/.js/target openfeature/sdk/.jvm/target openfeature/sdk/.js/target flipt/sdk-server/jvm/target project/target
run: tar cf targets.tar openfeature/provider-flipt/.jvm/target openfeature/provider-memory/.js/target flipt/sdk-server/native/target openfeature/sdk-otel4s/.js/target flipt/sdk-server/js/target openfeature/sdk-circe/.native/target openfeature/provider-memory/.native/target openfeature/sdk-otel4s/.jvm/target openfeature/sdk-circe/.jvm/target openfeature/provider-flipt/.native/target openfeature/sdk-otel4s/.native/target openfeature/sdk-circe/.js/target openfeature/sdk/.native/target openfeature/provider-memory/.jvm/target openfeature/provider-java/.jvm/target openfeature/provider-flipt/.js/target openfeature/sdk/.jvm/target openfeature/sdk/.js/target flipt/sdk-server/jvm/target project/target

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
Expand Down
1 change: 0 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ lazy val `openfeature-sdk-otel4s` = crossProject(
)
.crossType(CrossType.Pure)
.in(file("openfeature/sdk-otel4s"))
.enablePlugins(NoPublishPlugin)
.settings(commonDependencies)
.settings(
name := "openfeature-sdk-otel4s",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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

import org.typelevel.otel4s.AttributeKey

// Shim attributes until they are moved from experimental to stable
object FeatureFlagAttributes {
val FeatureFlagKey: AttributeKey[String] = AttributeKey("feature_flag.key")

/** The name of the service provider that performs the flag evaluation.
*/
val FeatureFlagProviderName: AttributeKey[String] = AttributeKey(
"feature_flag.provider_name"
)

/** SHOULD be a semantic identifier for a value. If one is unavailable, a
* stringified version of the value can be used. <p>
* @note
* <p> A semantic identifier, commonly referred to as a variant, provides a
* means for referring to a value without including the value itself. This
* can provide additional context for understanding the meaning behind a
* value. For example, the variant `red` maybe be used for the value
* `#c05543`. <p> A stringified version of the value can be used in
* situations where a semantic identifier is unavailable. String
* representation of the value should be determined by the implementer.
*/
val FeatureFlagVariant: AttributeKey[String] = AttributeKey(
"feature_flag.variant"
)

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
/*
* 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

import cats.data.OptionT
import cats.effect.IO
import cats.effect.IOLocal
import cats.syntax.all._
import org.typelevel.otel4s.Attributes
import org.typelevel.otel4s.trace.Span
import org.typelevel.otel4s.trace.StatusCode
import org.typelevel.otel4s.trace.Tracer
Expand All @@ -23,9 +40,15 @@ object TraceHooks {
private def fromIOLocal(
local: IOLocal[Option[Span[IO]]]
)(implicit T: Tracer[IO]): List[Hook[IO]] = {
val before = BeforeHook[IO] { case _ =>
import FeatureFlagAttributes._

val before = BeforeHook[IO] { case (context, _) =>
val attributes = Attributes(
FeatureFlagKey(context.flagKey)
)

Tracer[IO]
.span("resolve-flag")
.span("resolve-flag", attributes)
.startUnmanaged
.flatMap(s => local.update(_ => s.some))
.as(None)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +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

import cats.effect.IO
Expand Down Expand Up @@ -45,6 +61,10 @@ class TraceHookTest extends CatsEffectSuite {
spanName = headSpan.map(_.name)
spanStatus = headSpan.map(_.status.status)
spanEnded = headSpan.map(_.hasEnded)
spanAttrs = headSpan.map(_.attributes.elements)
flagKeyAttrExists = spanAttrs.map(
_.exists(_ == FeatureFlagAttributes.FeatureFlagKey("boolean-flag"))
)
} yield {
assertEquals(flagResult, expectedFlagResult)
assertEquals(spanCount, expectedSpanCount)
Expand Down Expand Up @@ -91,11 +111,16 @@ class TraceHookTest extends CatsEffectSuite {
spanName = headSpan.map(_.name)
spanStatus = headSpan.map(_.status.status)
spanEnded = headSpan.map(_.hasEnded)
spanAttrs = headSpan.map(_.attributes.elements)
flagKeyAttrExists = spanAttrs.map(
_.exists(_ == FeatureFlagAttributes.FeatureFlagKey("boolean-flag"))
)
} yield {
assertEquals(spanCount, expectedSpanCount)
assertEquals(spanName, Some(expectedSpanName))
assertEquals(spanStatus, Some(expectedSpanStatus))
assertEquals(spanEnded, Some(true))
assertEquals(flagKeyAttrExists, Some(true))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +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

import cats.Applicative
Expand Down

0 comments on commit be92fbe

Please sign in to comment.