Store remote_addr on the event

Fix #165
This commit is contained in:
Klaas van Schelven
2025-07-25 20:51:52 +02:00
parent 33fafc473b
commit 6b8d912e1a
4 changed files with 29 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0022_alter_event_project'),
]
operations = [
migrations.AddField(
model_name='event',
name='remote_addr',
field=models.GenericIPAddressField(blank=True, default=None, null=True),
),
]

View File

@@ -52,6 +52,7 @@ class Event(models.Model):
ingested_at = models.DateTimeField(blank=False, null=False)
digested_at = models.DateTimeField(db_index=True, blank=False, null=False)
remote_addr = models.GenericIPAddressField(blank=True, null=True, default=None)
issue = models.ForeignKey("issues.Issue", blank=False, null=False, on_delete=models.DO_NOTHING)
grouping = models.ForeignKey("issues.Grouping", blank=False, null=False, on_delete=models.DO_NOTHING)
@@ -237,6 +238,11 @@ class Event(models.Model):
debug_info=event_metadata["debug_info"][:255],
# just getting from the dict would be more precise, since we always add this info, but doing the .get()
# allows for backwards compatability (digesting events for which the info was not added on-ingest) so
# we'll take the defensive approach "for now" (until most everyone is on >= 1.7.4)
remote_addr=event_metadata.get("remote_addr"),
digest_order=digest_order,
irrelevance_for_retention=irrelevance_for_retention,

View File

@@ -171,11 +171,17 @@ class BaseIngestAPIView(View):
# Meta means: not part of the event data. Basically: information that is available at the time of ingestion, and
# that must be passed to digest() in a serializable form.
debug_info = request.META.get("HTTP_X_BUGSINK_DEBUGINFO", "")
# .get(..) -- don't want to crash on this and it's non-trivial to find a source that tells me with certainty
# that the REMOTE_ADDR is always in request.META (it probably is in practice)
remote_addr = request.META.get("REMOTE_ADDR")
return {
"event_id": event_id,
"project_id": project.id,
"ingested_at": format_timestamp(ingested_at),
"debug_info": debug_info,
"remote_addr": remote_addr,
}
@classmethod

View File

@@ -608,6 +608,7 @@ def issue_event_details(request, issue, event_pk=None, digest_order=None, nav=No
("ingested at", _date_with_milis_html(event.ingested_at)),
("digested at", _date_with_milis_html(event.digested_at)),
("digest order", event.digest_order),
("remote_addr", event.remote_addr),
]
logentry_info = []