Skip to content

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

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

feature: add CapacitorHttp support - Issue#820#1387
MuriloZF wants to merge 7 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?

Co-authored-by: LucasZF <lucas-zimerman1@hotmail.com>
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.

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.

Reviewed by Cursor Bugbot for commit 5d4f794. Configure here.

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

function getMethod(method: HttpMethod, options: HttpOptions): string {
return method === 'request'
? (options.method ?? 'GET').toUpperCase()

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.

GET is always uppercase so we only need to apply it only to the method if method exists

Suggested change
? (options.method ?? 'GET').toUpperCase()
? (options.method?.toUpperCase() ?? 'GET')


setupOnce(): void {
if (!Capacitor.isNativePlatform()) {
return;

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.

Lets add a warning so users know why this is disabled:

Suggested change
return;
debug.warn(`[${INTEGRATION_NAME}]` is disabled by not running on a native platform`);
return;

Must import debug from @sentry/core

function addTracingHeaders(options: HttpOptions, span: Span): HttpOptions {
const client = getClient();

if (!client) {

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.

client already exists here since the previous function that called addTracingHeaders already checked it before invoking it. I would suggest passing the client as a parameter into this function

Comment thread src/integrations/default.ts Outdated
integrations.push(nativeReleaseIntegration());
integrations.push(eventOriginIntegration());
integrations.push(sdkInfoIntegration());
integrations.push(capacitorHttpIntegration());

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.

Let's remove this line so it makes the integration optional for the time being.

Suggested change
integrations.push(capacitorHttpIntegration());

@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
{
name: spanName,
op: 'http.client',
onlyIfParent: true,

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.

Let's follow what the Sentry JavaScript is doing for deciding about the parent with

onlyIfParent:  !hasSpanStreamingEnabled(client),

must import hasSpanStreamingEnabled from @sentry/core

Comment on lines +156 to +184
function mergeBaggageHeader(
headers: Record<string, string>,
sentryBaggage: string | undefined,
): void {
if (!sentryBaggage) {
return;
}

const existingKey = findHeaderKey(headers, 'baggage');

if (!existingKey) {
headers.baggage = sentryBaggage;
return;
}

const existingValue = headers[existingKey];

if (!existingValue) {
headers[existingKey] = sentryBaggage;
return;
}

// Preserve baggage which already contains Sentry Values
if (/(?:^|,)\s*sentry-[^=]*=/.test(existingValue)) {
return;
}

headers[existingKey] = `${existingValue},${sentryBaggage}`;
}

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.

We can simplify this code reducing the if complexity

Suggested change
function mergeBaggageHeader(
headers: Record<string, string>,
sentryBaggage: string | undefined,
): void {
if (!sentryBaggage) {
return;
}
const existingKey = findHeaderKey(headers, 'baggage');
if (!existingKey) {
headers.baggage = sentryBaggage;
return;
}
const existingValue = headers[existingKey];
if (!existingValue) {
headers[existingKey] = sentryBaggage;
return;
}
// Preserve baggage which already contains Sentry Values
if (/(?:^|,)\s*sentry-[^=]*=/.test(existingValue)) {
return;
}
headers[existingKey] = `${existingValue},${sentryBaggage}`;
}
function mergeBaggageHeader(
headers: Record<string, string>,
sentryBaggage: string | undefined,
): void {
if (!sentryBaggage) {
return;
}
const key = findHeaderKey(headers, 'baggage') ?? 'baggage';
const existingValue = headers[key];
// Preserve baggage which already contains Sentry values
if (existingValue && /(?:^|,)\s*sentry-[^=]*=/.test(existingValue)) {
return;
}
headers[key] = existingValue ? `${existingValue},${sentryBaggage}` : sentryBaggage;
}

@lucas-zimerman

Copy link
Copy Markdown
Collaborator

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

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