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.
- Loading branch information
Showing
15 changed files
with
576 additions
and
27 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,65 @@ | ||
cabal-version: 2.4 | ||
|
||
name: hdbc-mysql-example | ||
version: 0.0.0.0 | ||
author: Kazuki Okamoto (岡本和樹) | ||
maintainer: kazuki.okamoto@herp.co.jp | ||
|
||
common common | ||
build-depends: base >= 4 && < 5 | ||
ghc-options: -Wall | ||
if impl(ghc >= 8.0) | ||
ghc-options: -Wcompat | ||
default-language: Haskell2010 | ||
|
||
executable hdbc-mysql-example | ||
import: common | ||
hs-source-dirs: . | ||
main-is: main.hs | ||
build-depends: hs-opentelemetry-sdk, | ||
hs-opentelemetry-instrumentation-HDBC-mysql, | ||
HDBC, | ||
ghc-options: -threaded | ||
-with-rtsopts=-N | ||
-Wno-name-shadowing | ||
if impl(ghc >= 6.4) | ||
ghc-options: -Wincomplete-record-updates | ||
if impl(ghc >= 6.8) | ||
ghc-options: -Wmonomorphism-restriction | ||
if impl(ghc >= 7.0) | ||
ghc-options: -Wmissing-import-lists | ||
if impl(ghc >= 7.2) | ||
ghc-options: -Wincomplete-uni-patterns | ||
-Widentities | ||
if impl(ghc >= 8.0) | ||
ghc-options: -Wmissing-exported-signatures | ||
-Wredundant-constraints | ||
if impl(ghc >= 8.2) | ||
ghc-options: -Wmissing-home-modules | ||
if impl(ghc >= 8.4) | ||
ghc-options: -Wmissing-export-lists | ||
-Wpartial-fields | ||
if impl(ghc >= 8.8) | ||
ghc-options: -Wmissing-deriving-strategies | ||
if impl(ghc >= 8.10) | ||
ghc-options: -Wunused-packages | ||
if impl(ghc >= 9.0) | ||
ghc-options: -Winvalid-haddock | ||
if impl(ghc >= 9.2) | ||
ghc-options: -Wambiguous-fields | ||
-Wmissing-kind-signatures | ||
-Woperator-whitespace | ||
-Wredundant-bang-patterns | ||
if impl(ghc >= 9.4) | ||
ghc-options: -Wredundant-strictness-flags | ||
-Wforall-identifier | ||
-Woperator-whitespace-ext-conflict | ||
if impl(ghc >= 9.4.1) | ||
ghc-options: -Wgadt-mono-local-binds | ||
-Wtype-equality-out-of-scope | ||
-Wtype-equality-requires-operators | ||
if impl(ghc >= 9.6.1) | ||
-- ghc-options: -Wloopy-superclass-solve | ||
-- Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/24071 | ||
if impl(ghc >= 9.8.1) | ||
ghc-options: -Wincomplete-export-warnings |
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,37 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
import Control.Exception (bracket) | ||
import Control.Monad (void) | ||
import Database.HDBC (commit, disconnect, run) | ||
import OpenTelemetry.Instrumentation.HDBC.MySQL (connectMySQL, defaultMySQLConnectInfo) | ||
import OpenTelemetry.Trace ( | ||
defaultSpanArguments, | ||
inSpan, | ||
initializeTracerProvider, | ||
makeTracer, | ||
shutdownTracerProvider, | ||
tracerOptions, | ||
) | ||
import System.IO (hFlush, stdout) | ||
|
||
|
||
main :: IO () | ||
main = do | ||
bracket | ||
initializeTracerProvider | ||
shutdownTracerProvider | ||
$ \tracerProvider -> do | ||
bracket | ||
(connectMySQL tracerProvider mempty defaultMySQLConnectInfo) | ||
disconnect | ||
$ \connection -> do | ||
let tracer = makeTracer tracerProvider "hdbc-mysql-example" tracerOptions | ||
inSpan tracer "create" defaultSpanArguments $ do | ||
void $ run connection "CREATE TABLE test (id INTEGER PRIMARY KEY)" [] | ||
commit connection | ||
inSpan tracer "drop" defaultSpanArguments $ do | ||
void $ run connection "DROP TABLE test" [] | ||
commit connection | ||
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
64 changes: 64 additions & 0 deletions
64
instrumentation/hdbc-mysql/hs-opentelemetry-instrumentation-HDBC-mysql.cabal
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,64 @@ | ||
cabal-version: 2.4 | ||
|
||
name: hs-opentelemetry-instrumentation-HDBC-mysql | ||
version: 0.0.0.0 | ||
author: Kazuki Okamoto (岡本和樹) | ||
maintainer: kazuki.okamoto@herp.co.jp | ||
|
||
common common | ||
build-depends: base >= 4 && < 5 | ||
ghc-options: -Wall | ||
if impl(ghc >= 8.0) | ||
ghc-options: -Wcompat | ||
default-language: Haskell2010 | ||
|
||
library | ||
import: common | ||
hs-source-dirs: src | ||
exposed-modules: OpenTelemetry.Instrumentation.HDBC.MySQL | ||
build-depends: hs-opentelemetry-api, | ||
hs-opentelemetry-instrumentation-HDBC, | ||
HDBC-mysql, | ||
text, | ||
ghc-options: -Wno-name-shadowing | ||
if impl(ghc >= 6.4) | ||
ghc-options: -Wincomplete-record-updates | ||
if impl(ghc >= 6.8) | ||
ghc-options: -Wmonomorphism-restriction | ||
if impl(ghc >= 7.0) | ||
ghc-options: -Wmissing-import-lists | ||
if impl(ghc >= 7.2) | ||
ghc-options: -Wincomplete-uni-patterns | ||
-Widentities | ||
if impl(ghc >= 8.0) | ||
ghc-options: -Wmissing-exported-signatures | ||
-Wredundant-constraints | ||
if impl(ghc >= 8.2) | ||
ghc-options: -Wmissing-home-modules | ||
if impl(ghc >= 8.4) | ||
ghc-options: -Wmissing-export-lists | ||
-Wpartial-fields | ||
if impl(ghc >= 8.8) | ||
ghc-options: -Wmissing-deriving-strategies | ||
if impl(ghc >= 8.10) | ||
ghc-options: -Wunused-packages | ||
if impl(ghc >= 9.0) | ||
ghc-options: -Winvalid-haddock | ||
if impl(ghc >= 9.2) | ||
ghc-options: -Wambiguous-fields | ||
-Wmissing-kind-signatures | ||
-Woperator-whitespace | ||
-Wredundant-bang-patterns | ||
if impl(ghc >= 9.4) | ||
ghc-options: -Wredundant-strictness-flags | ||
-Wforall-identifier | ||
-Woperator-whitespace-ext-conflict | ||
if impl(ghc >= 9.4.1) | ||
ghc-options: -Wgadt-mono-local-binds | ||
-Wtype-equality-out-of-scope | ||
-Wtype-equality-requires-operators | ||
if impl(ghc >= 9.6.1) | ||
-- ghc-options: -Wloopy-superclass-solve | ||
-- Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/24071 | ||
if impl(ghc >= 9.8.1) | ||
ghc-options: -Wincomplete-export-warnings |
52 changes: 52 additions & 0 deletions
52
instrumentation/hdbc-mysql/src/OpenTelemetry/Instrumentation/HDBC/MySQL.hs
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,52 @@ | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module OpenTelemetry.Instrumentation.HDBC.MySQL ( | ||
Orig.MySQLConnectInfo (..), | ||
Otel.Connection, | ||
connectMySQL, | ||
Orig.defaultMySQLConnectInfo, | ||
Orig.withRTSSignalsBlocked, | ||
) where | ||
|
||
import qualified Data.Text as Text | ||
import qualified Database.HDBC.MySQL as Orig | ||
import qualified OpenTelemetry.Attribute as Attr | ||
import qualified OpenTelemetry.Attribute.Attributes as Attr | ||
import qualified OpenTelemetry.Attribute.Key as Attr | ||
import qualified OpenTelemetry.Instrumentation.HDBC as Otel | ||
import qualified OpenTelemetry.Trace.Core as Otel | ||
|
||
|
||
connectMySQL :: Otel.TracerProvider -> Attr.Attributes -> Orig.MySQLConnectInfo -> IO Otel.Connection | ||
connectMySQL | ||
tracerProvider | ||
extraAttributes | ||
connectInfo@Orig.MySQLConnectInfo | ||
{ Orig.mysqlHost | ||
, Orig.mysqlUser | ||
, Orig.mysqlDatabase | ||
, Orig.mysqlPort | ||
, Orig.mysqlUnixSocket | ||
} = do | ||
connection <- Orig.connectMySQL connectInfo | ||
let port :: Maybe Word | ||
transport :: Text.Text | ||
(port, transport) = | ||
if null mysqlUnixSocket | ||
then (Just $ fromIntegral mysqlPort, "tcp") | ||
else (Nothing, "unix") | ||
attributes = | ||
Otel.Attributes | ||
{ Otel.db_connectionString = Nothing | ||
, Otel.db_system = "mysql" | ||
, Otel.db_user = Just $ Text.pack mysqlUser | ||
, Otel.network_peer_address = Just $ Text.pack mysqlHost | ||
, Otel.network_peer_port = port | ||
, Otel.network_transport = Just transport | ||
, Otel.network_type = Nothing | ||
, Otel.server_address = Just $ Text.pack mysqlHost | ||
, Otel.server_port = port | ||
} | ||
extraAttributes' = Attr.insert Attr.db_name (Text.pack mysqlDatabase) extraAttributes | ||
pure $ Otel.makeConnection connection tracerProvider attributes extraAttributes' |
64 changes: 64 additions & 0 deletions
64
instrumentation/hdbc/hs-opentelemetry-instrumentation-HDBC.cabal
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,64 @@ | ||
cabal-version: 2.4 | ||
|
||
name: hs-opentelemetry-instrumentation-HDBC | ||
version: 0.0.0.0 | ||
author: Kazuki Okamoto (岡本和樹) | ||
maintainer: kazuki.okamoto@herp.co.jp | ||
|
||
common common | ||
build-depends: base >= 4 && < 5 | ||
ghc-options: -Wall | ||
if impl(ghc >= 8.0) | ||
ghc-options: -Wcompat | ||
default-language: Haskell2010 | ||
|
||
library | ||
import: common | ||
hs-source-dirs: src | ||
exposed-modules: OpenTelemetry.Instrumentation.HDBC | ||
build-depends: hs-opentelemetry-api, | ||
HDBC, | ||
data-default-class, | ||
text | ||
ghc-options: -Wno-name-shadowing | ||
if impl(ghc >= 6.4) | ||
ghc-options: -Wincomplete-record-updates | ||
if impl(ghc >= 6.8) | ||
ghc-options: -Wmonomorphism-restriction | ||
if impl(ghc >= 7.0) | ||
ghc-options: -Wmissing-import-lists | ||
if impl(ghc >= 7.2) | ||
ghc-options: -Wincomplete-uni-patterns | ||
-Widentities | ||
if impl(ghc >= 8.0) | ||
ghc-options: -Wmissing-exported-signatures | ||
-Wredundant-constraints | ||
if impl(ghc >= 8.2) | ||
ghc-options: -Wmissing-home-modules | ||
if impl(ghc >= 8.4) | ||
ghc-options: -Wmissing-export-lists | ||
-Wpartial-fields | ||
if impl(ghc >= 8.8) | ||
ghc-options: -Wmissing-deriving-strategies | ||
if impl(ghc >= 8.10) | ||
ghc-options: -Wunused-packages | ||
if impl(ghc >= 9.0) | ||
ghc-options: -Winvalid-haddock | ||
if impl(ghc >= 9.2) | ||
ghc-options: -Wambiguous-fields | ||
-Wmissing-kind-signatures | ||
-Woperator-whitespace | ||
-Wredundant-bang-patterns | ||
if impl(ghc >= 9.4) | ||
ghc-options: -Wredundant-strictness-flags | ||
-Wforall-identifier | ||
-Woperator-whitespace-ext-conflict | ||
if impl(ghc >= 9.4.1) | ||
ghc-options: -Wgadt-mono-local-binds | ||
-Wtype-equality-out-of-scope | ||
-Wtype-equality-requires-operators | ||
if impl(ghc >= 9.6.1) | ||
-- ghc-options: -Wloopy-superclass-solve | ||
-- Bug: https://gitlab.haskell.org/ghc/ghc/-/issues/24071 | ||
if impl(ghc >= 9.8.1) | ||
ghc-options: -Wincomplete-export-warnings |
Oops, something went wrong.