Skip to content

Use context swap for Akka and Pekko HTTP flows - #12507

Open
amarziali wants to merge 5 commits into
masterfrom
andrea.marziali/fix-akka-pekko-http-context-swap
Open

amarziali wants to merge 5 commits into
masterfrom
andrea.marziali/fix-akka-pekko-http-context-swap

Conversation

@amarziali

@amarziali amarziali commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Akka and Pekko HTTP flows intentionally keep request context active while an
element moves through the stream.

With the legacy scope manager, the flow attaches a scope and relies on either
the response path or actor rollback to close it. With the new context manager,
the equivalent operation is a context swap rather than an attached scope.

This change:

  • Keeps the existing attach/close behavior in legacy mode.
  • Uses Context.swap() for HTTP flows with the new context manager.
  • Returns a closeable swap handle that can restore the previous context on
    synchronous and blocked-response paths.
  • Lets actor boundaries restore context after asynchronous processing when the
    flow no longer owns the current context.
  • Leaves async handlers unchanged because they own and close their scopes
    directly.
  • Separates the legacy cleanup test from the context-swap contract.
  • Adds context-swap and restoration tests for both Akka and Pekko.
flowchart TD
    A[HTTP request enters flow] --> B{Legacy context manager?}

    B -->|Yes| C[Attach request scope]
    C --> D[Process request]
    D --> E[Response closes scope<br/>or actor rollback cleans it up]

    B -->|No| F[Swap to request context<br/>and remember previous context]
    F --> G[Process request]
    G --> H{Request context still current<br/>when flow closes?}
    H -->|Yes| I[Restore previous context]
    H -->|No| J[Actor boundary restores context]

    E --> K[Finish request span]
    I --> K
    J --> K
Loading

Motivation

Avoid mixing legacy scope rollback with the new context manager while ensuring
that immediate completion paths cannot leave the request context active.

Additional Notes

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@amarziali
amarziali requested a review from a team as a code owner September 15, 2026 13:52
@amarziali
amarziali requested review from ygree and removed request for a team September 15, 2026 13:52
@amarziali amarziali added type: bug fix Bug fix inst: akka Akka instrumentation labels Sep 15, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-15T14:41:36.399243Z eaf2cf7 Manual request
🔒 Security Review Completed 2026-09-15T14:39:07.847187Z eaf2cf7 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f7c999133

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Datadog Autotest: PASS

More details

The flow path keeps legacy attach behavior and uses context swap with the new context manager. Async handlers keep their own scopes.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Datadog Autotest · Commit 4f7c999 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@datadog-official

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 13.98 s 13.94 s [-0.5%; +1.2%] (no difference)
startup:insecure-bank:tracing:Agent 12.87 s 12.95 s [-1.3%; -0.0%] (maybe better)
startup:petclinic:appsec:Agent 17.61 s 17.44 s [+0.1%; +1.8%] (maybe worse)
startup:petclinic:iast:Agent 17.33 s 16.95 s [-2.1%; +6.6%] (no difference)
startup:petclinic:profiling:Agent 17.26 s 17.41 s [-1.8%; +0.1%] (no difference)
startup:petclinic:sca:Agent 17.47 s 17.34 s [-0.3%; +1.8%] (no difference)
startup:petclinic:tracing:Agent 16.55 s 16.23 s [-2.4%; +6.3%] (no difference)

Commit: 93781bdb · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@amarziali
amarziali force-pushed the andrea.marziali/fix-akka-pekko-http-context-swap branch from 43f284a to eaf2cf7 Compare September 15, 2026 14:33
@amarziali

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: eaf2cf7494

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: eaf2cf7494

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@amarziali
amarziali requested a review from mcculls September 15, 2026 14:48

@ygree ygree left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: akka Akka instrumentation type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants