Skip to content

Commit

Permalink
chore(Azure): remove Azure OpenCensus integration
Browse files Browse the repository at this point in the history
Now that we have Sentry, we determined that the App Service logs are sufficient for other logs, and thus it isn't worth the complexity/confusion of having the logs sent to Azure Monitor.
  • Loading branch information
afeld committed Feb 16, 2023
1 parent f72883a commit 09a7bee
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 112 deletions.
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
49 changes: 0 additions & 49 deletions benefits/logging.py

This file was deleted.

46 changes: 27 additions & 19 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,23 +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.append("opencensus.ext.django.middleware.OpencensusMiddleware")

# 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 @@ -221,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,
},
},
}

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

Note that we aren't [sending exceptions to Azure Monitor](https://learn.microsoft.com/en-us/azure/azure-monitor/app/opencensus-python#send-exceptions) (aside from the logs), so you won't see anything show up under `Failures` or `Logs`->`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.

0 comments on commit 09a7bee

Please sign in to comment.