Skip to content

docs: add documentation for experimental browser proxy handler#1742

Open
AlanPonnachan wants to merge 4 commits intopydantic:mainfrom
AlanPonnachan:docs/browser-proxy-handler
Open

docs: add documentation for experimental browser proxy handler#1742
AlanPonnachan wants to merge 4 commits intopydantic:mainfrom
AlanPonnachan:docs/browser-proxy-handler

Conversation

@AlanPonnachan
Copy link
Contributor

Summary

This PR adds the documentation for the newly merged experimental browser proxy handler (logfire.experimental.forwarding.logfire_proxy) introduced in #1697.

It bridges the gap between frontend browser telemetry and Python backends by explaining how to securely route OTLP payloads to Logfire without exposing the Write Token in the client-side code.

Changes Made

  • docs/integrations/javascript/browser.md:
    • Updated the "Securely Sending Traces" admonition to explicitly mention the new Python built-in handler.
    • Added cross-reference links to the FastAPI and Starlette documentation.
    • Updated the TS example to show url.pathname = "/logfire-proxy/v1/traces".
  • docs/integrations/web-frameworks/fastapi.md:
    • Added a "Proxying Browser Telemetry" section.
    • Provided idiomatic FastAPI examples showing how to mount the handler using @app.post while injecting the Request object.
    • Included an example demonstrating how to protect the unauthenticated endpoint using FastAPI's Depends (addressing security considerations discussed in the previous PR).
  • docs/integrations/web-frameworks/starlette.md:
    • Added a "Proxying Browser Telemetry" section.
    • Provided an example of mounting the handler directly as a Starlette Route.
    • Added a security admonition regarding authentication and rate-limiting for production use.

devin-ai-integration[bot]

This comment was marked as resolved.

@codecov
Copy link

codecov bot commented Feb 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

!!! info "Securely Sending Traces"
Logfire does not directly expose an endpoint suitable for sending traces from the browser, as this would make your write token publicly accessible.

To safely send traces, you must route them through a backend proxy that attaches the `Authorization` header server-side.
Copy link
Contributor

Choose a reason for hiding this comment

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

the deleted "forwards requests from your browser instrumentation to Logfire" was good to have for clarity

Logfire does not directly expose an endpoint suitable for sending traces from the browser, as this would make your write token publicly accessible.

To safely send traces, you must route them through a backend proxy that attaches the `Authorization` header server-side.
- **Python:** Use the built-in `logfire_proxy` handler for [FastAPI](../web-frameworks/fastapi.md#proxying-browser-telemetry) or [Starlette](../web-frameworks/starlette.md#proxying-browser-telemetry).
Copy link
Contributor

Choose a reason for hiding this comment

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

the forward_export_request function is worth mentioning for generic usage.

It can also be useful for grouping together child logs and spans produced by the request.


## Proxying Browser Telemetry
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think this belongs on this page, same for starlette. it's not about how to instrument fastapi. i think the browser page should get a proper section on the topic with this info, explaining how to do it with fastapi, starlette, or anything else. the fastapi and starlette pages can briefly mention and link to that.

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.

2 participants