Skip to content

Commit

Permalink
Updated SemanticsConfig tests. NOTE: does not currently pass memoizat…
Browse files Browse the repository at this point in the history
…ion tests.
  • Loading branch information
evanlauer1 committed May 24, 2024
1 parent 591ac8c commit 77b4c5f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 35 deletions.
2 changes: 1 addition & 1 deletion api/hs-opentelemetry-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ test-suite hs-opentelemetry-api-test
main-is: Spec.hs
other-modules:
OpenTelemetry.BaggageSpec
OpenTelemetry.SemConvStabilityOptInSpec
OpenTelemetry.SemanticsConfigSpec
OpenTelemetry.Trace.SamplerSpec
OpenTelemetry.Trace.TraceFlagsSpec
Paths_hs_opentelemetry_api
Expand Down
3 changes: 3 additions & 0 deletions api/src/OpenTelemetry/SemanticsConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

module OpenTelemetry.SemanticsConfig (
SemanticsOptions (httpOption),
HttpOption (..),
getSemanticsOptions,
getSemanticsOptions',
) where
Expand Down Expand Up @@ -80,6 +81,8 @@ getSemanticsOptions' :: IO SemanticsOptions
getSemanticsOptions' = parseSemanticsOptions <$> lookupEnv "OTEL_SEMCONV_STABILITY_OPT_IN"


-- ! Does not pass memoization tests yet

{- | Create a new memoized IO action using an 'IORef' under the surface. Note that
the action may be run in multiple threads simultaneously, so this may not be
thread safe (depending on the underlying action). For the sake of reading an environment
Expand Down
32 changes: 0 additions & 32 deletions api/test/OpenTelemetry/SemConvStabilityOptInSpec.hs

This file was deleted.

44 changes: 44 additions & 0 deletions api/test/OpenTelemetry/SemanticsConfigSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module OpenTelemetry.SemanticsConfigSpec where

import OpenTelemetry.SemanticsConfig
import System.Environment
import Test.Hspec


envVarName :: String
envVarName = "OTEL_SEMCONV_STABILITY_OPT_IN"


spec :: Spec
spec = do
describe "SemanticsConfig" $ do
describe "HttpOption" $ do
it "defaults to 'Old' when env var has no value" $ do
unsetEnv envVarName
semanticsOptions <- getSemanticsOptions'
httpOption semanticsOptions `shouldBe` Old
mapM_
( \(envVarVal, expectedVal) ->
it ("returns " ++ show expectedVal ++ " when env var is " ++ show envVarVal) $ do
setEnv envVarName envVarVal
semanticsOptions <- getSemanticsOptions'
httpOption semanticsOptions `shouldBe` expectedVal
)
[ ("http", Stable)
, ("http/du", Old) -- intentionally similar to both "http/dup" and "http"
, ("http/dup", StableAndOld)
, ("http/dup,http", StableAndOld)
, ("http,http/dup", StableAndOld)
, ("http,something-random,http/dup", StableAndOld)
]
context "memoization" $ do
it "works" $ do
setEnv envVarName "http"
semanticsOptions <- getSemanticsOptions
httpOption semanticsOptions `shouldBe` Stable
it ("does not change when " ++ envVarName ++ " changes") $ do
setEnv envVarName "http"
semanticsOptions <- getSemanticsOptions
setEnv envVarName "http/dup"
semanticsOptions <- getSemanticsOptions
httpOption semanticsOptions `shouldBe` Stable -- and not StableAndOld because of memoization
4 changes: 2 additions & 2 deletions api/test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import OpenTelemetry.Attributes (lookupAttribute)

import qualified OpenTelemetry.BaggageSpec as Baggage
import OpenTelemetry.Context
import qualified OpenTelemetry.SemConvStabilityOptInSpec as SemConvStabilityOptIn
import qualified OpenTelemetry.SemanticsConfigSpec as SemanticsConfigSpec
import OpenTelemetry.Trace.Core
import qualified OpenTelemetry.Trace.SamplerSpec as Sampler
import qualified OpenTelemetry.Trace.TraceFlagsSpec as TraceFlags
Expand Down Expand Up @@ -55,4 +55,4 @@ main = hspec $ do
Baggage.spec
Sampler.spec
TraceFlags.spec
SemConvStabilityOptIn.spec
SemanticsConfigSpec.spec

0 comments on commit 77b4c5f

Please sign in to comment.