Skip to content

feat: Add parent_request_id to server().request method - #1214

Open
janbuchar wants to merge 1 commit into
masterfrom
composition-actor-request-id
Open

janbuchar wants to merge 1 commit into
masterfrom
composition-actor-request-id

Conversation

@janbuchar

Copy link
Copy Markdown
Contributor

@janbuchar
janbuchar requested a review from szaganek as a code owner November 9, 2026 15:24
@janbuchar janbuchar added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Nov 9, 2026
@janbuchar
janbuchar requested review from Pijukatel and vdusek November 9, 2026 15:24
@janbuchar janbuchar self-assigned this Nov 9, 2026
@apify-service-account apify-service-account added the tested Temporary label used only programatically for some analytics. label Nov 9, 2026
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.73%. Comparing base (e521a24) to head (1a51641).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/apify_client/_resource_clients/actor_server.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1214   +/-   ##
=======================================
  Coverage   95.73%   95.73%           
=======================================
  Files          63       63           
  Lines        6676     6680    +4     
=======================================
+ Hits         6391     6395    +4     
  Misses        285      285           
Flag Coverage Δ
integration 90.98% <50.00%> (+0.11%) ⬆️
unit 90.86% <75.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Pijukatel Pijukatel 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.

Just some small suggestions.

server_url = self.get_url()
server_path = path.partition('#')[0].lstrip('/')
if parent_request_id is not None:
headers = self._http_client._merge_headers(headers, {'X-Actor-Request-ID': parent_request_id}) # noqa: SLF001

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.

Can we refactor it a little so that we do not need # noqa: SLF001 ? Since we need the method outside, may it is time to make it less private?

response = await server_client.request(
'/search',
params={'q': 'apify'},
parent_request_id=request.headers['x-actor-request-id'],

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.

There are 2 requests in the snippet. One we are sending and the one we have received and are handling right now. I do not think it is obvious from the snippet. Could you either name it differently (incoming_request.headers or handled_request.headers ...) or add some context around the snippet?

@vdusek vdusek 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.

Chore - no changelog mention?

Comment on lines +194 to +195
parent_request_id: The `X-Actor-Request-ID` header of the request your Server Actor is handling, sent on
as the same header so the called Actor charges at that request's pricing tier.

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.

The method docstring above and the docs page (line 77) say that headers from headers reach the server as they are. parent_request_id replaces one of them, so I'd say it here (and in the async twin):

Suggested change
parent_request_id: The `X-Actor-Request-ID` header of the request your Server Actor is handling, sent on
as the same header so the called Actor charges at that request's pricing tier.
parent_request_id: The `X-Actor-Request-ID` header of the request your Server Actor is handling, sent on
as the same header so the called Actor charges at that request's pricing tier. It replaces an
`X-Actor-Request-ID` passed in `headers`.

✍️ Drafted by Claude Code


When your multi-tenant Server Actor calls another one while handling a request, pass the incoming `X-Actor-Request-ID` header in `parent_request_id`. The client sends it as the same header, so the called Actor charges at the pricing tier of your incoming request. Use a client created with the run's `APIFY_TOKEN`. For details, see [Compose multi-tenant Server Actors](https://docs.apify.com/platform/actors/development/programming-interface/standby#compose-server-actors).

```python

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.

Could this go into dedicated test files like all other code examples so ruff and ty can check it?

assert captured[0].headers['X-Apify-Authorization'] == 'Bearer test'


def test_request_sends_parent_request_id_header(httpserver: HTTPServer, sync_client: ApifyClient) -> None:

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.

Async counterpart of this test?

@janbuchar janbuchar changed the title chore: Add parentRequestId to server().request method feat: Add parent_request_id to server().request method Nov 10, 2026

This branch has not been deployed

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

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants