Skip to content

fix(tracing): truncate long span attributes #13270

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

Merged
merged 20 commits into from
Apr 29, 2025

Conversation

quinna-h
Copy link
Contributor

@quinna-h quinna-h commented Apr 24, 2025

Truncate span resource name, tag key and tag values.

Previously, a very large resource name would result in a runtime error during encoding.

If any of these have over 25000 chars, this will truncate them to up to 2500 chars (and include the suffix <truncated>)
The agent will truncate based on the limits here

Resolves:

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

Copy link
Contributor

github-actions bot commented Apr 24, 2025

CODEOWNERS have been resolved as:

releasenotes/notes/truncate-long-span-attributes-a4900ee9844160b4.yaml  @DataDog/apm-python
tests/snapshots/tests.integration.test_integration_snapshots.test_encode_span_with_large_string_attributes[v0.4].json  @DataDog/apm-python
tests/snapshots/tests.integration.test_integration_snapshots.test_encode_span_with_large_string_attributes[v0.5].json  @DataDog/apm-python
ddtrace/_trace/_limits.py                                               @DataDog/apm-sdk-api-python
ddtrace/internal/_encoding.pyx                                          @DataDog/apm-core-python
tests/integration/test_integration.py                                   @DataDog/apm-core-python
tests/integration/test_integration_snapshots.py                         @DataDog/apm-core-python

Copy link
Contributor

github-actions bot commented Apr 24, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 233 ± 2 ms.

The average import time from base is: 235 ± 2 ms.

The import time difference between this PR and base is: -2.1 ± 0.1 ms.

Import time breakdown

The following import paths have appeared:

ddtrace.auto 0.901 ms (0.39%)
ddtrace 0.901 ms (0.39%)
ddtrace._logger 0.901 ms (0.39%)
ddtrace.internal.telemetry 0.901 ms (0.39%)
ddtrace.internal.telemetry.writer 0.901 ms (0.39%)
ddtrace.internal.encoding 0.901 ms (0.39%)
ddtrace.internal._encoding 0.901 ms (0.39%)
ddtrace._trace._limits 0.901 ms (0.39%)
ddtrace._trace 0.128 ms (0.05%)

The following import paths have disappeared:

ddtrace.auto 0.488 ms (0.21%)
ddtrace 0.488 ms (0.21%)
ddtrace.trace 0.488 ms (0.21%)
ddtrace._trace.context 0.258 ms (0.11%)
ddtrace._trace 0.258 ms (0.11%)
ddtrace._trace.filters 0.231 ms (0.10%)
ddtrace._trace.processor 0.231 ms (0.10%)
ddtrace._trace.sampler 0.231 ms (0.10%)
ddtrace._trace.span 0.231 ms (0.10%)
ddtrace._trace._limits 0.231 ms (0.10%)

The following import paths have grown:

ddtrace.auto 0.631 ms (0.27%)
ddtrace 0.391 ms (0.17%)
ddtrace.trace 0.375 ms (0.16%)
ddtrace._trace.filters 0.278 ms (0.12%)
ddtrace._trace.processor 0.278 ms (0.12%)
ddtrace.internal.dogstatsd 0.105 ms (0.05%)
ddtrace.vendor.dogstatsd 0.105 ms (0.05%)
ddtrace.vendor.dogstatsd.base 0.105 ms (0.05%)
queue 0.105 ms (0.05%)
heapq 0.105 ms (0.05%)
ddtrace.internal.writer 0.092 ms (0.04%)
ddtrace.internal.writer.writer 0.092 ms (0.04%)
ddtrace.internal.writer.writer_client 0.092 ms (0.04%)
ddtrace._trace.sampler 0.080 ms (0.03%)
ddtrace._trace.span 0.080 ms (0.03%)
ddtrace.internal.sampling 0.080 ms (0.03%)
ddtrace._trace.sampling_rule 0.080 ms (0.03%)
ddtrace._trace.tracer 0.097 ms (0.04%)
ddtrace.internal.processor.endpoint_call_counter 0.097 ms (0.04%)
ddtrace.settings._config 0.016 ms (0.01%)
ddtrace.settings.endpoint_config 0.016 ms (0.01%)
ddtrace.bootstrap.sitecustomize 0.241 ms (0.10%)
ddtrace.bootstrap.preload 0.241 ms (0.10%)
ddtrace.internal.products 0.241 ms (0.10%)
importlib.metadata 0.165 ms (0.07%)
csv 0.103 ms (0.04%)
importlib.metadata._collections 0.062 ms (0.03%)
ddtrace.internal.remoteconfig._connectors 0.075 ms (0.03%)
ctypes 0.075 ms (0.03%)

The following import paths have shrunk:

ddtrace.auto 3.264 ms (1.40%)
ddtrace 1.722 ms (0.74%)
ddtrace._logger 0.594 ms (0.26%)
ddtrace.internal.telemetry 0.594 ms (0.26%)
ddtrace.internal.telemetry.writer 0.594 ms (0.26%)
ddtrace.internal.encoding 0.579 ms (0.25%)
ddtrace.internal._encoding 0.579 ms (0.25%)
ddtrace.internal.periodic 0.015 ms (0.01%)
ddtrace.trace 0.455 ms (0.20%)
ddtrace._trace.filters 0.285 ms (0.12%)
ddtrace._trace.processor 0.285 ms (0.12%)
ddtrace.internal.dogstatsd 0.104 ms (0.04%)
ddtrace.vendor.dogstatsd 0.104 ms (0.04%)
ddtrace.vendor.dogstatsd.base 0.104 ms (0.04%)
queue 0.104 ms (0.04%)
ddtrace.internal.writer 0.092 ms (0.04%)
ddtrace.internal.writer.writer 0.092 ms (0.04%)
ddtrace.internal.sma 0.092 ms (0.04%)
ddtrace._trace.sampler 0.089 ms (0.04%)
ddtrace._trace.span 0.089 ms (0.04%)
ddtrace.internal.sampling 0.089 ms (0.04%)
ddtrace._trace.tracer 0.102 ms (0.04%)
ddtrace.internal.peer_service.processor 0.102 ms (0.04%)
ddtrace._trace.context 0.069 ms (0.03%)
ddtrace.bootstrap.sitecustomize 1.542 ms (0.66%)
ddtrace.bootstrap.preload 1.523 ms (0.65%)
ddtrace.internal.products 1.523 ms (0.65%)
ddtrace.internal.remoteconfig.client 0.639 ms (0.27%)
importlib.metadata 0.161 ms (0.07%)
importlib.metadata._meta 0.069 ms (0.03%)
ddtrace.internal.remoteconfig._connectors 0.056 ms (0.02%)
ctypes 0.056 ms (0.02%)
_ctypes 0.056 ms (0.02%)
ddtrace.appsec._common_module_patches 0.019 ms (0.01%)

@pr-commenter
Copy link

pr-commenter bot commented Apr 24, 2025

Benchmarks

Benchmark execution time: 2025-04-29 15:49:33

Comparing candidate commit fac94e0 in PR branch quinna/truncate-long-attributes with baseline commit ea64efc in branch main.

Found 12 performance improvements and 0 performance regressions! Performance is the same for 489 metrics, 7 unstable metrics.

scenario:packagesupdateimporteddependencies-import_many

  • 🟩 execution_time [-27.157ms; -27.008ms] or [-99.696%; -99.152%]

scenario:packagesupdateimporteddependencies-import_many_cached

  • 🟩 execution_time [-26.833µs; -25.623µs] or [-18.171%; -17.352%]

scenario:packagesupdateimporteddependencies-import_many_stdlib

  • 🟩 execution_time [-719.485ms; -716.024ms] or [-100.139%; -99.657%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • 🟩 execution_time [-719.228ms; -715.786ms] or [-100.216%; -99.737%]

scenario:packagesupdateimporteddependencies-import_many_unknown

  • 🟩 execution_time [-29.890ms; -29.744ms] or [-97.540%; -97.061%]

scenario:packagesupdateimporteddependencies-import_many_unknown_cached

  • 🟩 execution_time [-237.463µs; -221.987µs] or [-23.168%; -21.658%]

scenario:packagesupdateimporteddependencies-import_one

  • 🟩 execution_time [-11.252ms; -11.205ms] or [-100.030%; -99.618%]

scenario:packagesupdateimporteddependencies-import_one_cache

  • 🟩 execution_time [-740.439ns; -656.121ns] or [-10.580%; -9.375%]

scenario:packagesupdateimporteddependencies-import_one_stdlib

  • 🟩 execution_time [-10.291ms; -10.223ms] or [-100.148%; -99.489%]

scenario:packagesupdateimporteddependencies-import_one_stdlib_cache

  • 🟩 execution_time [-651.269ns; -573.875ns] or [-9.416%; -8.297%]

scenario:packagesupdateimporteddependencies-import_one_unknown

  • 🟩 execution_time [-19.618ms; -19.522ms] or [-100.009%; -99.522%]

scenario:packagesupdateimporteddependencies-import_one_unknown_cache

  • 🟩 execution_time [-769.010ns; -691.756ns] or [-10.992%; -9.888%]

@quinna-h quinna-h requested review from mabdinur and wantsui April 25, 2025 19:20
@quinna-h quinna-h changed the title chore(tracing): truncate long span attributes fix(tracing): truncate long span attributes Apr 25, 2025
@quinna-h quinna-h marked this pull request as ready for review April 28, 2025 14:08
@quinna-h quinna-h requested review from a team as code owners April 28, 2025 14:08
@quinna-h quinna-h requested a review from juanjux April 28, 2025 14:08
add release note

update test and snapshot
@quinna-h quinna-h force-pushed the quinna/truncate-long-attributes branch from 3b9bf18 to d21d413 Compare April 28, 2025 14:43
Copy link
Contributor

@mabdinur mabdinur left a comment

Choose a reason for hiding this comment

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

left some non blocking changes, thanks for pushing through

@quinna-h quinna-h enabled auto-merge (squash) April 29, 2025 19:05
@quinna-h quinna-h merged commit 5aa32d1 into main Apr 29, 2025
668 of 669 checks passed
@quinna-h quinna-h deleted the quinna/truncate-long-attributes branch April 29, 2025 19:06
Copy link
Contributor

The backport to 3.3 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-3.3 3.3
# Navigate to the new working tree
cd .worktrees/backport-3.3
# Create a new branch
git switch --create backport-13270-to-3.3
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 5aa32d185920544be12ca8372c74672b4f171a44
# Push it to GitHub
git push --set-upstream origin backport-13270-to-3.3
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-3.3

Then, create a pull request where the base branch is 3.3 and the compare/head branch is backport-13270-to-3.3.

Copy link
Contributor

The backport to 3.4 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-3.4 3.4
# Navigate to the new working tree
cd .worktrees/backport-3.4
# Create a new branch
git switch --create backport-13270-to-3.4
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 5aa32d185920544be12ca8372c74672b4f171a44
# Push it to GitHub
git push --set-upstream origin backport-13270-to-3.4
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-3.4

Then, create a pull request where the base branch is 3.4 and the compare/head branch is backport-13270-to-3.4.

brettlangdon pushed a commit that referenced this pull request May 6, 2025
Truncate span resource name, tag key and tag values.

Previously, a very large resource name would result in a runtime error
during encoding.

If any of these have over 25000 chars, this will truncate them to up to
2500 chars (and include the suffix `<truncated>`)
The agent will truncate based on the limits
[here](https://docs.datadoghq.com/tracing/troubleshooting/?tab=java#data-volume-guidelines)

Resolves:
- #13221
- #6587

## 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
- [ ] 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)

---------

Co-authored-by: Munir Abdinur <[email protected]>
Co-authored-by: wan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants