forked from iand675/hs-opentelemetry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from herp-inc/hedis-hook
フック版 Hedis インスツルメンテーション
- Loading branch information
Showing
12 changed files
with
320 additions
and
634 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
import Control.Exception (bracket) | ||
import Control.Monad (void) | ||
import Control.Monad.IO.Class (liftIO) | ||
import Database.Redis (connect, defaultConnectInfo, get, runRedis, set) | ||
import OpenTelemetry.Instrumentation.Hedis (appendHooksToConnectionInfo) | ||
import OpenTelemetry.Trace (defaultSpanArguments, inSpan, initializeTracerProvider, makeTracer, shutdownTracerProvider, tracerOptions) | ||
import System.IO (hFlush, stdout) | ||
|
||
|
||
main :: IO () | ||
main = | ||
bracket | ||
initializeTracerProvider | ||
shutdownTracerProvider | ||
$ \tracerProvider -> do | ||
let tracer = makeTracer tracerProvider "main" tracerOptions | ||
inSpan tracer "main" defaultSpanArguments $ do | ||
connInfo <- appendHooksToConnectionInfo tracerProvider defaultConnectInfo | ||
connection <- connect connInfo | ||
runRedis connection $ do | ||
void $ set "hello" "hello" | ||
void $ set "world" "world" | ||
hello <- get "hello" | ||
world <- get "world" | ||
liftIO $ print (hello, world) | ||
putStr "Press enter to exit after while..." | ||
hFlush stdout | ||
void $ getLine -- wait for transporting spans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
cabal-version: 3.4 | ||
|
||
name: hedis-example | ||
version: 0.0.0 | ||
build-type: Simple | ||
|
||
common common | ||
ghc-options: -threaded | ||
-with-rtsopts=-N | ||
-Wall | ||
-Wcompat | ||
-Widentities | ||
-Wincomplete-record-updates | ||
-Wincomplete-uni-patterns | ||
-Wmissing-export-lists | ||
-Wmissing-exported-signatures | ||
-Wmissing-home-modules | ||
-Wmissing-export-lists | ||
-Wmonomorphism-restriction | ||
-Wno-name-shadowing | ||
-Wpartial-fields | ||
-Wredundant-constraints | ||
-Wunused-packages | ||
if impl(ghc >= 9.0) | ||
ghc-options: -Winvalid-haddock | ||
if impl(ghc >= 9.2) | ||
ghc-options: -Wmissing-kind-signatures | ||
-Woperator-whitespace | ||
-Wredundant-bang-patterns | ||
default-language: Haskell2010 | ||
|
||
executable hedis-client | ||
import: common | ||
main-is: client.hs | ||
hs-source-dirs: . | ||
build-depends: base, | ||
hedis, | ||
hs-opentelemetry-sdk, | ||
hs-opentelemetry-instrumentation-hedis | ||
|
||
executable hedis-pubsub | ||
import: common | ||
main-is: pubsub.hs | ||
hs-source-dirs: . | ||
build-depends: base, | ||
hedis, | ||
hs-opentelemetry-sdk, | ||
hs-opentelemetry-instrumentation-hedis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
import Control.Concurrent (forkIO) | ||
import Control.Exception (bracket) | ||
import Control.Monad (void) | ||
import Control.Monad.IO.Class (liftIO) | ||
import Database.Redis | ||
import OpenTelemetry.Instrumentation.Hedis (appendHooksToConnectionInfo) | ||
import qualified OpenTelemetry.Trace as Otel | ||
import System.IO (hFlush, stdout) | ||
|
||
|
||
main :: IO () | ||
main = | ||
bracket | ||
Otel.initializeTracerProvider | ||
Otel.shutdownTracerProvider | ||
$ \tracerProvider -> do | ||
let tracer = Otel.makeTracer tracerProvider "hedis-pubsub" Otel.tracerOptions | ||
connInfo <- appendHooksToConnectionInfo tracerProvider defaultConnectInfo | ||
connection <- connect connInfo | ||
void $ forkIO $ Otel.inSpan tracer "single-thread" Otel.defaultSpanArguments $ do | ||
runRedis connection $ | ||
pubSub (subscribe ["hello"]) $ \message -> do | ||
Otel.inSpan tracer "single-thread callback" Otel.defaultSpanArguments $ do | ||
putStrLn $ "single-thread: received: " ++ show message | ||
pure mempty | ||
void $ forkIO $ Otel.inSpan tracer "multithread" Otel.defaultSpanArguments $ do | ||
controller <- newPubSubController [("hello", helloMessageCallback tracer)] [] | ||
pubSubForever connection controller $ do | ||
putStrLn "subscribed acknowledged" | ||
liftIO $ do | ||
putStrLn "Press enter to publish a message..." | ||
hFlush stdout | ||
void $ getLine -- wait for subscribing | ||
Otel.inSpan tracer "publish" Otel.defaultSpanArguments $ do | ||
runRedis connection $ do | ||
void $ publish "hello" "world" | ||
putStrLn "Press enter to exit after while..." | ||
hFlush stdout | ||
void $ getLine -- wait for transporting spans | ||
|
||
|
||
helloMessageCallback :: Otel.Tracer -> MessageCallback | ||
helloMessageCallback tracer message = do | ||
Otel.inSpan tracer "multithread callback" Otel.defaultSpanArguments $ do | ||
putStrLn $ "multithread: receive: " ++ show message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.