@@ -15,7 +15,6 @@ import OpenTelemetry.Trace.Sampler qualified as Sampler
1515import OpenTelemetry.Trace.TraceState (TraceState )
1616import OpenTelemetry.Trace.TraceState qualified as TraceState
1717import Share.Prelude
18- import Unison.Debug qualified as Debug
1918
2019initSampler :: IO Sampler. Sampler
2120initSampler =
@@ -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