Skip to content

Send Python SDK user agent on control-plane requests#191

Open
chirag03k wants to merge 1 commit into
mainfrom
ckawediya/controlplane-user-agent
Open

Send Python SDK user agent on control-plane requests#191
chirag03k wants to merge 1 commit into
mainfrom
ckawediya/controlplane-user-agent

Conversation

@chirag03k

@chirag03k chirag03k commented Jul 14, 2026

Copy link
Copy Markdown

Summary

  • Add the Python SDK User-Agent to the generated control-plane client during autoload
  • Keep sending Blaxel-Version for paginated control-plane endpoints
  • Cover the autoload header behavior in tests

Why

Sandbox creation through the Python SDK was reaching PostHog as request_origin=api with request_user_agent=python-httpx/..., so backend observability could not extract sdk-version or sdk-language=python.

Tests

  • pytest tests/core/test_environment.py tests/core/test_settings_api_version.py -q
  • ruff format --check src/blaxel/core/common/autoload.py tests/core/test_environment.py
  • ruff check src/blaxel/core/common/autoload.py tests/core/test_environment.py

Note

Adds the Python SDK User-Agent header to the generated control-plane client during autoload, alongside the existing Blaxel-Version header. Adds a test verifying both headers are set.

Written by Mendral for commit 9379bb6.

@mendral-app

mendral-app Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🧪 Testing Guide

What this PR addresses

The Python SDK's control-plane HTTP client (used for sandbox creation, etc.) was not sending the SDK-specific User-Agent header. This caused backend observability (PostHog) to see requests as generic python-httpx/<version> instead of blaxel/sdk/python/<version>, making it impossible to extract SDK name or version from telemetry data.

Steps to reproduce the original issue

  1. Before this PR, inspect the headers sent by the control-plane client after autoload() runs.
  2. Observe that User-Agent is not explicitly set — httpx defaults to python-httpx/x.y.z.
  3. In PostHog (or equivalent backend telemetry), SDK-originated requests are indistinguishable from raw httpx calls.

What to verify (expected behavior)

  1. Run the new test:

    pytest tests/core/test_environment.py::test_autoload_sets_control_plane_user_agent -q

    It should pass, confirming the client carries both Blaxel-Version and a User-Agent starting with blaxel/sdk/python/.

  2. Run the existing settings test to check for regressions:

    pytest tests/core/test_environment.py tests/core/test_settings_api_version.py -q
  3. Lint check (no formatting/style regressions):

    ruff format --check src/blaxel/core/common/autoload.py tests/core/test_environment.py
    ruff check src/blaxel/core/common/autoload.py tests/core/test_environment.py
  4. Verify the User-Agent value is sourced from settings.headers["User-Agent"] — the same header already used for other SDK requests — ensuring consistency across all outbound traffic.

Note

Posted by PR Testing Guide · Tag @mendral-app with feedback.

@mendral-app

mendral-app Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Interaction Flow

sequenceDiagram
    participant App as Application
    participant AL as autoload()
    participant Settings as settings
    participant Client as client (httpx)
    participant CP as Control Plane API

    App->>AL: autoload()
    AL->>Settings: read base_url, auth
    AL->>Settings: read api_version
    AL->>Settings: read headers["User-Agent"]
    AL->>Client: with_headers({"Blaxel-Version": ..., "User-Agent": ...})
    Client->>CP: HTTP request
    Note right of CP: Headers now include:<br/>Blaxel-Version: 2026-04-28<br/>User-Agent: blaxel/sdk/python/x.y.z
    CP-->>CP: PostHog observability<br/>classifies SDK traffic
Loading

Summary: The autoload() function now propagates the Python SDK User-Agent header (alongside the existing Blaxel-Version) from settings into the control-plane client. This lets backend observability (PostHog) distinguish Python SDK traffic from generic python-httpx requests.

Note

Posted by PR Sequence Diagram · Tag @mendral-app with feedback.

@mendral-app mendral-app 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.

LGTM

Change is minimal and correct. settings.headers["User-Agent"] is evaluated once at autoload time and stored as a static header—no repeated property evaluation or auth-token leakage risk. The riskiest aspect (accidentally sending auth headers via settings.headers) is avoided because only the User-Agent key is extracted explicitly.

Tag @mendral-app with feedback or questions. View session

@mendral-app

mendral-app Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

✅ Linked to Linear issue ENG-3781 — status: In Review

Note

Posted by Linear Issue Enforcer · Tag @mendral-app with feedback.

@chirag03k

Copy link
Copy Markdown
Author

This is complementary to https://github.com/blaxel-ai/controlplane/pull/4816 which sends tracks SDK information, among other things, upon sandbox creation.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant