feat: payload compression, tracing, and DLQ observability - #743
Merged
Conversation
|
@OtowoSamuel Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
There was a problem hiding this comment.
Pull request overview
This PR adds backend performance and observability improvements to SoroScan’s ingest/webhook pipeline by enabling payload compression (DB + HTTP), adding custom OpenTelemetry tracing helpers/spans, and improving dead-letter queue (DLQ) visibility via Prometheus metrics.
Changes:
- Enabled response compression via Django
GZipMiddlewareand added a migration to enable Postgres TOAST compression on event payload columns. - Introduced a small ingest telemetry module and instrumented key ingest/webhook paths with custom OpenTelemetry spans + outbound trace header injection.
- Added new Prometheus metrics (payload compression ratio, webhook DLQ depth) and tests covering the new helpers/trace header propagation.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| django-backend/soroscan/settings.py | Adds GZipMiddleware for HTTP response compression. |
| django-backend/soroscan/ingest/telemetry.py | New helper module for trace header injection and compression ratio observation. |
| django-backend/soroscan/ingest/tasks.py | Instruments ingest + webhook dispatch with spans, injects trace headers, records compression ratio, updates DLQ depth metric on enqueue. |
| django-backend/soroscan/ingest/cache_utils.py | Wraps contract cache lookups in a tracing span. |
| django-backend/soroscan/ingest/metrics.py | Adds new metrics and extends metric factory to support histogram kwargs (e.g., buckets). |
| django-backend/soroscan/ingest/migrations/0044_contractevent_payload_compression.py | Enables Postgres column compression for payload storage with fallback behavior. |
| django-backend/soroscan/ingest/tests/test_tasks.py | Adds tests for compression ratio metric emission and trace header propagation in webhook requests. |
| django-backend/requirements.txt | Adds OpenTelemetry API/SDK dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
118
to
121
| "soroscan.middleware.ApiDeprecationMiddleware", | ||
| "django.middleware.common.CommonMiddleware", | ||
| "django.middleware.gzip.GZipMiddleware", | ||
| "django.middleware.csrf.CsrfViewMiddleware", |
Comment on lines
+9
to
+17
| from opentelemetry import propagate, trace | ||
| from opentelemetry.sdk.trace import TracerProvider | ||
|
|
||
| from .metrics import event_payload_compression_ratio | ||
|
|
||
| if trace.get_tracer_provider().__class__.__name__ == "ProxyTracerProvider": | ||
| trace.set_tracer_provider(TracerProvider()) | ||
|
|
||
| tracer = trace.get_tracer("soroscan.ingest") |
Comment on lines
+290
to
+295
| event_payload_compression_ratio = _get_or_create( | ||
| Histogram, | ||
| "soroscan_event_payload_compression_ratio", | ||
| "Observed compressed-to-raw size ratio for stored event payloads", | ||
| buckets=(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.25, 1.5), | ||
| ) |
Comment on lines
+18
to
+23
| with schema_editor.connection.cursor() as cursor: | ||
| for statement in statements: | ||
| try: | ||
| cursor.execute(statement) | ||
| except Exception: | ||
| cursor.execute(statement.replace("lz4", "pglz")) |
Comment on lines
+626
to
+630
| return (None, False) | ||
|
|
||
| raw_xdr = str(_event_attr(event, "xdr", "raw_xdr", default="") or "") | ||
| signature_status = resolve_signature_status(contract, event, payload) | ||
| payload_compression_ratio(payload) | ||
|
|
||
| timestamp = _event_attr(event, "timestamp", default=timezone.now()) | ||
| if isinstance(timestamp, datetime) and timezone.is_naive(timestamp): | ||
| timestamp = timezone.make_aware(timestamp, dt_timezone.utc) | ||
| if not isinstance(timestamp, datetime): | ||
| timestamp = timezone.now() | ||
| raw_xdr = str(_event_attr(event, "xdr", "raw_xdr", default="") or "") |
Comment on lines
1458
to
+1463
| error=error[:2000], | ||
| retries_exhausted=retries_exhausted, | ||
| ) | ||
| _get_metrics().webhook_dead_letter_depth.set( | ||
| WebhookDeadLetter.objects.filter(resolved=False).count() | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements the requested backend improvements.
Closes #507
Closes #496
Closes #511
Closes #510