Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Switch from wsgi to asgi (attempt 3) #21579

Merged
merged 6 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ jobs:
timeout-minutes: 5
outputs:
chunks: ${{ steps.chunk.outputs.chunks }}

steps:
- name: Check out
uses: actions/checkout@v3
Expand Down
8 changes: 8 additions & 0 deletions posthog/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "posthog.settings")
os.environ.setdefault("SERVER_GATEWAY_INTERFACE", "ASGI")

application = get_asgi_application()
6 changes: 6 additions & 0 deletions posthog/settings/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def traces_sampler(sampling_context: dict) -> float:
if op == "http.server":
path = sampling_context.get("wsgi_environ", {}).get("PATH_INFO")
force_sample = bool(sampling_context.get("wsgi_environ", {}).get("HTTP_FORCE_SAMPLE"))
if os.environ.get("SERVER_GATEWAY_INTERFACE") == "ASGI":
path = sampling_context.get("asgi_scope", {}).get("path")
headers = sampling_context.get("asgi_scope", {}).get("headers", [])
for name, value in headers:
if name.lower().replace(b"_", b"-") == "force-sample":
force_sample = bool(value)

# HTTP header to force sampling set
if force_sample:
Expand Down
1 change: 1 addition & 0 deletions posthog/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "posthog.settings")
os.environ.setdefault("SERVER_GATEWAY_INTERFACE", "WSGI")

application = get_wsgi_application()
3 changes: 2 additions & 1 deletion unit.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"processes": 4,
"working_directory": "/code",
"path": ".",
"module": "posthog.wsgi",
"module": "posthog.asgi",
"protocol": "asgi",
"user": "nobody",
"limits": {
"requests": 50000
Expand Down
Loading