Skip to content

refactor: remove some layering violations related to Span type in ASM - #19863

Open
emmettbutler wants to merge 41 commits into
mainfrom
emmett.butler/appsec-span-proto
Open

refactor: remove some layering violations related to Span type in ASM#19863
emmettbutler wants to merge 41 commits into
mainfrom
emmett.butler/appsec-span-proto

Conversation

@emmettbutler

@emmettbutler emmettbutler commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

This change factors out some layering violations incurred by the import of Span for the purpose of type annotation in the AppSec module.

@emmettbutler
emmettbutler requested a review from a team as a code owner August 25, 2026 18:17
@emmettbutler
emmettbutler requested a review from avara1986 August 25, 2026 18:17
@emmettbutler
emmettbutler marked this pull request as draft August 25, 2026 18:17
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 25, 2026

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 230 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 230 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=134)
ddtrace.internal.ci_visibility.api._base -×-> ddtrace.trace  (product:ci_visibility -> product:tracing, score=132)
ddtrace.llmobs._integrations.anthropic -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=132)
ddtrace.llmobs._integrations.langchain -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=132)
ddtrace.internal.opentelemetry.span -×-> ddtrace.trace  (product:opentelemetry -> product:tracing, score=132)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

✅ Dependency direction violations removed

10 violation(s) have been removed by this PR.

Show removed violations (showing 5 of 10 highest severity)
ddtrace.appsec._contrib.flask -×-> ddtrace.trace  (product:appsec -> product:tracing, score=133)
ddtrace.appsec._asm_request_context -×-> ddtrace._trace.span  (product:appsec -> product:tracing, score=55)
ddtrace.appsec._handlers -×-> ddtrace._trace.span  (product:appsec -> product:tracing, score=55)
ddtrace.appsec._contrib.aws_lambda -×-> ddtrace._trace.span  (product:appsec -> product:tracing, score=55)
ddtrace.appsec._iast.processor -×-> ddtrace._trace.span  (product:appsec -> product:tracing, score=55)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Aug 25, 2026

Copy link
Copy Markdown

Pipelines  Tests

Unblock PR with BitsAI

⚠️ Warnings

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 12 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-py | build linux serverless: [amd64, cp315-cp315, v113741238-d2b8243-manylinux2014_x86_64, 1] — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

DataDog/apm-reliability/dd-trace-py | build linux serverless: [arm64, cp315-cp315, v113741357-d2b8243-manylinux2014_aarch64, 1] — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

DataDog/apm-reliability/dd-trace-py | build linux: [amd64, cp315-cp315, v113741238-d2b8243-manylinux2014_x86_64] — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

View all 12 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

🔄 Datadog auto-retried 4 jobs - 4 passed on retry View in Datadog

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 746d710 | Docs | View more details | Give us feedback!

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

ddtrace/appsec/_asm_request_context.py                                  @DataDog/asm-python
ddtrace/appsec/_contrib/aws_lambda/__init__.py                          @DataDog/asm-python
ddtrace/appsec/_contrib/django/__init__.py                              @DataDog/asm-python
ddtrace/appsec/_contrib/flask/__init__.py                               @DataDog/asm-python
ddtrace/appsec/_exploit_prevention/stack_traces.py                      @DataDog/asm-python
ddtrace/appsec/_handlers.py                                             @DataDog/asm-python
ddtrace/appsec/_iast/_iast_env.py                                       @DataDog/asm-python
ddtrace/appsec/_iast/_iast_request_context.py                           @DataDog/asm-python
ddtrace/appsec/_iast/_overhead_control_engine.py                        @DataDog/asm-python
ddtrace/appsec/_iast/processor.py                                       @DataDog/asm-python
ddtrace/appsec/_processor.py                                            @DataDog/asm-python
ddtrace/appsec/_trace_utils.py                                          @DataDog/asm-python
ddtrace/appsec/_utils.py                                                @DataDog/asm-python
ddtrace/appsec/track_user_sdk.py                                        @DataDog/asm-python
ddtrace/contrib/internal/trace_utils_base.py                            @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/internal/appsec/prototypes.py                                   @DataDog/asm-python

@pr-commenter

pr-commenter Bot commented Aug 25, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-26 18:37:40

Comparing candidate commit 746d710 in PR branch emmett.butler/appsec-span-proto with baseline commit 160fd51 in branch main.

📊 Benchmarking dashboard

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

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+112.612µs; +119.293µs] or [+28.196%; +29.868%]

@emmettbutler
emmettbutler force-pushed the emmett.butler/appsec-span-proto branch from efbc9e6 to abe0ab7 Compare August 25, 2026 18:48
@emmettbutler
emmettbutler changed the base branch from main to emmett.butler/native-context-2 August 25, 2026 18:48
@emmettbutler emmettbutler added the changelog/no-changelog A changelog entry is not required for this PR. label Aug 25, 2026
@emmettbutler emmettbutler changed the title Emmett.butler/appsec span proto refactor: remove some layering violations related to Span type in ASM Aug 25, 2026
This change completes the migration of the `Context` class to native code and uses this relocation to resolve some dependency direction violations.

Original commits:
* 38ef60b migrate Context to native
* c6f748b Merge branch 'main' into emmett.butler/native-context
* bbada76 Merge branch 'main' into emmett.butler/native-context
* d834b0a dont silently ignore non-context values
* 85d2351 span_id same type as trace_id
* 8e448be undo
* cd0f567 missed spots
* 590b576 accept string span_ids to accommodate existing lambda repo test
* 10560a7 remove misleading comment
* 14b363b clean possible state from previous tests
* 7b13a50 Merge branch 'main' into emmett.butler/native-context
* f1a7d02 move the rest of the Context functionality to ContextData
* a2be13d fix double-borrow
* 65b107b fix type
* f8f5e7a remove descriptive comments
* 433c349 entirely replace Context with native
* 692e688 fix import errors
* 71aec91 cargo fmt
* 89398f6 update imports to avoid layering violations
* cd5a2c6 fix some PR comments
* 017cc34 Merge branch 'emmett.butler/native-context' into emmett.butler/native-context-2
* 32e6d77 Merge branch 'main' into emmett.butler/native-context-2
* d054801 native lock instead of python threading
* 7ec4e55 args/kwargs not necessary
* 0e5e60f clippy
* 5c77276 remove locking
* 79d06af inlines, remove Option
* 30cd0ea Merge branch 'main' into emmett.butler/native-context-2
* 687ff85 update merged import
* 78d9605 update signature

Signed-off-by: Emmett Butler <emmett.butler@datadoghq.com>
@emmettbutler
emmettbutler force-pushed the emmett.butler/native-context-2 branch from 78d9605 to 2051f3b Compare August 25, 2026 19:37
Base automatically changed from emmett.butler/native-context-2 to main August 26, 2026 14:28
@emmettbutler
emmettbutler marked this pull request as ready for review August 26, 2026 14:42
@emmettbutler
emmettbutler requested review from a team as code owners August 26, 2026 14:42

@brettlangdon brettlangdon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

trace utils base lgtm

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