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

Fix broken local serve due to azure logging middleware failure #31

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 7 additions & 5 deletions app/azure_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,20 @@ def initialize_logging(
logger = logging.getLogger()
logging.basicConfig(level=logging_level, format="%(asctime)s %(message)s")

ai_conn_string = os.environ.get("APPLICATIONINSIGHTS_CONNECTION_STRING")
if (ai_conn_string is None or ai_conn_string == ""):
logger.info(f"APPLICATIONINSIGHTS_CONNECTION_STRING unset or empty. Azure logging will not be enabled.")
return

try:
# picks up os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"] automatically
azurelog_handler = AzureLogHandler()
azurelog_handler.add_telemetry_processor(telemetry_processor_callback_function)
azurelog_handler.addFilter(ExceptionTracebackFilter())
logger.addHandler(azurelog_handler)
except ValueError as e:
if os.environ.get("APPLICATIONINSIGHTS_CONNECTION_STRING") is None:
logger.info(f"Application Insights logger handler not set")
else:
logger.error(f"Failed to set Application Insights logger handler: {e}")
raise e
logger.error(f"Failed to set Application Insights logger handler: {e}")
raise e

config_integration.trace_integrations(["logging"])
Tracer(sampler=AlwaysOnSampler())
Expand Down