Skip to content

Commit ae66854

Browse files
committed
setup IS_PRODUCTION_SERVER for logfire setup
1 parent d4cbbc7 commit ae66854

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

pythonkr_backend/pythonkr_backend/asgi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@
1313

1414
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pythonkr_backend.settings')
1515

16+
# setup environment for logfire setup
17+
os.environ['IS_ASGI_ENVIRONMENT'] = 'True'
18+
1619
application = get_asgi_application()

pythonkr_backend/pythonkr_backend/settings/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
BASE_DIR = Path(__file__).resolve().parent.parent.parent
1818

1919

20+
# check WSGI/ASGI environment
21+
IS_PRODUCTION_SERVER = os.environ.get('IS_WSGI_ENVIRONMENT') == 'True' or \
22+
os.environ.get('IS_ASGI_ENVIRONMENT') == 'True'
23+
2024
# Quick-start development settings - unsuitable for production
2125
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
2226

pythonkr_backend/pythonkr_backend/settings/localtesting.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pathlib import Path
22
import os
3-
#import logfire
3+
4+
import logfire
45

56
from .base import *
67

@@ -28,6 +29,7 @@
2829
BAKERY_MULTISITE = True
2930
BUILD_DIR = os.path.join("/app/bakery_static", "build")
3031

31-
# setup logfire
32-
# logfire.configure(environment='localtest')
33-
# logfire.instrument_django()
32+
# logfire settings
33+
if IS_PRODUCTION_SERVER:
34+
logfire.configure(environment='localtest')
35+
logfire.instrument_django()

pythonkr_backend/pythonkr_backend/settings/prod.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from .base import *
66

7+
78
DATABASES = {
89
'default': {
910
'ENGINE': 'django.db.backends.postgresql',
@@ -30,7 +31,8 @@
3031
sha_service_version = os.environ.get("SHA")
3132

3233
# logfire settings
33-
logfire.configure(environment='prod', service_name="web", service_version=sha_service_version)
34-
logfire.instrument_system_metrics()
35-
logfire.instrument_django()
36-
logfire.instrument_psycopg('psycopg')
34+
if IS_PRODUCTION_SERVER:
35+
logfire.configure(environment='prod', service_name="web", service_version=sha_service_version)
36+
logfire.instrument_system_metrics()
37+
logfire.instrument_django()
38+
logfire.instrument_psycopg('psycopg')

pythonkr_backend/pythonkr_backend/wsgi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@
1313

1414
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pythonkr_backend.settings')
1515

16+
# setup environment for logfire setup
17+
os.environ['IS_WSGI_ENVIRONMENT'] = 'True'
18+
1619
application = get_wsgi_application()

0 commit comments

Comments
 (0)