Spaces:
Sleeping
Sleeping
Srini P commited on
Commit ·
cee9a8d
1
Parent(s): c390b0c
Diag: Use manual AzureMonitorTraceExporter for lower-level control and debug
Browse files- app/backend/main.py +17 -2
app/backend/main.py
CHANGED
|
@@ -17,14 +17,29 @@ import sys
|
|
| 17 |
|
| 18 |
# Initialize Azure Monitor Tracing FIRST (Before project imports)
|
| 19 |
def init_azure_monitor():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Check both standard and common variants
|
| 21 |
connection_string = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING") or os.getenv("APPLICATION_INSIGHTS_CONNECTION_STRING")
|
| 22 |
|
| 23 |
if connection_string:
|
| 24 |
connection_string = connection_string.strip("'\"")
|
| 25 |
try:
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
return True, connection_string
|
| 29 |
except Exception as e:
|
| 30 |
print(f"ERROR: Failed to initialize Azure Monitor Tracing: {str(e)}")
|
|
|
|
| 17 |
|
| 18 |
# Initialize Azure Monitor Tracing FIRST (Before project imports)
|
| 19 |
def init_azure_monitor():
|
| 20 |
+
from opentelemetry.sdk.trace import TracerProvider
|
| 21 |
+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
| 22 |
+
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
|
| 23 |
+
from opentelemetry import trace
|
| 24 |
+
|
| 25 |
# Check both standard and common variants
|
| 26 |
connection_string = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING") or os.getenv("APPLICATION_INSIGHTS_CONNECTION_STRING")
|
| 27 |
|
| 28 |
if connection_string:
|
| 29 |
connection_string = connection_string.strip("'\"")
|
| 30 |
try:
|
| 31 |
+
# Set up the provider
|
| 32 |
+
provider = TracerProvider()
|
| 33 |
+
|
| 34 |
+
# Configure the Azure Monitor Exporter manually for better visibility
|
| 35 |
+
exporter = AzureMonitorTraceExporter(connection_string=connection_string)
|
| 36 |
+
span_processor = BatchSpanProcessor(exporter)
|
| 37 |
+
provider.add_span_processor(span_processor)
|
| 38 |
+
|
| 39 |
+
# Register the provider globally
|
| 40 |
+
trace.set_tracer_provider(provider)
|
| 41 |
+
|
| 42 |
+
print("INFO: Azure Monitor tracing initialized successfully (Manual Setup).")
|
| 43 |
return True, connection_string
|
| 44 |
except Exception as e:
|
| 45 |
print(f"ERROR: Failed to initialize Azure Monitor Tracing: {str(e)}")
|