Skip to content

feat: send attributable User-Agent on REST and OAuth requests - #477

Merged
jwulf merged 9 commits into
mainfrom
feat/issue-476
Nov 19, 2026
Merged

jwulf merged 9 commits into
mainfrom
feat/issue-476

Conversation

@jwulf

@jwulf jwulf commented Nov 19, 2026

Copy link
Copy Markdown
Member

What

Every request the SDK sends now leads its User-Agent with camunda-orchestration-sdk-python/<version> (the installed distribution version via importlib.metadata), so gateway usage reports can attribute SDK traffic.

  • REST (sync + async, generated operations and raw requests via the underlying httpx client): new runtime/user_agent.py request hook, injected by hooks/post_gen/0900_flatten_client.py alongside the auth / cluster-admin hooks.
  • OAuth token request (sync + async providers): token httpx client is created with the same User-Agent.
  • Extracted the shared append_request_hook helper in runtime/cluster_admin_url.py (reused by the new hook; keeps the escape-hatch baseline flat).
  • Application user agent: new CAMUNDA_USER_AGENT config key (env or explicit configuration) is appended after the SDK token. A caller-supplied User-Agent header (headers=) is also appended rather than replacing it.
  • Removed the dead httpUserAgent setting from generator-config.yaml (ignored by openapi-python-client).
  • README config table updated (generated from the field description).

Tests (red → green)

tests/acceptance/test_user_agent.py was committed first and failed (python-httpx/0.28.1 sent, missing module/config key); now green. Covers sync + async REST and token requests, env/config app UA appending, caller header precedence, and the removed generator setting.

make generate && make lint && make typecheck && make test — all green (962 passed).

Commits are split per AGENTS.md: generator/runtime change, then chore(generation) regenerated output.

Backport

Labelled backport stable/10 and backport stable/9: verified runtime/auth.py, runtime/configuration_resolver.py, hooks/post_gen/0900_flatten_client.py (with inject_auth_event_hooks) and the httpUserAgent line all exist on both branches. Cherry-pick only the generator commit. Note: this adds a config key (additive, non-breaking).

Closes #476

Refs #476

Signed-off-by: Josh Wulf <josh@magikcraft.io>
Every request now leads its User-Agent with
camunda-orchestration-sdk-python/<version>. CAMUNDA_USER_AGENT (or a
caller-supplied User-Agent header) is appended, never replacing it.
Removes the dead httpUserAgent setting from generator-config.yaml.

Closes #476

Signed-off-by: Josh Wulf <josh@magikcraft.io>
Signed-off-by: Josh Wulf <josh@magikcraft.io>
@jwulf
jwulf requested a review from a team as a code owner November 19, 2026 07:00
@jwulf jwulf added backport stable/10 Backport to stable/10 after merge backport stable/9 Backport to stable/9 after merge labels Nov 19, 2026
Copilot AI balanced review requested due to automatic review settings November 19, 2026 07:00

Copilot AI 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.

🟡 Changes recommended

User-agent handling still drops caller-supplied header content or bypasses the installed SDK version and CAMUNDA_USER_AGENT, requiring a matching fix, sync/async tests, and regenerated runtime code.

1 open issue
What changed in this PR

Adds a versioned SDK User-Agent to REST and OAuth requests so gateway reports can identify Python SDK traffic, addressing #476.

Changes:

  • Adds sync/async request handling and CAMUNDA_USER_AGENT configuration for application identifiers.
  • Shares request-hook wiring and removes the ignored generator setting.
  • Adds acceptance tests and refreshes documentation, generated code, and type stubs.
File Description
tests/​acceptance/​test_user_agent.py Tests REST/OAuth headers and application identifiers.
stubs/​camunda_orchestration_sdk/​runtime/​user_agent.pyi Declares User-Agent helper interfaces.
stubs/​camunda_orchestration_sdk/​runtime/​configuration_resolver.pyi Exposes the application User-Agent setting.
stubs/​camunda_orchestration_sdk/​runtime/​cluster_admin_url.pyi Declares the shared request-hook helper.
stubs/​camunda_orchestration_sdk/​runtime/​auth.pyi Adds OAuth provider User-Agent parameters.
runtime/​user_agent.py Builds versioned headers and injects request hooks.
runtime/​configuration_resolver.py Registers and documents CAMUNDA_USER_AGENT.
runtime/​cluster_admin_url.py Extracts reusable request-hook appending logic.
runtime/​auth.py Sets headers on sync/async OAuth clients.
README.md Documents the application User-Agent setting.
hooks/​post_gen/​0900_flatten_client.py Wires User-Agent handling into generated clients.
generator-config.yaml Removes the ignored httpUserAgent option.
generated/​camunda_orchestration_sdk/​runtime/​user_agent.py Packages the User-Agent helpers and hooks.
generated/​camunda_orchestration_sdk/​runtime/​configuration_resolver.py Includes the new configuration setting.
generated/​camunda_orchestration_sdk/​runtime/​cluster_admin_url.py Includes the shared request-hook helper.
generated/​camunda_orchestration_sdk/​runtime/​auth.py Includes OAuth User-Agent handling.
generated/​camunda_orchestration_sdk/​client.py Connects configuration, REST hooks, and OAuth headers.

Review effort: Balanced

Comment thread runtime/user_agent.py Resolved
Refs #476

Signed-off-by: Josh Wulf <josh@magikcraft.io>
Signed-off-by: Josh Wulf <josh@magikcraft.io>
@jwulf

jwulf commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

🤖 The changes in this PR were produced by nano-agent, an autonomous agent. Commits are authored under the operator's own git identity when one is resolvable (the human running the fleet), so they can satisfy CLA/DCO requirements; this note records that the work was generated by the agent.

Copilot AI 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.

🔵 Needs a closer look

The publicly exported Client and AuthenticatedClient bypass the wrapper-only attribution hook, leaving direct sync and async REST requests without the SDK identifier in default headers.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Add SDK attribution to exported REST client factories

hooks/​post_gen/​0900_flatten_client.py:1312

The publicly exported Client and AuthenticatedClient bypass this wrapper-only hook, so direct sync/async REST requests with default headers still lack the SDK identifier. Add attribution to their httpx factories through the generator, preserving application-supplied suffixes, and cover both client types before regenerating. Same issue in the async wrapper at line 1552.

1 resolved since last review

Review effort: Balanced

The publicly exported Client and AuthenticatedClient bypassed the
CamundaClient wrapper's User-Agent hook, so direct sync/async REST
requests with default headers lacked the SDK identifier.

Install the hook in an attrs __attrs_post_init__ on both generated
classes via ensure_user_agent_hook (idempotent — the wrapper's own
injection is detected by a marker and never doubled). The async httpx
factory converts sync hooks to async via asyncify_user_agent_hooks,
preserving each hook's composed value (application suffix survives).

Raise the escape-hatch baseline for 3 new Any uses in the httpx
hook-conversion path (HttpxArgs is dict[str, Any]; the hook list holds
arbitrary callables).

Refs #476

Signed-off-by: Josh Wulf <josh@magikcraft.io>
…ribution

Signed-off-by: Josh Wulf <josh@magikcraft.io>
Comment thread hooks/post_gen/0900_flatten_client.py Resolved

Copilot AI 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.

🔵 Needs a closer look

Custom user agents replace SDK attribution on token requests in both synchronous and asynchronous OAuth providers.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve SDK attribution in OAuth token request user agent

runtime/​auth.py:213

Directly constructing OAuthClientCredentialsAuthProvider(..., user_agent="my-app/1.2") sends only the application value on token requests, losing SDK attribution. The async provider has the same issue at runtime/auth.py:456. Compose with build_user_agent(user_agent) in both providers, update the wrapper template to pass only CAMUNDA_USER_AGENT, and regenerate the SDK.

Review effort: Balanced

Both OAuthClientCredentialsAuthProvider and AsyncOAuthClientCredentialsAuthProvider
previously sent only the caller-supplied user_agent value on token requests,
losing SDK attribution. Compose with build_user_agent() so the SDK token
always leads and the application suffix follows.

The wrapper template now passes CAMUNDA_USER_AGENT directly (not pre-composed),
so the provider owns composition in one place.

Closes #476

Signed-off-by: Josh Wulf <josh@magikcraft.io>
Signed-off-by: Josh Wulf <josh@magikcraft.io>
Comment thread runtime/auth.py Resolved

Copilot AI 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.

🟢 Approval recommended

No active review issues block approval of the SDK User-Agent changes.

No open issues 🎉

Review effort: Balanced

@jwulf
jwulf merged commit be03747 into main Nov 19, 2026
27 checks passed
claude Bot pushed a commit that referenced this pull request Nov 19, 2026
Resolve the add/add conflict at the end of
tests/acceptance/test_pluggable_auth.py: keep this branch's
token-endpoint failure and expiry-boundary cases, and main's OAuth
User-Agent cases from #477. The two sets are independent; no test
was changed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RcVhnekJQeXnMfPhs9pYda
jwulf added a commit that referenced this pull request Nov 19, 2026
#477 to stable/10) (#478)

* feat: send attributable User-Agent on REST and OAuth requests (backport #477 to stable/10)

Backport of #477 (cherry picked from commit be03747), hand-written
sources only. The escape-hatch baseline is recounted on stable/10 (any: 363 -> 366).

* chore(gen): regenerate for backport of #477
jwulf added a commit that referenced this pull request Nov 19, 2026
#477 to stable/9) (#479)

* feat: send attributable User-Agent on REST and OAuth requests (backport #477 to stable/9)

Backport of #477 (cherry picked from commit be03747), ported by
hand. stable/9 has no runtime/cluster_admin_url.py, so user_agent.py carries its own HttpxArgs,
RequestHook and append_request_hook, and the OAuth providers take no clock argument. There is no
escape-hatch baseline on stable/9.

* chore(gen): regenerate for backport of #477

* fix: type the user-agent hook helpers for stable/9's strict pyright

* test: annotate the topology fixture for stable/9's strict pyright

* chore(gen): regenerate for user-agent typing fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport stable/9 Backport to stable/9 after merge backport stable/10 Backport to stable/10 after merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send an attributable User-Agent on REST and OAuth requests (camunda-orchestration-sdk-python/<version>)

2 participants