Skip to content

setup IS_PRODUCTION_SERVER for logfire setup #27

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

Merged
merged 1 commit into from
Jun 1, 2025
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
3 changes: 3 additions & 0 deletions pythonkr_backend/pythonkr_backend/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@

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

# setup environment for logfire setup
os.environ['IS_ASGI_ENVIRONMENT'] = 'True'

application = get_asgi_application()
4 changes: 4 additions & 0 deletions pythonkr_backend/pythonkr_backend/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
BASE_DIR = Path(__file__).resolve().parent.parent.parent


# check WSGI/ASGI environment
IS_PRODUCTION_SERVER = os.environ.get('IS_WSGI_ENVIRONMENT') == 'True' or \
os.environ.get('IS_ASGI_ENVIRONMENT') == 'True'

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/

Expand Down
10 changes: 6 additions & 4 deletions pythonkr_backend/pythonkr_backend/settings/localtesting.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path
import os
#import logfire

import logfire

from .base import *

Expand Down Expand Up @@ -28,6 +29,7 @@
BAKERY_MULTISITE = True
BUILD_DIR = os.path.join("/app/bakery_static", "build")

# setup logfire
# logfire.configure(environment='localtest')
# logfire.instrument_django()
# logfire settings
if IS_PRODUCTION_SERVER:
logfire.configure(environment='localtest')
logfire.instrument_django()
10 changes: 6 additions & 4 deletions pythonkr_backend/pythonkr_backend/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from .base import *


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

# logfire settings
logfire.configure(environment='prod', service_name="web", service_version=sha_service_version)
logfire.instrument_system_metrics()
logfire.instrument_django()
logfire.instrument_psycopg('psycopg')
if IS_PRODUCTION_SERVER:
logfire.configure(environment='prod', service_name="web", service_version=sha_service_version)
logfire.instrument_system_metrics()
logfire.instrument_django()
logfire.instrument_psycopg('psycopg')
3 changes: 3 additions & 0 deletions pythonkr_backend/pythonkr_backend/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@

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

# setup environment for logfire setup
os.environ['IS_WSGI_ENVIRONMENT'] = 'True'

application = get_wsgi_application()