Skip to content

Commit 037b029

Browse files
authored
chore(access-logs): trace access logs via sentry exception option (#97183)
Send a (very very) small portion of API access log stack traces to Sentry. We're having difficulty debugging [missing organization id](https://linear.app/getsentry/issue/ID-805/fix-missing-organization-id-in-api-access-logs) from access logs, and so we want to send the stack traces to check if the request and request auth have the correct fields. Planning to roll this out at 0.0001 — with [~10M access logs created per hour](https://app.datadoghq.com/metric/explorer?fromUser=false&graph_layout=stacked&start=1754407289153&end=1754410889153&paused=false#N4Ig7glgJg5gpgFxALlAGwIYE8D2BXJVEADxQEYAaELcqyKBAC1pEbghkcLIF8qo4AMwgA7CAgg4RKUAiwAHOChASAtnADOcAE4RNIKtrgBHPJoQaUAbVBGN8qVoD6gnNtUZCKiOq279VKY6epbINiAiGOrKQdpYZAYgUJ4YThr42gDGSsgg6gi6mZaBZnHKGniqyFoiBVgAdKrQUGhwYBhG9RiZ2RoaTmg4MPWZRp5wUMAAVDxd-Zn4tQAUAJQgPAC6VK7ueJih4TuqexjKmZUVqkux8WubVBpyrTIg8hitCAg5SUNOmfsaCCZRJoURwJxyRTlHCgqAgsFOehMZQiNweNDrfgQeyYLAQhTfUEiJSbHh8EA48QAYSkwhgKBEezQPCAA) we should get ~1000 access logs an hour, or ~16 a minute — should be very doable by sentry.
1 parent af5fda1 commit 037b029

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/sentry/middleware/access_log.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
from collections.abc import Callable
66
from dataclasses import dataclass
77

8+
import sentry_sdk
89
from django.conf import settings
910
from django.utils.encoding import force_str
1011
from rest_framework.authentication import get_authorization_header
1112
from rest_framework.request import Request
1213
from rest_framework.response import Response
1314

1415
from sentry.auth.services.auth import AuthenticatedToken
16+
from sentry.options.rollout import in_random_rollout
1517
from sentry.types.ratelimit import RateLimitMeta, SnubaRateLimitMeta
1618
from sentry.utils import metrics
1719

@@ -128,6 +130,10 @@ def _create_api_access_log(
128130
log_metrics["token_last_characters"] = force_str(auth[1])[-4:]
129131
api_access_logger.info("api.access", extra=log_metrics)
130132
metrics.incr("middleware.access_log.created")
133+
134+
if in_random_rollout("issues.log-access-logs") and not org_id:
135+
sentry_sdk.capture_message("Acesss log created without org_id", level="debug")
136+
131137
except Exception:
132138
api_access_logger.exception("api.access: Error capturing API access logs")
133139

src/sentry/options/defaults.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,6 +3441,8 @@
34413441
# Enable enhancing access logs with snuba responses
34423442
register("issues.use-snuba-error-data", type=Float, default=0.0, flags=FLAG_AUTOMATOR_MODIFIABLE)
34433443

3444+
register("issues.log-access-logs", type=Float, default=0.0, flags=FLAG_AUTOMATOR_MODIFIABLE)
3445+
34443446
# Use "first-seen" group instead of "most-seen" group when merging
34453447
register(
34463448
"issues.merging.first-seen",

0 commit comments

Comments
 (0)