Skip to content

Commit d7b8029

Browse files
committed
reuse userTracingEnabled
1 parent 5f7decb commit d7b8029

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

Diff for: ghcide/ghcide.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ library
5252
filepath,
5353
fingertree,
5454
ghc-exactprint,
55+
ghc-trace-events,
5556
Glob,
5657
haddock-library ^>= 1.10.0,
5758
hashable,

Diff for: ghcide/src/Development/IDE/Core/Tracing.hs

+4-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module Development.IDE.Core.Tracing
88
, getInstrumentCached
99
, otTracedProvider
1010
, otSetUri
11-
, isTracingEnabled
1211
)
1312
where
1413

@@ -29,6 +28,7 @@ import Data.IORef (modifyIORef', newIORef,
2928
readIORef, writeIORef)
3029
import Data.String (IsString (fromString))
3130
import Data.Text.Encoding (encodeUtf8)
31+
import Debug.Trace.Flags (userTracingEnabled)
3232
import Development.IDE.Core.RuleTypes (GhcSession (GhcSession),
3333
GhcSessionDeps (GhcSessionDeps),
3434
GhcSessionIO (GhcSessionIO))
@@ -39,7 +39,6 @@ import Development.IDE.Types.Shake (Key (..), Value,
3939
Values)
4040
import Development.Shake (Action, actionBracket)
4141
import Foreign.Storable (Storable (sizeOf))
42-
import GHC.RTS.Flags
4342
import HeapSize (recursiveSize, runHeapsize)
4443
import Ide.PluginUtils (installSigUsr1Handler)
4544
import Ide.Types (PluginId (..))
@@ -51,7 +50,6 @@ import OpenTelemetry.Eventlog (Instrument, SpanInFlight (..),
5150
addEvent, beginSpan, endSpan,
5251
mkValueObserver, observe,
5352
setTag, withSpan, withSpan_)
54-
import System.IO.Unsafe (unsafePerformIO)
5553

5654
-- | Trace a handler using OpenTelemetry. Adds various useful info into tags in the OpenTelemetry span.
5755
otTracedHandler
@@ -61,7 +59,7 @@ otTracedHandler
6159
-> (SpanInFlight -> m a)
6260
-> m a
6361
otTracedHandler requestType label act
64-
| isTracingEnabled = do
62+
| userTracingEnabled = do
6563
let !name =
6664
if null label
6765
then requestType
@@ -74,14 +72,6 @@ otTracedHandler requestType label act
7472
otSetUri :: SpanInFlight -> Uri -> IO ()
7573
otSetUri sp (Uri t) = setTag sp "uri" (encodeUtf8 t)
7674

77-
{-# NOINLINE isTracingEnabled #-}
78-
isTracingEnabled :: Bool
79-
isTracingEnabled = unsafePerformIO $ do
80-
flags <- getTraceFlags
81-
case tracing flags of
82-
TraceNone -> return False
83-
_ -> return True
84-
8575
-- | Trace a Shake action using opentelemetry.
8676
otTracedAction
8777
:: Show k
@@ -91,7 +81,7 @@ otTracedAction
9181
-> Action a -- ^ The action
9282
-> Action a
9383
otTracedAction key file success act
94-
| isTracingEnabled =
84+
| userTracingEnabled =
9585
actionBracket
9686
(do
9787
sp <- beginSpan (fromString (show key))
@@ -111,7 +101,7 @@ otTracedProvider :: MonadUnliftIO m => PluginId -> ByteString -> m a -> m a
111101
otTracedProvider :: MonadUnliftIO m => PluginId -> String -> m a -> m a
112102
#endif
113103
otTracedProvider (PluginId pluginName) provider act
114-
| isTracingEnabled = do
104+
| userTracingEnabled = do
115105
runInIO <- askRunInIO
116106
liftIO $ withSpan (provider <> " provider") $ \sp -> do
117107
setTag sp "plugin" (encodeUtf8 pluginName)

0 commit comments

Comments
 (0)