Skip to content

feature: add CapacitorHttp support - Issue#820 - #1387

Open
MuriloZF wants to merge 6 commits into
getsentry:mainfrom
MuriloZF:feature/issue-820-capacitor-http
Open

MuriloZF wants to merge 6 commits into
getsentry:mainfrom
MuriloZF:feature/issue-820-capacitor-http

Conversation

@MuriloZF

@MuriloZF MuriloZF commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

  • Adds automatic instrumentation for CapacitorHttp requests
  • Adds HTTP client spans and breadcrumbs
  • Supports tracePropagationTargets and propagateTraceparent
  • Limits instrumentation to native platforms

💡 Motivation and Context

Fixes Issue#820

💚 How did you test it?

  • Added tests for request methods, tracing headers, breadcrumbs, errors, and web behavior
  • All tests pass
  • Full lint passes

📝 Checklist

  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • All tests passing
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec
  • No breaking changes

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

Stale Bugbot comment from a previous run.

Comment thread src/integrations/capacitorHttp.ts
Comment thread CHANGELOG.md Outdated
@lucas-zimerman

Copy link
Copy Markdown
Collaborator

Thank you for your contribution! could you post some screenshots of CapacitorHttp being captured on sentry.io?

Comment thread CHANGELOG.md Outdated

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

Stale Bugbot comment from a previous run.

Comment thread CHANGELOG.md
Comment thread CHANGELOG.md Outdated
@lucas-zimerman lucas-zimerman self-assigned this Sep 5, 2026
Comment thread src/integrations/capacitorHttp.ts Outdated
Comment thread src/integrations/capacitorHttp.ts
Comment thread src/integrations/capacitorHttp.ts
Comment thread src/integrations/default.ts Outdated
@lucas-zimerman

Copy link
Copy Markdown
Collaborator

Thank you for your contribution!

I have a specific concern.
When a user has breadcrumbsIntegration enabled.
Won't calling a normal fetch generate 2 breadcrumbs? One from breadcrumbsIntegration and another from your integration? The idea is to only instrument calls from CapacitorHttp.*()

Comment thread src/integrations/capacitorHttp.ts Outdated
Comment thread src/integrations/capacitorHttp.ts
@lucas-zimerman

Copy link
Copy Markdown
Collaborator

Thank you for your contribution!
Another question, are query strings being captured?

@MuriloZF

Copy link
Copy Markdown
Contributor Author

Fixed them on commit 79cfd4d

@MuriloZF
MuriloZF force-pushed the feature/issue-820-capacitor-http branch from 79cfd4d to 95aac25 Compare September 29, 2026 02:07

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 95aac25. Configure here.

onlyIfParent: !hasSpanStreamingEnabled(client),
attributes: {
'http.request.method': method,
'url.full': options.url,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Request params omitted from captured URLs

Medium Severity

Spans and breadcrumbs record only options.url, so CapacitorHttp params never appear in url.full or breadcrumb url. Native requests commonly send those values as the actual query string, so captured HTTP data does not match the request that was made.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 95aac25. Configure here.

Comment thread CHANGELOG.md
Comment on lines +16 to +19
### Features

- Add automatic instrumentation for `CapacitorHttp` requests, including spans, breadcrumbs, and trace propagation using `tracePropagationTargets` and `propagateTraceparent`. ([#1387](https://github.com/getsentry/sentry-capacitor/pull/1387))
-

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you move the code below above # 4.4.0 ?

Suggested change
### Features
- Add automatic instrumentation for `CapacitorHttp` requests, including spans, breadcrumbs, and trace propagation using `tracePropagationTargets` and `propagateTraceparent`. ([#1387](https://github.com/getsentry/sentry-capacitor/pull/1387))
-
## Unreleased
### Features
- Add automatic instrumentation for `CapacitorHttp` requests, including spans, breadcrumbs, and trace propagation using `tracePropagationTargets` and `propagateTraceparent`. ([#1387](https://github.com/getsentry/sentry-capacitor/pull/1387))
-

@lucas-zimerman

Copy link
Copy Markdown
Collaborator

Thanks for the PR! I tested it on an Android emulator (Capacitor 8, ionic-angular-v8 sample) against SaaS. Direct plugin calls work well: CapacitorHttp.get/post/request produce http.client spans with origin: auto.http.capacitor, correct status (ok / not_found / error), capacitor.http breadcrumbs with the right level, and sentry-trace/baggage reach the server and link to the right span. 🎉

Duplicate spans when CapacitorHttp global patching is enabled

With plugins: { CapacitorHttp: { enabled: true } }, the native bridge patches window.fetch/XHR and routes non-GET requests through cap.nativePromise('CapacitorHttp', 'request', ...) (see native-bridge.js). Sentry's existing fetch instrumentation already wraps the patched fetch, so those requests were already traced before this PR. With this PR they get traced twice.

A single fetch('https://httpbin.org/post', { method: 'POST' }) produced:

fetch span CapacitorHttp span
origin auto.http.browser auto.http.capacitor
parent transaction root transaction root (sibling, not nested)
duration / self time 1607ms / 1607ms 1604ms / 1604ms
breadcrumb Fetch POST [200] Capacitor Http POST [200]

So one 1.6s request shows up as ~3.2s of HTTP time, is double-counted in Insights → Outbound API Requests, and adds two breadcrumbs. Trace headers are not duplicated (the inner call sees the existing sentry-trace and setHeaderIfMissing skips it). GET requests are unaffected since the bridge sends them through the proxy URL instead of nativePromise.

To summarize the scope:

Usage Traced without this PR?
Direct CapacitorHttp.get/post/request(...) ❌ No, this is the real gap from #820
fetch with CapacitorHttp.enabled: true ✅ Yes, by the existing browser tracing

Suggestion: restrict the integration to direct plugin calls. For example, in the nativePromise wrapper, if options.headers already has sentry-trace or traceparent (case-insensitive), call original without creating a span/breadcrumb, since Sentry's fetch/XHR instrumentation already handled it. Please add a test that calls nativePromise('CapacitorHttp', 'request', { url, headers: { 'sentry-trace': '...' } }) and asserts that no span or breadcrumb is created.

Known gap with that approach: URLs outside tracePropagationTargets don't get the header, so they'd still be double-counted under global patching. A short note in the JSDoc/docs would be enough for now, e.g. "instruments direct CapacitorHttp plugin calls; fetch/XHR are already covered by browser tracing".

I haven't verified XHR (e.g. Angular HttpClient/axios) under global patching or iOS yet. The bridge patches XHR through the same nativePromise path, so I'd expect the same duplication there.

Other

  • CHANGELOG (this is why Danger fails): the entry landed inside the released ## 4.4.0 section. It should go under ## Unreleased, and the stray - line and the duplicated fix(ios): forward enableCaptureFailedRequests and sendDefaultPii to Sentry Cocoa #1384 "Fixes" entry should be removed.
  • src/integrations/default.ts only has formatting changes. Could you revert them to keep the diff focused?
  • Nits: if (!client) in addTracingHeaders can never be true (the caller already checks it); typo "wich".

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for CapacitorHttp

2 participants