Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(llmobs): add parent ID handling for integration-generated spans #9417

Merged
merged 2 commits into from
May 29, 2024

Conversation

Yun-Kim
Copy link
Contributor

@Yun-Kim Yun-Kim commented May 28, 2024

This PR adds a fix to add handling for integration-generated spans for LLMObs parent ID propagation. #9152 added a edge case handling in LLMObs._start_span() if the span was part of the first service in a distributed trace, in which case we would need to check the span.get_tag(PROPAGATED_PARENT_KEY) due to the distributed header being propagated upwards to the local root of the original service at span finish time (but would always be propagated to all spans in subsequent services at span start time).

Integration (openai, bedrock, langchain) generated spans use BaseLLMIntegration.trace(...) instead of LLMObs._start_span() so we needed to add handling here.

Checklist

  • Change(s) are motivated and described in the PR description
  • Testing strategy is described if automated tests are not included in the PR
  • Risks are described (performance impact, potential for breakage, maintainability)
  • Change is maintainable (easy to change, telemetry, documentation)
  • Library release note guidelines are followed or label changelog/no-changelog is set
  • Documentation is included (in-code, generated user docs, public corp docs)
  • Backport labels are set (if applicable)
  • If this PR changes the public interface, I've notified @DataDog/apm-tees.

Reviewer Checklist

  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Description motivates each change
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Change is maintainable (easy to change, telemetry, documentation)
  • Release note makes sense to a user of the library
  • 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

@Yun-Kim Yun-Kim added changelog/no-changelog A changelog entry is not required for this PR. backport 2.9 labels May 28, 2024
@Yun-Kim Yun-Kim requested a review from a team as a code owner May 28, 2024 20:43
@datadog-datadog-prod-us1
Copy link
Contributor

Software Composition Analysis

We found vulnerabilities in the following libraries (compared 56b4885 against 0d695e6):

@Yun-Kim Yun-Kim enabled auto-merge (squash) May 28, 2024 20:47
Copy link
Contributor

@sabrenner sabrenner left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

@Yun-Kim Yun-Kim force-pushed the yunkim/llmobs-fix-integration-propagation branch from 56b4885 to 1290d8d Compare May 28, 2024 20:49
@datadog-dd-trace-py-rkomorn
Copy link

datadog-dd-trace-py-rkomorn bot commented May 28, 2024

Datadog Report

Branch report: yunkim/llmobs-fix-integration-propagation
Commit report: f2732a7
Test service: dd-trace-py

✅ 0 Failed, 2088 Passed, 1447 Skipped, 59m 44.68s Total duration (26m 54.99s time saved)

@Yun-Kim Yun-Kim force-pushed the yunkim/llmobs-fix-integration-propagation branch from 1290d8d to 0d4c6fa Compare May 28, 2024 21:22
@Yun-Kim Yun-Kim requested a review from a team as a code owner May 28, 2024 22:21
@Yun-Kim Yun-Kim force-pushed the yunkim/llmobs-fix-integration-propagation branch 2 times, most recently from 3bffafb to 2995819 Compare May 28, 2024 22:43
@Yun-Kim Yun-Kim requested a review from mabdinur May 28, 2024 23:35
@Yun-Kim Yun-Kim force-pushed the yunkim/llmobs-fix-integration-propagation branch from 2995819 to 7e6af37 Compare May 29, 2024 00:44
@Yun-Kim Yun-Kim force-pushed the yunkim/llmobs-fix-integration-propagation branch from 7e6af37 to f2732a7 Compare May 29, 2024 00:45
@Yun-Kim Yun-Kim closed this May 29, 2024
auto-merge was automatically disabled May 29, 2024 01:18

Pull request was closed

@Yun-Kim Yun-Kim reopened this May 29, 2024
@Yun-Kim Yun-Kim enabled auto-merge (squash) May 29, 2024 01:18
@Yun-Kim Yun-Kim merged commit 538a024 into main May 29, 2024
185 of 197 checks passed
@Yun-Kim Yun-Kim deleted the yunkim/llmobs-fix-integration-propagation branch May 29, 2024 01:40
github-actions bot pushed a commit that referenced this pull request May 29, 2024
…9417)

This PR adds a fix to add handling for integration-generated spans for
LLMObs parent ID propagation. #9152 added a edge case handling in
`LLMObs._start_span()` if the span was part of the first service in a
distributed trace, in which case we would need to check the
`span.get_tag(PROPAGATED_PARENT_KEY)` due to the distributed header
being propagated upwards to the local root of the original service at
span finish time (but would always be propagated to all spans in
subsequent services at span start time).

Integration (openai, bedrock, langchain) generated spans use
`BaseLLMIntegration.trace(...)` instead of `LLMObs._start_span()` so we
needed to add handling here.

## Checklist

- [x] Change(s) are motivated and described in the PR description
- [x] Testing strategy is described if automated tests are not included
in the PR
- [x] Risks are described (performance impact, potential for breakage,
maintainability)
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed or label `changelog/no-changelog` is set
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/))
- [x] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))
- [x] If this PR changes the public interface, I've notified
`@DataDog/apm-tees`.

## Reviewer Checklist

- [x] Title is accurate
- [x] All changes are related to the pull request's stated goal
- [x] Description motivates each change
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- [x] Testing strategy adequately addresses listed risks
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] Release note makes sense to a user of the library
- [x] Author has acknowledged and discussed the performance implications
of this PR as reported in the benchmarks PR comment
- [x] 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)

(cherry picked from commit 538a024)
Yun-Kim added a commit that referenced this pull request May 29, 2024
…backport 2.9] (#9422)

Backport 538a024 from #9417 to 2.9.

This PR adds a fix to add handling for integration-generated spans for
LLMObs parent ID propagation. #9152 added a edge case handling in
`LLMObs._start_span()` if the span was part of the first service in a
distributed trace, in which case we would need to check the
`span.get_tag(PROPAGATED_PARENT_KEY)` due to the distributed header
being propagated upwards to the local root of the original service at
span finish time (but would always be propagated to all spans in
subsequent services at span start time).

Integration (openai, bedrock, langchain) generated spans use
`BaseLLMIntegration.trace(...)` instead of `LLMObs._start_span()` so we
needed to add handling here.

## Checklist

- [x] Change(s) are motivated and described in the PR description
- [x] Testing strategy is described if automated tests are not included
in the PR
- [x] Risks are described (performance impact, potential for breakage,
maintainability)
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed or label `changelog/no-changelog` is set
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/))
- [x] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))
- [x] If this PR changes the public interface, I've notified
`@DataDog/apm-tees`.

## Reviewer Checklist

- [x] Title is accurate
- [x] All changes are related to the pull request's stated goal
- [x] Description motivates each change
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- [x] Testing strategy adequately addresses listed risks
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] Release note makes sense to a user of the library
- [x] Author has acknowledged and discussed the performance implications
of this PR as reported in the benchmarks PR comment
- [x] 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)

Co-authored-by: Yun Kim <[email protected]>
Yun-Kim added a commit that referenced this pull request May 30, 2024
NOTE to apm-python reviewers: The only files this PR touches outside of
LLM Observability ownership are snapshot files.

This PR expands on #9417 by only set span.span_type = "llm" if LLMObs is
enabled. This means that we will not even attempt to process the given
span (i.e. set temporary LLMObs tags), which should minimize when the
affect LLMObs code has outside of LLMObs contexts. The majority of this
PR's LOC involves modifying all openai/langchain/bedrock snapshot files
to remove "type":"llm".

Existing tests should cover the reverted functionality.

## Checklist

- [x] Change(s) are motivated and described in the PR description
- [x] Testing strategy is described if automated tests are not included
in the PR
- [x] Risks are described (performance impact, potential for breakage,
maintainability)
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed or label `changelog/no-changelog` is set
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/))
- [x] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))
- [x] If this PR changes the public interface, I've notified
`@DataDog/apm-tees`.

## Reviewer Checklist

- [x] Title is accurate
- [x] All changes are related to the pull request's stated goal
- [x] Description motivates each change
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- [x] Testing strategy adequately addresses listed risks
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] Release note makes sense to a user of the library
- [x] Author has acknowledged and discussed the performance implications
of this PR as reported in the benchmarks PR comment
- [x] 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)
brettlangdon pushed a commit that referenced this pull request Jun 1, 2024
NOTE to apm-python reviewers: The only files this PR touches outside of
LLM Observability ownership are snapshot files.

This PR expands on #9417 by only set span.span_type = "llm" if LLMObs is
enabled. This means that we will not even attempt to process the given
span (i.e. set temporary LLMObs tags), which should minimize when the
affect LLMObs code has outside of LLMObs contexts. The majority of this
PR's LOC involves modifying all openai/langchain/bedrock snapshot files
to remove "type":"llm".

Existing tests should cover the reverted functionality.

## Checklist

- [x] Change(s) are motivated and described in the PR description
- [x] Testing strategy is described if automated tests are not included
in the PR
- [x] Risks are described (performance impact, potential for breakage,
maintainability)
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed or label `changelog/no-changelog` is set
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/))
- [x] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))
- [x] If this PR changes the public interface, I've notified
`@DataDog/apm-tees`.

## Reviewer Checklist

- [x] Title is accurate
- [x] All changes are related to the pull request's stated goal
- [x] Description motivates each change
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- [x] Testing strategy adequately addresses listed risks
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] Release note makes sense to a user of the library
- [x] Author has acknowledged and discussed the performance implications
of this PR as reported in the benchmarks PR comment
- [x] 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
backport 2.9 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