Skip to content

chore(llmobs): update ragas trace ml app#11952

Merged
lievan merged 20 commits intomainfrom
evan.li/ragas-ml-app
Jan 22, 2025
Merged

chore(llmobs): update ragas trace ml app#11952
lievan merged 20 commits intomainfrom
evan.li/ragas-ml-app

Conversation

@lievan
Copy link
Copy Markdown
Contributor

@lievan lievan commented Jan 15, 2025

Update the ml application of any ragas evaluation span to be the same as the span being evaluated.

Refresher:

  • Spans are generated by datadog for RAGAS operations
  • These spans need to be identified as RAGAS-specific to avoid an infinite eval loop and tagged with 'runner.integration:ragas' for backend purposes
  • Some of these spans are auto-instrumented through our langchain integration, meaning they can't be manually tagged

Previous Implementation:

  • Added a dd-ragas- prefix to the ML application name for RAGAS spans
  • This prefix was used to identify which spans came from RAGAS when spans are processed

Now:

  • add _dd_ragas prefix on ragas span's ml app for identification purposes, except only temporarily.
  • Just before sending these spans to the backend, remove the prefix

An alternative solution is to utilize annotation_contexts to set a tag on auto-instrumented ragas spans. This is a larger refactor that i would like to explore when we clean up the ragas evaluators (more cleanly separate tracing setup vs actual eval logic).

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 15, 2025

CODEOWNERS have been resolved as:

ddtrace/llmobs/_constants.py                                            @DataDog/ml-observability
ddtrace/llmobs/_evaluators/ragas/answer_relevancy.py                    @DataDog/ml-observability
ddtrace/llmobs/_evaluators/ragas/base.py                                @DataDog/ml-observability
ddtrace/llmobs/_evaluators/ragas/context_precision.py                   @DataDog/ml-observability
ddtrace/llmobs/_evaluators/ragas/faithfulness.py                        @DataDog/ml-observability
ddtrace/llmobs/_llmobs.py                                               @DataDog/ml-observability
ddtrace/llmobs/_utils.py                                                @DataDog/ml-observability
tests/llmobs/_utils.py                                                  @DataDog/ml-observability
tests/llmobs/test_llmobs_service.py                                     @DataDog/ml-observability

@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Jan 16, 2025

Benchmarks

Benchmark execution time: 2025-01-21 20:43:48

Comparing candidate commit 808663a in PR branch evan.li/ragas-ml-app with baseline commit a5bf963 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 394 metrics, 2 unstable metrics.

Comment thread ddtrace/llmobs/_llmobs.py
@lievan lievan added the changelog/no-changelog A changelog entry is not required for this PR. label Jan 16, 2025
@lievan lievan marked this pull request as ready for review January 16, 2025 16:06
@lievan lievan requested a review from a team as a code owner January 16, 2025 16:06
@lievan lievan changed the title chore(llmobs): update ragas tracing experience chore(llmobs): update ragas trace ml app Jan 16, 2025
Comment thread ddtrace/llmobs/_constants.py Outdated
Comment thread ddtrace/llmobs/_llmobs.py Outdated
Comment thread ddtrace/llmobs/_constants.py Outdated
Comment thread ddtrace/llmobs/_llmobs.py Outdated
Comment thread ddtrace/llmobs/_llmobs.py Outdated
Comment thread ddtrace/llmobs/_llmobs.py
Comment thread ddtrace/llmobs/_utils.py
Copy link
Copy Markdown
Contributor

@Yun-Kim Yun-Kim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last small comments

Comment thread ddtrace/llmobs/_llmobs.py Outdated
Comment thread ddtrace/llmobs/_llmobs.py Outdated
Comment thread ddtrace/llmobs/_llmobs.py
Comment thread ddtrace/llmobs/_llmobs.py
Comment thread ddtrace/llmobs/_utils.py Outdated
@lievan lievan merged commit 57c43a7 into main Jan 22, 2025
@lievan lievan deleted the evan.li/ragas-ml-app branch January 22, 2025 00:14
Yun-Kim added a commit that referenced this pull request Jan 30, 2025
…ckport #12089] (#12134)

Backports #12089 to 2.20.

Note that we had to manually cherry-pick from #12089 to account for
#11952 not being backported.

This PR makes a change to our shared distributed tracing header
injection method to dispatch signals/events instead of relying on the
global config settings, which is only modifiable via env vars. This
fixes distributed tracing for users that might rely solely on the
`LLMObs.enable()` setup config.

Programmatic `LLMObs.enable()/disable()` calls do not set the global
`config._llmobs_enabled` boolean setting, which is only controlled by
the `DD_LLMOBS_ENABLED` env var. This was problematic for users that
relied on manual `LLMObs.enable()` setup (i.e. no env vars) because our
distributed tracing injection code only checks the global config to
inject llmobs parent IDs into request headers. If users manually enabled
LLMObs without any env vars, then this would not be reflected in the
global config value and thus LLMObs parent IDs would never be injected
into the request headers.

We can't check directly if LLMObs is enabled in the http injection
module because:
1. This would require us to import significant product-specific
LLMObs-code into the shared http injector helper module which would
impact non-LLMObs users' app performance
2. Circular imports in LLMObs which imports http injector logic to use
in its own helpers

Instead of doing our check based on the global `config._llmobs_enabled`
setting, we now send a tracing event to our shared product listeners,
and register a corresponding `LLMObs._inject_llmobs_context()` hook to
be called for all inject() calls if LLMObs is enabled (we check the
LLMObs instance, not the global config setting value).

~One risk and why I don't like changing global config settings is
because this then implies that it is no longer global or tied to an env
var (I want to push for env var configuration where possible over manual
overriding/enabling). If a global enabled config can be toggled
indiscriminately then this could open a can of worms for
enabling/disabling logic in our LLMObs service, which isn't really
designed to be toggled on/off multiple times in the app's lifespan.
However if some users cannot rely on env vars, then I don't see any
other solution that does not couple tracer internal code with LLMObs
code which is a no-option.~ (UPDATE: we avoided this issue by using
signal dispatching)

# Checklist

- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

# Reviewer Checklist 

- [x] Reviewer has checked that all the criteria below are met
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance

policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog A changelog entry is not required for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants