Skip to content

Commit

Permalink
telemetry JK (facebookincubator#441)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebookincubator#441

Install a JK to conditionally enable the telemetry added in the previous Diff

Reviewed By: phlalx

Differential Revision: D55860620

fbshipit-source-id: f532136bad279c8d1eccc8193526f25c611e7285
  • Loading branch information
Pepe Iborra authored and facebook-github-bot committed Apr 8, 2024
1 parent b6b1b33 commit 990ad18
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions glean.cabal.in
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,7 @@ library glass-lib
Glean.Glass.SymbolKind
Glean.Glass.SymbolMap
Glean.Glass.SymbolSig
Glean.Glass.Tracer
Glean.Glass.Tracing
Glean.Glass.Utils
Glean.Glass.Visibility
Expand Down
10 changes: 9 additions & 1 deletion glean/glass/Glean/Glass/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import Glean.Glass.Types
( GlassException (GlassException, glassException_reasons),
GlassExceptionReason (GlassExceptionReason_exactRevisionNotAvailable))
import Glean.Glass.Env (Env(tracer))
import Glean.Glass.Tracer ( isTracingEnabled )
import Glean.Glass.Tracing (GlassTrace(TraceCommand))

kThriftCacheNoCache :: Text
Expand Down Expand Up @@ -153,11 +154,18 @@ withCurrentRepoMapping env0 fn = do
current <- getRepoMapping
fn (env0 { Glass.repoMapping = current })

withRequestTracing :: Env -> (Env -> IO b) -> IO b
withRequestTracing env k = do
enabled <- isTracingEnabled
k $ if enabled then env else env { tracer = mempty }

-- Actual glass service handler, types from glass.thrift
-- TODO: snapshot the env, rather than passing in the mutable fields
--
glassHandler :: Glass.Env -> GlassServiceCommand r -> IO r
glassHandler env0 cmd = withCurrentRepoMapping env0 $ \env ->
glassHandler env0 cmd =
withCurrentRepoMapping env0 $ \env1 ->
withRequestTracing env1 $ \env ->
traceMsg (tracer env) (TraceCommand cmd) $ case cmd of
SuperFacebookService r -> fb303Handler (Glass.fb303 env) r

Expand Down
14 changes: 14 additions & 0 deletions glean/glass/Glean/Glass/Tracer.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{-
Copyright (c) Meta Platforms, Inc. and affiliates.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree.
-}

module Glean.Glass.Tracer
( isTracingEnabled
) where

isTracingEnabled :: IO Bool
isTracingEnabled = return True

0 comments on commit 990ad18

Please sign in to comment.