packages feed

hs-opentelemetry-instrumentation-persistent-mysql 0.0.0.0 → 1.0.0.0

raw patch · 4 files changed

+80/−23 lines, 4 filesdep +hs-opentelemetry-semantic-conventionsdep ~hs-opentelemetry-apidep ~hs-opentelemetry-instrumentation-persistent

Dependencies added: hs-opentelemetry-semantic-conventions

Dependency ranges changed: hs-opentelemetry-api, hs-opentelemetry-instrumentation-persistent

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Changelog for hs-opentelemetry-instrumentation-persistent-mysql++## 1.0.0.0 - 2026-05-29++- Promoted to 1.0.0.0 for the hs-opentelemetry 1.0 release.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Ian Duncan (c) 2021-2026++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Ian Duncan nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
hs-opentelemetry-instrumentation-persistent-mysql.cabal view
@@ -1,12 +1,26 @@ cabal-version: 2.4  name: hs-opentelemetry-instrumentation-persistent-mysql-version: 0.0.0.0+version: 1.0.0.0 synopsis: OpenTelemetry instrumentation for persistent-mysql+description:+  OpenTelemetry instrumentation for @persistent-mysql@. Records database client+  spans for MySQL queries issued through the Persistent ORM, including+  connection-level attributes following the database semantic conventions. license: BSD-3-Clause author: Kazuki Okamoto (岡本和樹) maintainer: kazuki.okamoto@herp.co.jp+copyright: 2024 Ian Duncan, Mercury Technologies+license-file: LICENSE+homepage: https://github.com/iand675/hs-opentelemetry#readme+bug-reports: https://github.com/iand675/hs-opentelemetry/issues+category: OpenTelemetry, Database, MySQL+extra-doc-files: CHANGELOG.md +source-repository head+  type: git+  location: https://github.com/iand675/hs-opentelemetry+ common common   build-depends: base >= 4 && < 5   ghc-options: -Wall@@ -18,8 +32,9 @@   import: common   hs-source-dirs: src   exposed-modules: OpenTelemetry.Instrumentation.Persistent.MySQL-  build-depends: hs-opentelemetry-api,-                 hs-opentelemetry-instrumentation-persistent,+  build-depends: hs-opentelemetry-api ^>= 1.0,+                 hs-opentelemetry-instrumentation-persistent ^>= 1.0,+                 hs-opentelemetry-semantic-conventions >= 1.40 && < 2,                  iproute,                  monad-logger,                  mysql,
src/OpenTelemetry/Instrumentation/Persistent/MySQL.hs view
@@ -7,10 +7,14 @@  {- | Wrapper module for @Database.Persist.MySQL@ with @OpenTelemetry.Instrumentation.Persistent@. -[New HTTP semantic conventions have been declared stable.](https://opentelemetry.io/blog/2023/http-conventions-declared-stable/#migration-plan) Opt-in by setting the environment variable OTEL_SEMCONV_STABILITY_OPT_IN to-- "http" - to use the stable conventions-- "http/dup" - to emit both the old and the stable conventions-Otherwise, the old conventions will be used. The stable conventions will replace the old conventions in the next major release of this library.+New database semantic conventions have been declared stable. Opt-in by setting+the environment variable @OTEL_SEMCONV_STABILITY_OPT_IN@ to:++- @"database"@ — to use the stable database conventions+- @"database\/dup"@ — to emit both the old and the stable conventions++Otherwise, the old conventions will be used. The stable conventions will+replace the old conventions in the next major release of this library. -} module OpenTelemetry.Instrumentation.Persistent.MySQL (   withMySQLPool,@@ -49,7 +53,9 @@ import qualified Database.MySQL.Base as MySQL import qualified Database.Persist.MySQL as Orig import Database.Persist.Sql+import OpenTelemetry.Attributes.Key (unkey) import qualified OpenTelemetry.Instrumentation.Persistent as Otel+import qualified OpenTelemetry.SemanticConventions as SC import OpenTelemetry.SemanticsConfig import qualified OpenTelemetry.Trace.Core as Otel import Text.Read (readMaybe)@@ -105,10 +111,10 @@   -- ^ Connection information.   -> LogFunc   -> IO (MySQL.Connection, SqlBackend)-openMySQLConn tp attrs ci@MySQL.ConnectInfo {connectUser, connectPort, connectOptions, connectHost} logFunc = do+openMySQLConn tp attrs ci@MySQL.ConnectInfo {connectUser, connectPort, connectOptions, connectHost, connectDatabase} logFunc = do   let     portAttr, transportAttr :: Otel.Attribute-    portAttr = fromString $ show connectPort+    portAttr = Otel.toAttribute (fromIntegral connectPort :: Int)     transportAttr =       fromMaybe "ip_tcp" $         getLast $@@ -122,28 +128,29 @@                   MySQL.Memory -> "inproc"               _ -> Last Nothing     addStableAttributes =-      H.union-        [ ("db.connection_string" :: Text, fromString $ showsPrecConnectInfoMasked 0 ci "")-        , ("db.user", fromString connectUser)-        , ("server.port", portAttr)-        , ("network.peer.port", portAttr)-        , ("net.transport", transportAttr)-        , (maybe "server.address" (const "network.peer.address") (readMaybe connectHost :: Maybe IP), fromString connectHost)+      H.union $+        [ (unkey SC.db_system_name, "mysql")+        , (unkey SC.server_port, portAttr)+        , (unkey SC.network_peer_port, portAttr)+        , (maybe (unkey SC.server_address) (const (unkey SC.network_peer_address)) (readMaybe connectHost :: Maybe IP), fromString connectHost)         ]+          <> if null connectDatabase+            then []+            else [(unkey SC.db_namespace, fromString connectDatabase)]     addOldAttributes =       -- "net.sock.family" is unnecessary because it must be "inet" when "net.sock.peer.addr" or "net.sock.host.addr" is set.       H.union-        [ ("db.connection_string" :: Text, fromString $ showsPrecConnectInfoMasked 0 ci "")-        , ("db.user", fromString connectUser)-        , ("net.peer.port", portAttr)-        , ("net.sock.peer.port", portAttr)-        , ("net.transport", transportAttr)-        , (maybe "net.peer.name" (const "net.sock.peer.addr") (readMaybe connectHost :: Maybe IP), fromString connectHost)+        [ (unkey SC.db_connectionString, fromString $ showsPrecConnectInfoMasked 0 ci "")+        , (unkey SC.db_user, fromString connectUser)+        , (unkey SC.net_peer_port, portAttr)+        , (unkey SC.net_sock_peer_port, portAttr)+        , (unkey SC.net_transport, transportAttr)+        , (maybe (unkey SC.net_peer_name) (const (unkey SC.net_sock_peer_addr)) (readMaybe connectHost :: Maybe IP), fromString connectHost)         ]    semanticsOptions <- getSemanticsOptions   let attrs' =-        case httpOption semanticsOptions of+        case databaseOption semanticsOptions of           Stable -> addStableAttributes attrs           StableAndOld -> addStableAttributes $ addOldAttributes attrs           Old -> addOldAttributes attrs