Skip to content

Commit 9ba6faa

Browse files
fix: sample high-volume "Token required" Sentry errors at 1%
The CLI-S issue has ~21M occurrences of "Token required - not valid tokenless upload" errors flooding Sentry. Add a before_send hook that randomly drops 99 out of 100 events matching this message pattern, reducing volume while still capturing representative samples.
1 parent 03f2564 commit 9ba6faa

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

codecov-cli/codecov_cli/opentelemetry.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
import os
2-
import time
2+
import random
33

44
import sentry_sdk
55

66
from codecov_cli import __version__
77

8+
_SAMPLED_MESSAGES = [
9+
"Token required",
10+
]
11+
_SAMPLE_RATE = 100
12+
13+
14+
def _before_send(event, hint):
15+
message = (event.get("logentry") or {}).get("message", "")
16+
if not message:
17+
message = event.get("message", "")
18+
for pattern in _SAMPLED_MESSAGES:
19+
if pattern in message:
20+
if random.randint(1, _SAMPLE_RATE) != 1:
21+
return None
22+
break
23+
return event
24+
825

926
def init_telem(ctx):
1027
if ctx["disable_telem"]:
@@ -19,6 +36,7 @@ def init_telem(ctx):
1936
enable_tracing=True,
2037
environment=os.getenv("CODECOV_ENV", "production"),
2138
release=f"cli@{__version__}",
39+
before_send=_before_send,
2240
)
2341

2442

0 commit comments

Comments
 (0)