Skip to content

Commit 1256d82

Browse files
committed
Allow forcing sampling on specific requests
1 parent 5f3ad76 commit 1256d82

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Share/Telemetry/Setup.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import OpenTelemetry.Trace.Sampler qualified as Sampler
1515
import OpenTelemetry.Trace.TraceState (TraceState)
1616
import OpenTelemetry.Trace.TraceState qualified as TraceState
1717
import Share.Prelude
18-
import Unison.Debug qualified as Debug
1918

2019
initSampler :: IO Sampler.Sampler
2120
initSampler =
@@ -29,21 +28,22 @@ initSampler =
2928
Trace.AttributeValue (Trace.TextAttribute t) -> Just t
3029
_ -> Nothing
3130
dropSample = (Sampler.Drop, HM.empty, TraceState.empty)
32-
-- Configure some custom sampling logic.
31+
-- Allow forcing a sample with the following header:
32+
-- "baggage: force-trace=true"
3333
shouldForceSample :: Context -> Bool
3434
shouldForceSample ctx = fromMaybe False do
3535
baggage <- Context.lookupBaggage ctx
3636
let baggageMap = Baggage.values baggage
3737
forceTraceToken <- Baggage.mkToken "force-trace"
3838
forceTrace <- Baggage.value <$> HM.lookup forceTraceToken baggageMap
39-
Debug.debugLogM Debug.Temp ("Force trace token: " <> show forceTrace)
4039
case Text.toLower forceTrace of
4140
"false" -> Just False
4241
"0" -> Just False
4342
_ -> Just True
4443
shouldSample :: Sampler.Sampler -> Context -> TraceId -> Text -> Trace.SpanArguments -> IO (Sampler.SamplingResult, HashMap Text Trace.Attribute, TraceState)
4544
shouldSample defaultSampler ctx tid name args
46-
| shouldForceSample ctx = Sampler.shouldSample Sampler.alwaysOn ctx tid name args
45+
| shouldForceSample ctx = do
46+
Sampler.shouldSample Sampler.alwaysOn ctx tid name args
4747
| otherwise = do
4848
case (lookupTextAttribute "http.target" args >>= URI.parseURIReference . Text.unpack) <&> URI.pathSegments of
4949
Just ("metrics" : _) -> pure dropSample

0 commit comments

Comments
 (0)