Skip to content

Commit

Permalink
reuse userTracingEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
pepeiborra committed Apr 5, 2021
1 parent ac25452 commit 3dad4db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
1 change: 1 addition & 0 deletions ghcide/ghcide.cabal
Expand Up @@ -52,6 +52,7 @@ library
filepath,
fingertree,
ghc-exactprint,
ghc-trace-events,
Glob,
haddock-library ^>= 1.10.0,
hashable,
Expand Down
18 changes: 4 additions & 14 deletions ghcide/src/Development/IDE/Core/Tracing.hs
Expand Up @@ -8,7 +8,6 @@ module Development.IDE.Core.Tracing
, getInstrumentCached
, otTracedProvider
, otSetUri
, isTracingEnabled
)
where

Expand All @@ -29,6 +28,7 @@ import Data.IORef (modifyIORef', newIORef,
readIORef, writeIORef)
import Data.String (IsString (fromString))
import Data.Text.Encoding (encodeUtf8)
import Debug.Trace.Flags (userTracingEnabled)
import Development.IDE.Core.RuleTypes (GhcSession (GhcSession),
GhcSessionDeps (GhcSessionDeps),
GhcSessionIO (GhcSessionIO))
Expand All @@ -39,7 +39,6 @@ import Development.IDE.Types.Shake (Key (..), Value,
Values)
import Development.Shake (Action, actionBracket)
import Foreign.Storable (Storable (sizeOf))
import GHC.RTS.Flags
import HeapSize (recursiveSize, runHeapsize)
import Ide.PluginUtils (installSigUsr1Handler)
import Ide.Types (PluginId (..))
Expand All @@ -51,7 +50,6 @@ import OpenTelemetry.Eventlog (Instrument, SpanInFlight (..),
addEvent, beginSpan, endSpan,
mkValueObserver, observe,
setTag, withSpan, withSpan_)
import System.IO.Unsafe (unsafePerformIO)

-- | Trace a handler using OpenTelemetry. Adds various useful info into tags in the OpenTelemetry span.
otTracedHandler
Expand All @@ -61,7 +59,7 @@ otTracedHandler
-> (SpanInFlight -> m a)
-> m a
otTracedHandler requestType label act
| isTracingEnabled = do
| userTracingEnabled = do
let !name =
if null label
then requestType
Expand All @@ -74,14 +72,6 @@ otTracedHandler requestType label act
otSetUri :: SpanInFlight -> Uri -> IO ()
otSetUri sp (Uri t) = setTag sp "uri" (encodeUtf8 t)

{-# NOINLINE isTracingEnabled #-}
isTracingEnabled :: Bool
isTracingEnabled = unsafePerformIO $ do
flags <- getTraceFlags
case tracing flags of
TraceNone -> return False
_ -> return True

-- | Trace a Shake action using opentelemetry.
otTracedAction
:: Show k
Expand All @@ -91,7 +81,7 @@ otTracedAction
-> Action a -- ^ The action
-> Action a
otTracedAction key file success act
| isTracingEnabled =
| userTracingEnabled =
actionBracket
(do
sp <- beginSpan (fromString (show key))
Expand All @@ -111,7 +101,7 @@ otTracedProvider :: MonadUnliftIO m => PluginId -> ByteString -> m a -> m a
otTracedProvider :: MonadUnliftIO m => PluginId -> String -> m a -> m a
#endif
otTracedProvider (PluginId pluginName) provider act
| isTracingEnabled = do
| userTracingEnabled = do
runInIO <- askRunInIO
liftIO $ withSpan (provider <> " provider") $ \sp -> do
setTag sp "plugin" (encodeUtf8 pluginName)
Expand Down

0 comments on commit 3dad4db

Please sign in to comment.