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

chore(Azure): remove app-level logging to Azure Monitor #1261

Merged
merged 2 commits into from
Feb 17, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions appcontainer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ Authlib==1.2.0
Django==4.1.6
django-csp==3.7
eligibility-api==2023.01.1
opencensus-ext-azure==1.1.8
opencensus-ext-django==0.8.0
requests==2.28.2
sentry-sdk==1.15.0
six==1.16.0
15 changes: 0 additions & 15 deletions benefits/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,6 @@ def process_view(self, request, view_func, view_args, view_kwargs):
return redirect("oauth:login")


# https://github.com/census-instrumentation/opencensus-python/issues/766
class LogErrorToAzure(MiddlewareMixin):
def __init__(self, get_response):
super().__init__(get_response)
# wait to do this here to be sure the handler is initialized
self.azure_logger = logging.getLogger("azure")

def process_exception(self, request, exception):
# https://stackoverflow.com/a/45532289
msg = getattr(exception, "message", repr(exception))
self.azure_logger.exception(msg, exc_info=exception)

return None


class RecaptchaEnabled(MiddlewareMixin):
"""Middleware configures the request with required reCAPTCHA settings."""

Expand Down
49 changes: 0 additions & 49 deletions benefits/logging.py

This file was deleted.

51 changes: 27 additions & 24 deletions benefits/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
import os
from benefits import sentry
import benefits.logging


def _filter_empty(ls):
Expand Down Expand Up @@ -69,28 +68,6 @@ def _filter_empty(ls):
MIDDLEWARE.append("benefits.core.middleware.DebugSession")


# Azure Insights
# https://docs.microsoft.com/en-us/azure/azure-monitor/app/opencensus-python-request#tracking-django-applications

ENABLE_AZURE_INSIGHTS = "APPLICATIONINSIGHTS_CONNECTION_STRING" in os.environ
print("ENABLE_AZURE_INSIGHTS: ", ENABLE_AZURE_INSIGHTS)
if ENABLE_AZURE_INSIGHTS:
MIDDLEWARE.extend(
[
"opencensus.ext.django.middleware.OpencensusMiddleware",
"benefits.core.middleware.LogErrorToAzure",
]
)

# only used if enabled above
OPENCENSUS = {
"TRACE": {
"SAMPLER": "opencensus.trace.samplers.AlwaysOnSampler()",
"EXPORTER": "opencensus.ext.azure.trace_exporter.AzureExporter()",
}
}


CSRF_COOKIE_AGE = None
CSRF_COOKIE_SAMESITE = "Strict"
CSRF_COOKIE_HTTPONLY = True
Expand Down Expand Up @@ -226,7 +203,33 @@ def _filter_empty(ls):

# Logging configuration
LOG_LEVEL = os.environ.get("DJANGO_LOG_LEVEL", "DEBUG" if DEBUG else "WARNING")
LOGGING = benefits.logging.get_config(LOG_LEVEL, enable_azure=ENABLE_AZURE_INSIGHTS)
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"default": {
"format": "[{asctime}] {levelname} {name}:{lineno} {message}",
"datefmt": "%d/%b/%Y %H:%M:%S",
"style": "{",
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "default",
},
},
"root": {
"handlers": ["console"],
"level": LOG_LEVEL,
},
"loggers": {
"django": {
"handlers": ["console"],
"propagate": False,
},
},
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change, just moved back into this file.


sentry.configure()

Expand Down
14 changes: 0 additions & 14 deletions docs/configuration/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,6 @@ The base URL for the (running) application, against which all Cypress `.visit()`
When Cypress is running inside the devcontainer, this should be `http://localhost:8000`. When Cypress is running outside the
devcontainer, check the [`DJANGO_LOCAL_PORT`](#django_local_port).

## Azure

### `APPLICATIONINSIGHTS_CONNECTION_STRING`

!!! tldr "Azure docs"

[Azure Monitor connection strings](https://docs.microsoft.com/en-us/azure/azure-monitor/app/sdk-connection-string)

Enables [log collection](../../deployment/troubleshooting/#logs). Set the value in quotes, e.g. `APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=…"`.

[app-service-config]: https://docs.microsoft.com/en-us/azure/app-service/configure-common?tabs=portal
[benefits-secrets]: https://github.com/cal-itp/benefits-secrets
[getting-started_create-env]: ../getting-started/README.md#create-an-environment-file

## Sentry

### `SENTRY_DSN`
Expand Down
15 changes: 0 additions & 15 deletions docs/deployment/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ We have [ping tests](https://docs.microsoft.com/en-us/azure/azure-monitor/app/mo

### Logs

Logs can be found a couple of places:

#### Azure App Service Logs

[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:
Expand All @@ -20,19 +18,6 @@ Logs can be found a couple of places:

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

#### [Azure Monitor Logs](https://docs.microsoft.com/en-us/azure/azure-monitor/logs/data-platform-logs)

[Open the `Logs` for the environment you are interested in.](https://docs.google.com/document/d/11EPDIROBvg7cRtU2V42c6VBxcW_o8HhcyORALNtL_XY/edit#heading=h.n0oq4r1jo7zs)

The following [tables](https://docs.microsoft.com/en-us/azure/azure-monitor/app/opencensus-python#telemetry-type-mappings) are likely of interest:

- `requests`
- `traces`

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).

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.

#### Live tail

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):
Expand Down
13 changes: 0 additions & 13 deletions tests/pytest/test_logging.py

This file was deleted.