Skip to content

Commit

Permalink
Fixed tracing issues introduced by #159 (#164)
Browse files Browse the repository at this point in the history
* Fixed tracing issues introduced by #159

* Added app_insights param to deactivate it for eval
  • Loading branch information
cedricvidal authored Sep 4, 2024
1 parent 046a468 commit d099b35
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/api/evaluate/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 3 additions & 1 deletion src/api/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
28 changes: 14 additions & 14 deletions src/api/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

0 comments on commit d099b35

Please sign in to comment.