Skip to content

feat(http): add tracer header filter combinators to HttpClient#2132

Open
Zelys-DFKH wants to merge 1 commit intoEffect-TS:mainfrom
Zelys-DFKH:feat/httpclient-tracer-header-filter
Open

feat(http): add tracer header filter combinators to HttpClient#2132
Zelys-DFKH wants to merge 1 commit intoEffect-TS:mainfrom
Zelys-DFKH:feat/httpclient-tracer-header-filter

Conversation

@Zelys-DFKH
Copy link
Copy Markdown
Contributor

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Closes #2090. The issue describes it well: every request and response header lands in the span, including 15-30+ low-signal CDN headers (cf-ray, alt-svc, x-amz-cf-id, ...) with no API to restrict them. Headers.CurrentRedactedNames only redacts values — the attributes still emit. This adds a predicate-based filter that runs after redaction, so callers can drop headers from spans entirely.

Three new combinators:

  • withTracerRequestHeadersFilter(predicate) — controls which request headers appear on the span
  • withTracerResponseHeadersFilter(predicate) — controls which response headers appear on the span
  • withTracerHeadersFilter(predicate) — applies the same predicate to both

Plus two Context.Reference exports (TracerRequestHeadersFilter, TracerResponseHeadersFilter) for callers who prefer to set the filter via Effect.provideService directly.

The implementation follows the same Context.Reference + transformResponse + Effect.provideService pattern as TracerDisabledWhen, TracerPropagationEnabled, and SpanNameGenerator. Default is constTrue, so existing behavior is unchanged.

I went with separate request/response references rather than a single combined TracerHeaderFilter (as the issue suggested) because the two often warrant different policies — you might want all request headers for debugging but only x-request-id and content-type from responses. The combined withTracerHeadersFilter covers the common case where you want the same predicate for both.

Three tests added to HttpClient.test.ts, one per combinator.

This is a port of Effect-TS/effect#6215, redirected here by @tim-smart after Effect v3 entered feature freeze.

Related

Adds predicate-based filtering of which HTTP headers are recorded as OTEL
span attributes on HttpClient spans. Closes Effect-TS#2090.

New exports:
- TracerRequestHeadersFilter (Context.Reference)
- TracerResponseHeadersFilter (Context.Reference)
- withTracerRequestHeadersFilter(predicate)
- withTracerResponseHeadersFilter(predicate)
- withTracerHeadersFilter(predicate) — applies same predicate to both

Default is constTrue so existing behavior is unchanged. Follows the same
Context.Reference + transformResponse + Effect.provideService pattern as
SpanNameGenerator and TracerDisabledWhen.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 6, 2026

🦋 Changeset detected

Latest commit: 1d62110

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

HttpClient: allow filtering HTTP header span attributes (allowlist / predicate)

1 participant