Skip to content

Commit

Permalink
Replaced general Settings.hs with specific SemConvStability.hs
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlauer1 committed May 20, 2024
1 parent a9520aa commit 77538ca
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 38 deletions.
2 changes: 1 addition & 1 deletion api/hs-opentelemetry-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ library
OpenTelemetry.Resource.Service
OpenTelemetry.Resource.Telemetry
OpenTelemetry.Resource.Webengine
OpenTelemetry.Settings
OpenTelemetry.SemConvStabilityOptIn
OpenTelemetry.Trace.Core
OpenTelemetry.Trace.Id
OpenTelemetry.Trace.Id.Generator
Expand Down
21 changes: 21 additions & 0 deletions api/src/OpenTelemetry/SemConvStabilityOptIn.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{-# LANGUAGE LambdaCase #-}

module OpenTelemetry.SemConvStabilityOptIn (
getSemConvStabilityOptIn,
SemConvStabilityOptIn (Stable, Both, Old),
) where

import System.Environment (lookupEnv)


data SemConvStabilityOptIn = Stable | Both | Old


getSemConvStabilityOptIn :: IO SemConvStabilityOptIn
getSemConvStabilityOptIn =
( \case
Just "http" -> Stable
Just "http/dup" -> Both
_ -> Old
)
<$> lookupEnv "OTEL_SEMCONV_STABILITY_OPT_IN"
30 changes: 0 additions & 30 deletions api/src/OpenTelemetry/Settings.hs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

module OpenTelemetry.Instrumentation.HttpClient.Raw where

Expand All @@ -19,16 +17,14 @@ import Network.HTTP.Types
import OpenTelemetry.Context (Context, lookupSpan)
import OpenTelemetry.Context.ThreadLocal
import OpenTelemetry.Propagator
import OpenTelemetry.Settings
import OpenTelemetry.SemConvStabilityOptIn
import OpenTelemetry.Trace.Core
import System.Environment


data HttpClientInstrumentationConfig = HttpClientInstrumentationConfig
{ requestName :: Maybe T.Text
, requestHeadersToRecord :: [HeaderName]
, responseHeadersToRecord :: [HeaderName]
, settings :: Settings
}


Expand Down Expand Up @@ -122,7 +118,8 @@ instrumentRequest conf ctxt req = do
(\h -> (\v -> ("http.request.header." <> T.decodeUtf8 (foldedCase h), toAttribute (T.decodeUtf8 v))) <$> lookup h (requestHeaders req))
$ requestHeadersToRecord conf

case semConvStabilityOptIn . settings $ conf of
semConvStabilityOptIn <- liftIO getSemConvStabilityOptIn
case semConvStabilityOptIn of
Stable -> addStableAttributes
Both -> addStableAttributes >> addOldAttributes
Old -> addOldAttributes
Expand Down Expand Up @@ -186,7 +183,8 @@ instrumentResponse conf ctxt resp = do
(\h -> (\v -> ("http.response.header." <> T.decodeUtf8 (foldedCase h), toAttribute (T.decodeUtf8 v))) <$> lookup h (responseHeaders resp))
$ responseHeadersToRecord conf

case semConvStabilityOptIn . settings $ conf of
semConvStabilityOptIn <- liftIO getSemConvStabilityOptIn
case semConvStabilityOptIn of
Stable -> addStableAttributes
Both -> addStableAttributes >> addOldAttributes
Old -> addOldAttributes

0 comments on commit 77538ca

Please sign in to comment.