Skip to content

Commit f8ebdec

Browse files
authored
chore(Azure): remove app-level logging to Azure Monitor (#1261)
2 parents 2d0b6e3 + 09a7bee commit f8ebdec

File tree

7 files changed

+27
-132
lines changed

7 files changed

+27
-132
lines changed

appcontainer/requirements.txt

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ Authlib==1.2.0
22
Django==4.1.6
33
django-csp==3.7
44
eligibility-api==2023.01.1
5-
opencensus-ext-azure==1.1.8
6-
opencensus-ext-django==0.8.0
75
requests==2.28.2
86
sentry-sdk==1.15.0
97
six==1.16.0

benefits/core/middleware.py

-15
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,6 @@ def process_view(self, request, view_func, view_args, view_kwargs):
161161
return redirect("oauth:login")
162162

163163

164-
# https://github.com/census-instrumentation/opencensus-python/issues/766
165-
class LogErrorToAzure(MiddlewareMixin):
166-
def __init__(self, get_response):
167-
super().__init__(get_response)
168-
# wait to do this here to be sure the handler is initialized
169-
self.azure_logger = logging.getLogger("azure")
170-
171-
def process_exception(self, request, exception):
172-
# https://stackoverflow.com/a/45532289
173-
msg = getattr(exception, "message", repr(exception))
174-
self.azure_logger.exception(msg, exc_info=exception)
175-
176-
return None
177-
178-
179164
class RecaptchaEnabled(MiddlewareMixin):
180165
"""Middleware configures the request with required reCAPTCHA settings."""
181166

benefits/logging.py

-49
This file was deleted.

benefits/settings.py

+27-24
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44
import os
55
from benefits import sentry
6-
import benefits.logging
76

87

98
def _filter_empty(ls):
@@ -69,28 +68,6 @@ def _filter_empty(ls):
6968
MIDDLEWARE.append("benefits.core.middleware.DebugSession")
7069

7170

72-
# Azure Insights
73-
# https://docs.microsoft.com/en-us/azure/azure-monitor/app/opencensus-python-request#tracking-django-applications
74-
75-
ENABLE_AZURE_INSIGHTS = "APPLICATIONINSIGHTS_CONNECTION_STRING" in os.environ
76-
print("ENABLE_AZURE_INSIGHTS: ", ENABLE_AZURE_INSIGHTS)
77-
if ENABLE_AZURE_INSIGHTS:
78-
MIDDLEWARE.extend(
79-
[
80-
"opencensus.ext.django.middleware.OpencensusMiddleware",
81-
"benefits.core.middleware.LogErrorToAzure",
82-
]
83-
)
84-
85-
# only used if enabled above
86-
OPENCENSUS = {
87-
"TRACE": {
88-
"SAMPLER": "opencensus.trace.samplers.AlwaysOnSampler()",
89-
"EXPORTER": "opencensus.ext.azure.trace_exporter.AzureExporter()",
90-
}
91-
}
92-
93-
9471
CSRF_COOKIE_AGE = None
9572
CSRF_COOKIE_SAMESITE = "Strict"
9673
CSRF_COOKIE_HTTPONLY = True
@@ -226,7 +203,33 @@ def _filter_empty(ls):
226203

227204
# Logging configuration
228205
LOG_LEVEL = os.environ.get("DJANGO_LOG_LEVEL", "DEBUG" if DEBUG else "WARNING")
229-
LOGGING = benefits.logging.get_config(LOG_LEVEL, enable_azure=ENABLE_AZURE_INSIGHTS)
206+
LOGGING = {
207+
"version": 1,
208+
"disable_existing_loggers": False,
209+
"formatters": {
210+
"default": {
211+
"format": "[{asctime}] {levelname} {name}:{lineno} {message}",
212+
"datefmt": "%d/%b/%Y %H:%M:%S",
213+
"style": "{",
214+
},
215+
},
216+
"handlers": {
217+
"console": {
218+
"class": "logging.StreamHandler",
219+
"formatter": "default",
220+
},
221+
},
222+
"root": {
223+
"handlers": ["console"],
224+
"level": LOG_LEVEL,
225+
},
226+
"loggers": {
227+
"django": {
228+
"handlers": ["console"],
229+
"propagate": False,
230+
},
231+
},
232+
}
230233

231234
sentry.configure()
232235

docs/configuration/environment-variables.md

-14
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,6 @@ The base URL for the (running) application, against which all Cypress `.visit()`
158158
When Cypress is running inside the devcontainer, this should be `http://localhost:8000`. When Cypress is running outside the
159159
devcontainer, check the [`DJANGO_LOCAL_PORT`](#django_local_port).
160160

161-
## Azure
162-
163-
### `APPLICATIONINSIGHTS_CONNECTION_STRING`
164-
165-
!!! tldr "Azure docs"
166-
167-
[Azure Monitor connection strings](https://docs.microsoft.com/en-us/azure/azure-monitor/app/sdk-connection-string)
168-
169-
Enables [log collection](../../deployment/troubleshooting/#logs). Set the value in quotes, e.g. `APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=…"`.
170-
171-
[app-service-config]: https://docs.microsoft.com/en-us/azure/app-service/configure-common?tabs=portal
172-
[benefits-secrets]: https://github.com/cal-itp/benefits-secrets
173-
[getting-started_create-env]: ../getting-started/README.md#create-an-environment-file
174-
175161
## Sentry
176162

177163
### `SENTRY_DSN`

docs/deployment/troubleshooting.md

-15
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ We have [ping tests](https://docs.microsoft.com/en-us/azure/azure-monitor/app/mo
88

99
### Logs
1010

11-
Logs can be found a couple of places:
12-
1311
#### Azure App Service Logs
1412

1513
[Open the `Logs` for the environment you are interested in.](https://docs.google.com/document/d/11EPDIROBvg7cRtU2V42c6VBxcW_o8HhcyORALNtL_XY/edit#heading=h.6pxjhslhxwvj) The following tables are likely of interest:
@@ -20,19 +18,6 @@ Logs can be found a couple of places:
2018

2119
For some pre-defined queries, click `Queries`, then `Group by: Query type`, and look under `Query pack queries`.
2220

23-
#### [Azure Monitor Logs](https://docs.microsoft.com/en-us/azure/azure-monitor/logs/data-platform-logs)
24-
25-
[Open the `Logs` for the environment you are interested in.](https://docs.google.com/document/d/11EPDIROBvg7cRtU2V42c6VBxcW_o8HhcyORALNtL_XY/edit#heading=h.n0oq4r1jo7zs)
26-
27-
The following [tables](https://docs.microsoft.com/en-us/azure/azure-monitor/app/opencensus-python#telemetry-type-mappings) are likely of interest:
28-
29-
- `requests`
30-
- `traces`
31-
32-
In the latter two, you should see recent log output. Note [there is some latency](https://docs.microsoft.com/en-us/azure/azure-monitor/logs/data-ingestion-time).
33-
34-
See [`Failures`](https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-exceptions#diagnose-failures-using-the-azure-portal) in the sidebar (or `exceptions` under `Logs`) for application errors/exceptions.
35-
3621
#### Live tail
3722

3823
After [setting up the Azure CLI](#making-changes), you can use the following command to [stream live logs](https://docs.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs#in-local-terminal):

tests/pytest/test_logging.py

-13
This file was deleted.

0 commit comments

Comments
 (0)