hs-opentelemetry-instrumentation-http-client 0.0.1.1 → 0.0.2.0
raw patch · 2 files changed
+14/−9 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ OpenTelemetry.Instrumentation.HttpClient: [requestName] :: HttpClientInstrumentationConfig -> Maybe Text
+ OpenTelemetry.Instrumentation.HttpClient.Raw: [requestName] :: HttpClientInstrumentationConfig -> Maybe Text
+ OpenTelemetry.Instrumentation.HttpClient.Simple: [requestName] :: HttpClientInstrumentationConfig -> Maybe Text
- OpenTelemetry.Instrumentation.HttpClient: HttpClientInstrumentationConfig :: [HeaderName] -> [HeaderName] -> HttpClientInstrumentationConfig
+ OpenTelemetry.Instrumentation.HttpClient: HttpClientInstrumentationConfig :: Maybe Text -> [HeaderName] -> [HeaderName] -> HttpClientInstrumentationConfig
- OpenTelemetry.Instrumentation.HttpClient.Raw: HttpClientInstrumentationConfig :: [HeaderName] -> [HeaderName] -> HttpClientInstrumentationConfig
+ OpenTelemetry.Instrumentation.HttpClient.Raw: HttpClientInstrumentationConfig :: Maybe Text -> [HeaderName] -> [HeaderName] -> HttpClientInstrumentationConfig
- OpenTelemetry.Instrumentation.HttpClient.Simple: HttpClientInstrumentationConfig :: [HeaderName] -> [HeaderName] -> HttpClientInstrumentationConfig
+ OpenTelemetry.Instrumentation.HttpClient.Simple: HttpClientInstrumentationConfig :: Maybe Text -> [HeaderName] -> [HeaderName] -> HttpClientInstrumentationConfig
Files
- hs-opentelemetry-instrumentation-http-client.cabal +1/−1
- src/OpenTelemetry/Instrumentation/HttpClient/Raw.hs +13/−8
hs-opentelemetry-instrumentation-http-client.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: hs-opentelemetry-instrumentation-http-client-version: 0.0.1.1+version: 0.0.2.0 description: Please see the README on GitHub at <https://github.com/iand675/hs-opentelemetry/tree/main/instrumentation/http-client#readme> homepage: https://github.com/iand675/hs-opentelemetry#readme bug-reports: https://github.com/iand675/hs-opentelemetry/issues
src/OpenTelemetry/Instrumentation/HttpClient/Raw.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} module OpenTelemetry.Instrumentation.HttpClient.Raw where+import Control.Applicative ((<|>)) import Control.Monad.IO.Class import OpenTelemetry.Context (Context, lookupSpan) import OpenTelemetry.Context.ThreadLocal@@ -13,21 +14,25 @@ import qualified Data.Text.Encoding as T import Data.Foldable (Foldable(toList)) import Data.CaseInsensitive (foldedCase)+import qualified Data.Maybe data HttpClientInstrumentationConfig = HttpClientInstrumentationConfig- { requestHeadersToRecord :: [HeaderName]+ { requestName :: Maybe T.Text+ , requestHeadersToRecord :: [HeaderName] , responseHeadersToRecord :: [HeaderName] } instance Semigroup HttpClientInstrumentationConfig where l <> r = HttpClientInstrumentationConfig- { requestHeadersToRecord = requestHeadersToRecord l <> requestHeadersToRecord r+ { requestName = requestName r <|> requestName l -- flipped on purpose: last writer wins+ , requestHeadersToRecord = requestHeadersToRecord l <> requestHeadersToRecord r , responseHeadersToRecord = responseHeadersToRecord l <> responseHeadersToRecord r } instance Monoid HttpClientInstrumentationConfig where mempty = HttpClientInstrumentationConfig- { requestHeadersToRecord = mempty+ { requestName = Nothing+ , requestHeadersToRecord = mempty , responseHeadersToRecord = mempty } @@ -49,13 +54,13 @@ instrumentRequest conf ctxt req = do tp <- httpTracerProvider forM_ (lookupSpan ctxt) $ \s -> do- addAttributes s- [ ( "http.method", toAttribute $ T.decodeUtf8 $ method req)- , ( "http.url",- toAttribute $+ let url = T.decodeUtf8 ((if secure req then "https://" else "http://") <> host req <> ":" <> B.pack (show $ port req) <> path req <> queryString req)- )+ updateName s $ Data.Maybe.fromMaybe url $ requestName conf+ addAttributes s+ [ ( "http.method", toAttribute $ T.decodeUtf8 $ method req)+ , ( "http.url", toAttribute url) , ( "http.target", toAttribute $ T.decodeUtf8 (path req <> queryString req)) , ( "http.host", toAttribute $ T.decodeUtf8 $ host req) , ( "http.scheme", toAttribute $ TextAttribute $ if secure req then "https" else "http")