Skip to content

Commit 40d21ee

Browse files
blarghmateyCopilotfeohCopilot
authored
feat: migrate to mitol-django-observability plugin (#439)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: feoh <330070+feoh@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Christopher Patti <feoh@feoh.org> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent ebf46d6 commit 40d21ee

5 files changed

Lines changed: 1285 additions & 1612 deletions

File tree

main/apps.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,3 @@ def ready(self):
1313
from main import features
1414

1515
features.configure()
16-
17-
# Initialize OpenTelemetry
18-
from main.telemetry import configure_opentelemetry
19-
20-
configure_opentelemetry()

main/settings.py

Lines changed: 9 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"hijack.contrib.admin",
108108
"guardian",
109109
"channels",
110+
"mitol.observability.apps.ObservabilityConfig",
110111
# Put our apps after this point
111112
"main",
112113
"openapi",
@@ -336,67 +337,12 @@
336337
EMBEDLY_EMBED_URL = get_string("EMBEDLY_EMBED_URL", "https://api.embed.ly/1/oembed")
337338
EMBEDLY_EXTRACT_URL = get_string("EMBEDLY_EMBED_URL", "https://api.embed.ly/1/extract")
338339

339-
# Logging configuration
340-
LOG_LEVEL = get_string("MITOL_LOG_LEVEL", "INFO")
341-
DJANGO_LOG_LEVEL = get_string("DJANGO_LOG_LEVEL", "INFO")
342-
OS_LOG_LEVEL = get_string("OS_LOG_LEVEL", "INFO")
343-
344-
# For logging to a remote syslog host
345-
LOG_HOST = get_string("MITOL_LOG_HOST", "localhost")
346-
LOG_HOST_PORT = get_int("MITOL_LOG_HOST_PORT", 514)
347-
348340
HOSTNAME = platform.node().split(".")[0]
349341

350-
LOGGING = {
351-
"version": 1,
352-
"disable_existing_loggers": False,
353-
"filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
354-
"formatters": {
355-
"verbose": {
356-
"format": (
357-
"[%(asctime)s] %(levelname)s %(process)d [%(name)s] "
358-
"%(filename)s:%(lineno)d - "
359-
f"[{HOSTNAME}] - %(message)s"
360-
),
361-
"datefmt": "%Y-%m-%d %H:%M:%S",
362-
}
363-
},
364-
"handlers": {
365-
"console": {
366-
"level": LOG_LEVEL,
367-
"class": "logging.StreamHandler",
368-
"formatter": "verbose",
369-
},
370-
"syslog": {
371-
"level": LOG_LEVEL,
372-
"class": "logging.handlers.SysLogHandler",
373-
"facility": "local7",
374-
"formatter": "verbose",
375-
"address": (LOG_HOST, LOG_HOST_PORT),
376-
},
377-
"mail_admins": {
378-
"level": "ERROR",
379-
"filters": ["require_debug_false"],
380-
"class": "django.utils.log.AdminEmailHandler",
381-
},
382-
},
383-
"loggers": {
384-
"django": {
385-
"propagate": True,
386-
"level": DJANGO_LOG_LEVEL,
387-
"handlers": ["console", "syslog"],
388-
},
389-
"django.request": {
390-
"handlers": ["mail_admins"],
391-
"level": DJANGO_LOG_LEVEL,
392-
"propagate": True,
393-
},
394-
"opensearch": {"level": OS_LOG_LEVEL},
395-
"nplusone": {"handlers": ["console"], "level": "ERROR"},
396-
"boto3": {"handlers": ["console"], "level": "ERROR"},
397-
},
398-
"root": {"handlers": ["console", "syslog"], "level": LOG_LEVEL},
399-
}
342+
# LOGGING is provided by mitol-django-observability (structlog-based, JSON in prod).
343+
# Log levels are controlled via LOG_LEVEL (root) and DJANGO_LOG_LEVEL environment
344+
# variables, read directly by the plugin.
345+
from mitol.observability.settings.logging import LOGGING # noqa: E402, F401
400346

401347
STATUS_TOKEN = get_string("STATUS_TOKEN", "")
402348

@@ -736,8 +682,10 @@ def get_all_config_keys():
736682
},
737683
}
738684

739-
# OpenTelemetry configuration
740-
OPENTELEMETRY_ENABLED = get_bool("OPENTELEMETRY_ENABLED", default=False)
685+
# OpenTelemetry configuration (consumed by mitol-django-observability plugin).
686+
# OTel is activated when OPENTELEMETRY_ENDPOINT (or OTEL_EXPORTER_OTLP_ENDPOINT
687+
# env var) is set, or when DEBUG=True. The old OPENTELEMETRY_ENABLED flag is no
688+
# longer supported; set OPENTELEMETRY_ENDPOINT to enable tracing.
741689
OPENTELEMETRY_SERVICE_NAME = get_string("OPENTELEMETRY_SERVICE_NAME", "learn-ai")
742690
OPENTELEMETRY_INSECURE = get_bool("OPENTELEMETRY_INSECURE", default=True)
743691
OPENTELEMETRY_ENDPOINT = get_string("OPENTELEMETRY_ENDPOINT", None)

main/telemetry.py

Lines changed: 0 additions & 86 deletions
This file was deleted.

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies = [
2525
"django-hijack>=3.4.1,<4",
2626
"django-ipware>=7.0.0,<8",
2727
"django-oauth-toolkit>=3.0.0,<4",
28-
"django-redis>=5.2.0,<6",
28+
"django-redis>=5.2.0,<7",
2929
"django-scim2>=0.19.1,<0.20",
3030
"django-server-status>=0.7.0,<0.8",
3131
"django-storages>=1.13.2,<2",
@@ -44,15 +44,14 @@ dependencies = [
4444
"langsmith>=0.7.0,<0.8",
4545
"litellm>=1.53.5,<2",
4646
"markdown2>=2.5.2,<3",
47+
"mitol-django-observability>=2026.1.0",
48+
"setuptools>=69.0.0",
4749
"named-enum>=1.4.0,<2",
48-
"opentelemetry-api>=1.31.0",
49-
"opentelemetry-exporter-otlp>=1.31.0",
5050
"opentelemetry-instrumentation-celery>=0.52b0",
5151
"opentelemetry-instrumentation-django>=0.52b0",
5252
"opentelemetry-instrumentation-psycopg>=0.52b0",
5353
"opentelemetry-instrumentation-redis>=0.52b0",
5454
"opentelemetry-instrumentation-requests>=0.52b0",
55-
"opentelemetry-sdk>=1.31.0",
5655
"posthog>=7.0.1,<8",
5756
"psycopg>=3.2.4,<4",
5857
"psycopg-pool>=3.2.4,<4",
@@ -109,6 +108,7 @@ dev = [
109108
package = false
110109
default-groups = "all"
111110
constraint-dependencies = ["langgraph-checkpoint<3"]
111+
environments = ["sys_platform != 'win32'"]
112112

113113
[tool.uv.build-backend]
114114
module-root = ""

0 commit comments

Comments
 (0)