Skip to content

Commit

Permalink
only register hooks when llm obs enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
lievan committed Jan 9, 2025
1 parent 04ee68f commit 28e8830
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ddtrace/llmobs/_llmobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ def __init__(self, tracer=None):
self._annotations = []
self._annotation_context_lock = forksafe.RLock()

# Register hooks for span events
core.on("trace.span_start", self._do_annotations)
core.on("trace.span_finish", self._on_span_finish)

def _on_span_finish(self, span):
if self.enabled and span.span_type == SpanTypes.LLM:
self._submit_llmobs_span(span)
Expand Down Expand Up @@ -364,6 +360,10 @@ def enable(
cls.enabled = True
cls._instance.start()

# Register hooks for span events
core.on("trace.span_start", cls._instance._do_annotations)
core.on("trace.span_finish", cls._instance._on_span_finish)

atexit.register(cls.disable)
telemetry_writer.product_activated(TELEMETRY_APM_PRODUCT.LLMOBS, True)

Expand Down
1 change: 1 addition & 0 deletions tests/llmobs/test_llmobs_ragas_faithfulness_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def test_llmobs_with_faithfulness_emits_traces_and_evals_on_exit(mock_writer_log
"_DD_LLMOBS_EVALUATOR_INTERVAL": "5",
"_DD_LLMOBS_EVALUATORS": "ragas_faithfulness",
"DD_LLMOBS_AGENTLESS_ENABLED": "true",
"DD_TRACE_ENABLED": "0",
}
)
out, err, status, pid = run_python_code_in_subprocess(
Expand Down

0 comments on commit 28e8830

Please sign in to comment.