Skip to content

Commit c02e647

Browse files
committed
Add Back telemetry
1 parent 39fd08b commit c02e647

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/backend/app_kernel.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@
4343
from app_config import config
4444

4545
# # Check if the Application Insights Instrumentation Key is set in the environment variables
46-
# instrumentation_key = os.getenv("APPLICATIONINSIGHTS_INSTRUMENTATION_KEY")
47-
# if instrumentation_key:
48-
# # Configure Application Insights if the Instrumentation Key is found
49-
# configure_azure_monitor(connection_string=instrumentation_key)
50-
# logging.info("Application Insights configured with the provided Instrumentation Key")
51-
# else:
52-
# # Log a warning if the Instrumentation Key is not found
53-
# logging.warning("No Application Insights Instrumentation Key found. Skipping configuration")
46+
instrumentation_key = os.getenv("APPLICATIONINSIGHTS_INSTRUMENTATION_KEY")
47+
if instrumentation_key:
48+
# Configure Application Insights if the Instrumentation Key is found
49+
configure_azure_monitor(connection_string=instrumentation_key)
50+
logging.info(
51+
"Application Insights configured with the provided Instrumentation Key"
52+
)
53+
else:
54+
# Log a warning if the Instrumentation Key is not found
55+
logging.warning(
56+
"No Application Insights Instrumentation Key found. Skipping configuration"
57+
)
5458

5559
# Configure logging
5660
logging.basicConfig(level=logging.INFO)
@@ -62,9 +66,9 @@
6266
logging.getLogger("azure.identity.aio._internal").setLevel(logging.WARNING)
6367

6468
# # Suppress info logs from OpenTelemetry exporter
65-
# logging.getLogger("azure.monitor.opentelemetry.exporter.export._base").setLevel(
66-
# logging.WARNING
67-
# )
69+
logging.getLogger("azure.monitor.opentelemetry.exporter.export._base").setLevel(
70+
logging.WARNING
71+
)
6872

6973
# Initialize the FastAPI app
7074
app = FastAPI()

src/backend/event_utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
def track_event_if_configured(event_name: str, event_data: dict):
77
"""Track an event if Application Insights is configured.
8-
8+
99
This function safely wraps the Azure Monitor track_event function
1010
to handle potential errors with the ProxyLogger.
11-
11+
1212
Args:
1313
event_name: The name of the event to track
1414
event_data: Dictionary of event data/dimensions
@@ -17,8 +17,10 @@ def track_event_if_configured(event_name: str, event_data: dict):
1717
instrumentation_key = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
1818
if instrumentation_key:
1919
track_event(event_name, event_data)
20-
# else:
21-
# logging.warning(f"Skipping track_event for {event_name} as Application Insights is not configured")
20+
else:
21+
logging.warning(
22+
f"Skipping track_event for {event_name} as Application Insights is not configured"
23+
)
2224
except AttributeError as e:
2325
# Handle the 'ProxyLogger' object has no attribute 'resource' error
2426
logging.warning(f"ProxyLogger error in track_event: {e}")

0 commit comments

Comments
 (0)