packages feed

opentelemetry-wai (empty) → 0.2.0

raw patch · 3 files changed

+95/−0 lines, 3 filesdep +basedep +http-typesdep +opentelemetry

Dependencies added: base, http-types, opentelemetry, text, wai

Files

+ LICENSE view
@@ -0,0 +1,7 @@+Copyright 2020-present Dmitry Ivanov++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.
+ opentelemetry-wai.cabal view
@@ -0,0 +1,60 @@+cabal-version:       2.4+name:                opentelemetry-wai+description:         OpenTelemetry middleware for wai+category:            OpenTelemetry+version:             0.2.0+license-file:        LICENSE+license:             Apache-2.0+author:              Dmitry Ivanov+maintainer:          ethercrow@gmail.com+build-type:          Simple++source-repository head+  type: git+  location: https://github.com/ethercrow/opentelemetry-haskell++common options+  default-language: Haskell2010+  default-extensions:+    BangPatterns+    BlockArguments+    DataKinds+    DeriveGeneric+    DerivingStrategies+    DerivingVia+    FlexibleInstances+    InstanceSigs+    LambdaCase+    MultiParamTypeClasses+    MultiWayIf+    NamedFieldPuns+    NumericUnderscores+    RecordWildCards+    ScopedTypeVariables+    TupleSections+    TypeApplications+    ViewPatterns+  ghc-options:+    -Wall+    -Wcompat+    -Widentities+    -Wincomplete-record-updates+    -Wincomplete-uni-patterns+    -Wpartial-fields+    -Wredundant-constraints+    -fhide-source-paths+    -ferror-spans+    -freverse-errors++library+  import: options+  build-depends:+    base >= 4.12 && < 5,+    opentelemetry,+    http-types,+    text,+    wai+  hs-source-dirs: src+  exposed-modules:+    OpenTelemetry.Network.Wai.Middleware+
+ src/OpenTelemetry/Network/Wai/Middleware.hs view
@@ -0,0 +1,28 @@+{-# LANGUAGE OverloadedStrings #-}++module OpenTelemetry.Network.Wai.Middleware where++import qualified Data.Text as T+import qualified Data.Text.Encoding as T+import Network.HTTP.Types+import Network.Wai+import OpenTelemetry.Implicit+import OpenTelemetry.Propagation++-- Semantic conventions for HTTP spans:+-- https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-http.md++middleware :: Application -> Application+middleware app = \req sendResp -> do+  withSpan "WAI handler" $ do+    case extractSpanContextFromHeaders (requestHeaders req) of+      Just ctx -> setParentSpanContext ctx+      _ -> pure ()+    setTag "span.kind" ("server" :: T.Text)+    setTag "component" ("http" :: T.Text)+    setTag "http.method" $ T.decodeUtf8 (requestMethod req)+    setTag "http.target" $ T.decodeUtf8 (rawPathInfo req)+    setTag "http.flavor" $ show (httpVersion req)+    app req $ \resp -> do+      setTag "http.status_code" (statusCode $ responseStatus resp)+      sendResp resp