Skip to content

Feat/56 observability header redaction#68

Merged
Lakes41 merged 2 commits into
Adamantine-guild:mainfrom
Amarjeet325:feat/56-observability-header-redaction
Jun 21, 2026
Merged

Feat/56 observability header redaction#68
Lakes41 merged 2 commits into
Adamantine-guild:mainfrom
Amarjeet325:feat/56-observability-header-redaction

Conversation

@Amarjeet325

Copy link
Copy Markdown
Contributor

Description

This PR introduces request and response header redaction for the HTTP client's observability hooks. It ensures that hook payloads expose useful metadata (like request and response headers) without leaking sensitive information such as API keys, authorization tokens, or cookies.

Semver impact: minor

Linked Issue

Closes #56

Type of Change

  • 🐛 Bug fix (patch)
  • ✨ New feature / method (minor)
  • 💥 Breaking change (major)
  • 📝 Documentation / TypeDoc update
  • 🔧 Chore / refactor
  • 🧪 Tests only

Changes Made

  • src/http/http.types.ts: Expanded RequestHookPayload and ResponseHookPayload types to include the headers and responseHeaders properties. Both are typed to indicate they have been safely redacted.
  • src/http/httpClient.ts: Implemented a new redactHeaders utility helper that replaces known sensitive headers (authorization, x-api-key, cookie, set-cookie) with [REDACTED]. Applied this helper to format headers inside the onRequest and onResponse hook payloads.
  • tests/httpClient.test.ts: Updated observability hook tests to explicitly assert that sensitive headers are redacted while safe headers remain intact.
  • docs/sdk-guide.md: Updated the documentation to reflect the availability of header metadata in hook payloads and added a warning against logging sensitive application data.

Public API Changes

// New exported utility function:
export function redactHeaders(headers: Headers | Record<string, string>): Record<string, string>;

// Modified types:
export type RequestHookPayload = {
  method: HttpMethod;
  path: string;
  /** Safely redacted headers. Sensitive values are replaced with '[REDACTED]'. */
  headers: Record<string, string>;
};

export type ResponseHookPayload = RequestHookPayload & {
  status: number;
  durationMs: number;
  /** Safely redacted response headers. Sensitive values are replaced with '[REDACTED]'. */
  responseHeaders: Record<string, string>;
};

Fixes Adamantine-guild#56

This commit introduces a redactHeaders helper to ensure sensitive information such as API keys, authorization headers, and cookies are not leaked to user-defined observability hook callbacks.

Changes:

- Expanded RequestHookPayload and ResponseHookPayload to include safely redacted headers and responseHeaders.

- Added a redactHeaders utility function in httpClient.ts that filters out a default list of sensitive keys (authorization, x-api-key, cookie, set-cookie).

- Updated test coverage to assert redaction logic correctly intercepts known sensitive headers.

- Updated SDK guide documentation to describe the hook payload changes.

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

Very well done,

@Lakes41 Lakes41 merged commit 96cd555 into Adamantine-guild:main Jun 21, 2026
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.

Add request and response redaction for observability hooks

2 participants