@@ -36,6 +36,7 @@ import Development.IDE.Types.Shake (Key (..), Value,
36
36
Values )
37
37
import Development.Shake (Action , actionBracket )
38
38
import Foreign.Storable (Storable (sizeOf ))
39
+ import GHC.RTS.Flags
39
40
import HeapSize (recursiveSize , runHeapsize )
40
41
import Ide.PluginUtils (installSigUsr1Handler )
41
42
import Ide.Types (PluginId (.. ))
@@ -47,6 +48,7 @@ import OpenTelemetry.Eventlog (Instrument, SpanInFlight,
47
48
addEvent , beginSpan , endSpan ,
48
49
mkValueObserver , observe ,
49
50
setTag , withSpan , withSpan_ )
51
+ import System.IO.Unsafe (unsafePerformIO )
50
52
51
53
-- | Trace a handler using OpenTelemetry. Adds various useful info into tags in the OpenTelemetry span.
52
54
otTracedHandler
@@ -68,6 +70,14 @@ otTracedHandler requestType label act =
68
70
otSetUri :: SpanInFlight -> Uri -> IO ()
69
71
otSetUri sp (Uri t) = setTag sp " uri" (encodeUtf8 t)
70
72
73
+ {-# NOINLINE isTracingEnabled #-}
74
+ isTracingEnabled :: Bool
75
+ isTracingEnabled = unsafePerformIO $ do
76
+ flags <- getTraceFlags
77
+ case tracing flags of
78
+ TraceNone -> return False
79
+ _ -> return True
80
+
71
81
-- | Trace a Shake action using opentelemetry.
72
82
otTracedAction
73
83
:: Show k
@@ -76,23 +86,26 @@ otTracedAction
76
86
-> (a -> Bool ) -- ^ Did this action succeed?
77
87
-> Action a -- ^ The action
78
88
-> Action a
79
- otTracedAction key file success act = actionBracket
80
- (do
81
- sp <- beginSpan (fromString (show key))
82
- setTag sp " File" (fromString $ fromNormalizedFilePath file)
83
- return sp
84
- )
85
- endSpan
86
- (\ sp -> do
87
- res <- act
88
- unless (success res) $ setTag sp " error" " 1"
89
- return res)
90
-
91
- #if MIN_GHC_API_VERSION(8,8,0)
89
+ otTracedAction key file success act
90
+ | isTracingEnabled =
91
+ actionBracket
92
+ (do
93
+ sp <- beginSpan (fromString (show key))
94
+ setTag sp " File" (fromString $ fromNormalizedFilePath file)
95
+ return sp
96
+ )
97
+ endSpan
98
+ (\ sp -> do
99
+ res <- act
100
+ unless (success res) $ setTag sp " error" " 1"
101
+ return res)
102
+ | otherwise = act
103
+
104
+
92
105
otTracedProvider :: MonadUnliftIO m => PluginId -> ByteString -> m a -> m a
93
- #else
94
- otTracedProvider :: MonadUnliftIO m => PluginId -> String -> m a -> m a
95
- #endif
106
+
107
+
108
+
96
109
otTracedProvider (PluginId pluginName) provider act = do
97
110
runInIO <- askRunInIO
98
111
liftIO $ withSpan (provider <> " provider" ) $ \ sp -> do
@@ -220,3 +233,4 @@ repeatUntilJust nattempts action = do
220
233
case res of
221
234
Nothing -> repeatUntilJust (nattempts- 1 ) action
222
235
Just {} -> return res
236
+
0 commit comments