From d099b35abf045a7ddfa0f51b5be7a07f250f5f78 Mon Sep 17 00:00:00 2001 From: Cedric Vidal Date: Wed, 4 Sep 2024 03:06:20 -1000 Subject: [PATCH] Fixed tracing issues introduced by #159 (#164) * Fixed tracing issues introduced by #159 * Added app_insights param to deactivate it for eval --- src/api/evaluate/evaluate.py | 2 +- src/api/orchestrator.py | 4 +++- src/api/tracing.py | 28 ++++++++++++++-------------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/api/evaluate/evaluate.py b/src/api/evaluate/evaluate.py index 68d23630..71156965 100644 --- a/src/api/evaluate/evaluate.py +++ b/src/api/evaluate/evaluate.py @@ -156,7 +156,7 @@ def evaluate_row(research_context, product_context, assignment_context): # Use LOCAL_TRACING to determine if we should use the PromptyTracer locally # Never use remote_tracing for evaluation, it's not really relevant LOCAL_TRACING = True if os.getenv("LOCAL_TRACING", "false").lower() == "true" else False - tracer = init_tracing(local_tracing=LOCAL_TRACING, remote_tracing=False) + tracer = init_tracing(local_tracing=LOCAL_TRACING, remote_tracing=False, app_insights=False) eval_result = evaluate_orchestrator(model_config, data_path=folder +"/eval_inputs.jsonl") diff --git a/src/api/orchestrator.py b/src/api/orchestrator.py index 392029ff..b52fbaaf 100644 --- a/src/api/orchestrator.py +++ b/src/api/orchestrator.py @@ -170,6 +170,8 @@ def test_create_article(): if __name__ == "__main__": from tracing import init_tracing + import os - tracer = init_tracing(remote_tracing=True, local_tracing=True) + LOCAL_TRACING = True if os.getenv("LOCAL_TRACING", "false").lower() == "true" else False + tracer = init_tracing(local_tracing=LOCAL_TRACING) test_create_article() diff --git a/src/api/tracing.py b/src/api/tracing.py index df6272f7..285387b5 100644 --- a/src/api/tracing.py +++ b/src/api/tracing.py @@ -27,7 +27,7 @@ def verbose_trace(key, value): yield verbose_trace -def init_tracing(remote_tracing: bool, local_tracing: bool = False): +def init_tracing(local_tracing: bool = False, remote_tracing: bool = None, app_insights: bool = True): """ Initialize tracing for the application If local_tracing is True, use the PromptyTracer @@ -45,21 +45,21 @@ def init_tracing(remote_tracing: bool, local_tracing: bool = False): elif remote_tracing: Tracer.add("OpenTelemetry", trace_span) - azmon_logger = logging.getLogger("azure") - azmon_logger.setLevel(logging.INFO) + if app_insights: + azmon_logger = logging.getLogger("azure") + azmon_logger.setLevel(logging.INFO) - # oteltrace.set_tracer_provider(TracerProvider()) + # oteltrace.set_tracer_provider(TracerProvider()) - # Configure Azure Monitor as the Exporter - app_insights = os.getenv("APPINSIGHTS_CONNECTIONSTRING") + # Configure Azure Monitor as the Exporter + app_insights = os.getenv("APPINSIGHTS_CONNECTIONSTRING") - # Add the Azure exporter to the tracer provider + # Add the Azure exporter to the tracer provider - oteltrace.set_tracer_provider(TracerProvider(sampler=ParentBasedTraceIdRatio(1.0))) - oteltrace.get_tracer_provider().add_span_processor(BatchSpanProcessor(AzureMonitorTraceExporter(connection_string=app_insights))) - # oteltrace.get_tracer_provider().add_span_processor( - # SimpleSpanProcessor(trace_exporter) - # ) - - return oteltrace.get_tracer(_tracer) + oteltrace.set_tracer_provider(TracerProvider(sampler=ParentBasedTraceIdRatio(1.0))) + oteltrace.get_tracer_provider().add_span_processor(BatchSpanProcessor(AzureMonitorTraceExporter(connection_string=app_insights))) + # oteltrace.get_tracer_provider().add_span_processor( + # SimpleSpanProcessor(trace_exporter) + # ) + return oteltrace.get_tracer(_tracer)