Skip to content

Add log.fetch() HTTP auto-instrumentation and W3C traceparent propaga…#188

Merged
lillem4n merged 5 commits into
masterfrom
feat/fetch-auto-instrumentation
Jun 19, 2026
Merged

Add log.fetch() HTTP auto-instrumentation and W3C traceparent propaga…#188
lillem4n merged 5 commits into
masterfrom
feat/fetch-auto-instrumentation

Conversation

@lillem4n

@lillem4n lillem4n commented Jun 19, 2026

Copy link
Copy Markdown
Member

…tion (v2.3.0)

Summary by CodeRabbit

  • New Features

    • Added log.fetch() method as a drop-in fetch replacement with automatic HTTP tracing and OpenTelemetry span creation
    • Implemented W3C trace context propagation for distributed tracing across services
    • Added configuration options to capture request/response headers and query strings (with redaction support)
    • New helper functions for trace context header formatting and parsing
  • Documentation

    • Updated documentation with usage examples and configuration details for HTTP tracing

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@lillem4n, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 27 minutes and 7 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 71713b11-eb48-45a7-9c5d-eaf4acb38b8c

📥 Commits

Reviewing files that changed from the base of the PR and between 7c49272 and 3ed081d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • README.md
  • index.ts
  • package.json
  • test.ts
📝 Walkthrough

Walkthrough

Version 2.3.0 adds W3C trace context support to the log library. Two new exported helpers (formatTraceparent, parseTraceparent) are introduced. The Log constructor gains optional incoming traceparent adoption, clone() is updated to avoid re-adopting it, and a new log.fetch() method wraps globalThis.fetch to create OTLP CLIENT spans with HTTP attribute recording, query redaction, header allow-lists, and error status mapping.

Changes

log.fetch() auto-instrumentation and W3C trace context propagation

Layer / File(s) Summary
LogConf/LogInt type extensions and trace context helpers
index.ts
LogConf adds captureQuery, captureRequestHeaders, captureResponseHeaders, and traceparent fields; LogInt adds the traceparent() method signature; formatTraceparent() and parseTraceparent() are exported.
Log constructor traceparent adoption and clone() isolation
index.ts
Constructor parses conf.traceparent when no parentLog is present, using parsed trace/span IDs during span init; clone() excludes traceparent from inherited config.
log.fetch() wrapper and URL/query helpers
index.ts
Adds SENSITIVE_QUERY_KEYS and buildUrlFull() for query redaction, then implements Log.traceparent() and Log.fetch(), which create a nested CLIENT span, inject traceparent headers, record OTel HTTP attributes with optional header capture, set error status on failures, and export the span asynchronously.
Test harness updates and new traceparent/fetch tests
test.ts
okResponse gains Headers, fetchResponse helper is added, stubFetch records request headers, callHeader() and clientSpan() helpers are added; new test blocks cover formatTraceparent/parseTraceparent round-trips, traceparent adoption/precedence/clone behavior, and all log.fetch() scenarios.
README, AGENTS.md docs and version bump
README.md, AGENTS.md, package.json
README adds log.fetch() usage, trace continuation docs, new config options, and a v2.3.0 changelog entry; AGENTS.md description is expanded; package version is bumped to 2.3.0.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant LogFetch as log.fetch
  participant globalFetch as globalThis.fetch
  participant OTLP as OTLP /v1/traces

  Caller->>LogFetch: fetch(url, init)
  LogFetch->>LogFetch: create nested CLIENT span
  LogFetch->>LogFetch: inject traceparent into request headers
  LogFetch->>LogFetch: buildUrlFull - redact or strip query
  LogFetch->>globalFetch: forward request
  globalFetch-->>LogFetch: Response or network error
  LogFetch->>LogFetch: record HTTP attrs and url.full
  LogFetch->>LogFetch: set error status on 4xx or 5xx
  LogFetch->>OTLP: export CLIENT span async via log.end()
  LogFetch-->>Caller: return Response or rethrow
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • larvit/log#178: Modifies Log.end() to await OTLP exports with a timeout — directly relevant because this PR's log.fetch() CLIENT spans rely on that same flush path.
  • larvit/log#179: Updates test.ts fetch stubbing and OTLP payload assertions — the same test infrastructure this PR further extends for log.fetch() and traceparent tests.

Poem

🐇 Hoppity-hop through the network I go,
Wrapping each fetch with a span in tow,
traceparent headers injected with care,
Query strings redacted — your secrets stay there,
CLIENT spans exported, the trace flows complete,
🌐 Distributed tracing — now isn't that neat!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding log.fetch() HTTP auto-instrumentation and W3C traceparent propagation, which directly align with the PR's primary objectives and file changes.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/fetch-auto-instrumentation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@AGENTS.md`:
- Line 7: The documentation in AGENTS.md overstates the auto-instrumentation
behavior of log.fetch(). Update line 7 to clarify that log.fetch() only
auto-instruments outgoing HTTP requests when provided with string or URL inputs
(as defined by the Log.fetch(input: string | URL) signature in index.ts), and
that other input shapes fall back to raw fetch without creating a client span.
This will accurately reflect the narrower contract of the implementation and
prevent agents from relying on instrumentation that is not guaranteed for all
fetch input types.

In `@README.md`:
- Around line 73-88: The README documentation overstates the capabilities of
log.fetch() by claiming it is a full drop-in replacement for fetch(). However,
based on the actual implementation in index.ts, log.fetch() only supports string
or URL inputs; when given a Request object, it falls back to plain fetch()
without instrumentation. Revise the documentation to clarify that log.fetch() is
a drop-in replacement only for string/URL based fetch calls, and note that
Request-based inputs will not receive OpenTelemetry instrumentation or trace
header injection.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 50faa494-cebf-40da-8e31-97e10a222b99

📥 Commits

Reviewing files that changed from the base of the PR and between 63d85df and 7c49272.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • AGENTS.md
  • README.md
  • index.ts
  • package.json
  • test.ts

Comment thread AGENTS.md
Comment thread README.md Outdated
@lillem4n lillem4n merged commit 13b0a02 into master Jun 19, 2026
9 checks passed
@lillem4n lillem4n deleted the feat/fetch-auto-instrumentation branch June 19, 2026 13:35
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