Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sentryTest('should update spans for GraphQL fetch requests', async ({ getLocalTe
type: 'fetch',
'http.method': 'POST',
'http.url': 'http://sentry-test.io/foo',
'url.full': 'http://sentry-test.io/foo',
url: 'http://sentry-test.io/foo',
'server.address': 'sentry-test.io',
'sentry.op': 'http.client',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ sentryTest('should update spans for GraphQL persisted query fetch requests', asy
type: 'fetch',
'http.method': 'POST',
'http.url': 'http://sentry-test.io/graphql',
'url.full': 'http://sentry-test.io/graphql',
url: 'http://sentry-test.io/graphql',
'server.address': 'sentry-test.io',
'sentry.op': 'http.client',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ sentryTest('should update spans for GraphQL persisted query XHR requests', async
type: 'xhr',
'http.method': 'POST',
'http.url': 'http://sentry-test.io/graphql',
'url.full': 'http://sentry-test.io/graphql',
url: 'http://sentry-test.io/graphql',
'server.address': 'sentry-test.io',
'sentry.op': 'http.client',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sentryTest('should update spans for GraphQL XHR requests', async ({ getLocalTest
type: 'xhr',
'http.method': 'POST',
'http.url': 'http://sentry-test.io/foo',
'url.full': 'http://sentry-test.io/foo',
url: 'http://sentry-test.io/foo',
'server.address': 'sentry-test.io',
'sentry.op': 'http.client',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ sentryTest('sanitizes data URLs in fetch span name and attributes', async ({ get
});

expect(span?.data?.['http.url']).toBe(sanitizedUrl);
expect(span?.data?.['url.full']).toBe(sanitizedUrl);
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sentryTest('should create spans for fetch requests called directly after init',
data: {
'http.method': 'GET',
'http.url': 'http://sentry-test-site.example/0',
'url.full': 'http://sentry-test-site.example/0',
url: 'http://sentry-test-site.example/0',
'server.address': 'sentry-test-site.example',
type: 'fetch',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sentryTest('should create spans for fetch requests', async ({ getLocalTestUrl, p
data: {
'http.method': 'GET',
'http.url': `${TEST_HOST}/test-req/${index}`,
'url.full': `${TEST_HOST}/test-req/${index}`,
url: `/test-req/${index}`,
'server.address': 'sentry-test.io',
type: 'fetch',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ sentryTest('creates spans for fetch requests', async ({ getLocalTestUrl, page })
attributes: expect.objectContaining({
'http.method': { type: 'string', value: 'GET' },
'http.url': { type: 'string', value: `http://sentry-test-site.example/${index}` },
'url.full': { type: 'string', value: `http://sentry-test-site.example/${index}` },
url: { type: 'string', value: `http://sentry-test-site.example/${index}` },
'server.address': { type: 'string', value: 'sentry-test-site.example' },
type: { type: 'string', value: 'fetch' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ sentryTest('strips query params in fetch request spans', async ({ getLocalTestUr
data: expect.objectContaining({
'http.method': 'GET',
'http.url': 'http://sentry-test-site.example/0?id=123;page=5',
'url.full': 'http://sentry-test-site.example/0?id=123;page=5',
'http.query': '?id=123;page=5',
'http.response.status_code': 200,
'http.response_content_length': 2,
Expand Down Expand Up @@ -74,6 +75,7 @@ sentryTest('strips hash fragment in fetch request spans', async ({ getLocalTestU
data: expect.objectContaining({
'http.method': 'GET',
'http.url': 'http://sentry-test-site.example/1#fragment',
'url.full': 'http://sentry-test-site.example/1#fragment',
'http.fragment': '#fragment',
'http.response.status_code': 200,
'http.response_content_length': 2,
Expand Down Expand Up @@ -117,6 +119,7 @@ sentryTest('strips hash fragment and query params in fetch request spans', async
data: expect.objectContaining({
'http.method': 'GET',
'http.url': 'http://sentry-test-site.example/2?id=1#fragment',
'url.full': 'http://sentry-test-site.example/2?id=1#fragment',
'http.query': '?id=1',
'http.fragment': '#fragment',
'http.response.status_code': 200,
Expand Down Expand Up @@ -161,6 +164,7 @@ sentryTest(
data: expect.objectContaining({
'http.method': 'GET',
'http.url': 'http://sentry-test.io/api/users?id=1#fragment',
'url.full': 'http://sentry-test.io/api/users?id=1#fragment',
'http.query': '?id=1',
'http.fragment': '#fragment',
'http.response.status_code': 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ sentryTest('should create spans for fetch requests', async ({ getLocalTestUrl, p
data: {
'http.method': 'GET',
'http.url': `http://sentry-test-site.example/${index}`,
'url.full': `http://sentry-test-site.example/${index}`,
url: `http://sentry-test-site.example/${index}`,
'server.address': 'sentry-test-site.example',
type: 'fetch',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ sentryTest('sanitizes data URLs in XHR span name and attributes', async ({ getLo
});

expect(span?.data?.['http.url']).toBe(sanitizedUrl);
expect(span?.data?.['url.full']).toBe(sanitizedUrl);
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sentryTest('should create spans for xhr requests', async ({ getLocalTestUrl, pag
data: {
'http.method': 'GET',
'http.url': `${TEST_HOST}/test-req/${index}`,
'url.full': `${TEST_HOST}/test-req/${index}`,
url: `/test-req/${index}`,
'server.address': 'sentry-test.io',
type: 'xhr',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ sentryTest('creates spans for XHR requests', async ({ getLocalTestUrl, page }) =
attributes: expect.objectContaining({
'http.method': { type: 'string', value: 'GET' },
'http.url': { type: 'string', value: `http://sentry-test-site.example/${index}` },
'url.full': { type: 'string', value: `http://sentry-test-site.example/${index}` },
url: { type: 'string', value: `http://sentry-test-site.example/${index}` },
'server.address': { type: 'string', value: 'sentry-test-site.example' },
type: { type: 'string', value: 'xhr' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ sentryTest('strips query params in XHR request spans', async ({ getLocalTestUrl,
data: expect.objectContaining({
'http.method': 'GET',
'http.url': 'http://sentry-test-site.example/0?id=123;page=5',
'url.full': 'http://sentry-test-site.example/0?id=123;page=5',
'http.query': '?id=123;page=5',
'http.response.status_code': 200,
'sentry.op': 'http.client',
Expand Down Expand Up @@ -73,6 +74,7 @@ sentryTest('strips hash fragment in XHR request spans', async ({ getLocalTestUrl
data: expect.objectContaining({
'http.method': 'GET',
'http.url': 'http://sentry-test-site.example/1#fragment',
'url.full': 'http://sentry-test-site.example/1#fragment',
'http.fragment': '#fragment',
'http.response.status_code': 200,
'sentry.op': 'http.client',
Expand Down Expand Up @@ -115,6 +117,7 @@ sentryTest('strips hash fragment and query params in XHR request spans', async (
data: expect.objectContaining({
'http.method': 'GET',
'http.url': 'http://sentry-test-site.example/2?id=1#fragment',
'url.full': 'http://sentry-test-site.example/2?id=1#fragment',
'http.query': '?id=1',
'http.fragment': '#fragment',
'http.response.status_code': 200,
Expand Down Expand Up @@ -158,6 +161,7 @@ sentryTest(
data: expect.objectContaining({
'http.method': 'GET',
'http.url': 'http://sentry-test.io/api/users?id=1#fragment',
'url.full': 'http://sentry-test.io/api/users?id=1#fragment',
'http.query': '?id=1',
'http.fragment': '#fragment',
'http.response.status_code': 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sentryTest('should create spans for XHR requests', async ({ getLocalTestUrl, pag
data: {
'http.method': 'GET',
'http.url': `http://sentry-test-site.example/${index}`,
'url.full': `http://sentry-test-site.example/${index}`,
url: `http://sentry-test-site.example/${index}`,
'server.address': 'sentry-test-site.example',
type: 'xhr',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ test('should correctly instrument `fetch` for performance tracing', async ({ pag
'http.method': 'GET',
url: 'https://example.com',
'http.url': 'https://example.com/',
'url.full': 'https://example.com/',
'server.address': 'example.com',
type: 'fetch',
'http.response_content_length': expect.any(Number),
Expand Down
6 changes: 4 additions & 2 deletions packages/browser/src/integrations/httpcontext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineIntegration, safeSetSpanJSONAttributes } from '@sentry/core/browser';
import { defineIntegration, safeSetSpanJSONAttributes, SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core/browser';
import { getHttpRequestData, WINDOW } from '../helpers';

/**
Expand Down Expand Up @@ -27,6 +27,8 @@ export const httpContextIntegration = defineIntegration(() => {
};
},
processSegmentSpan(span) {
const spanOp = span.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_OP];

// if none of the information we want exists, don't bother
if (!WINDOW.navigator && !WINDOW.location && !WINDOW.document) {
return;
Expand All @@ -37,7 +39,7 @@ export const httpContextIntegration = defineIntegration(() => {
safeSetSpanJSONAttributes(span, {
// Coerce empty string to undefined so the helper's nullish check drops it,
// rather than writing an empty `url.full` attribute onto the span.
'url.full': reqData.url || undefined,
'url.full': spanOp !== 'http.client' ? reqData.url : undefined,
Comment thread
Lms24 marked this conversation as resolved.
'http.request.header.user_agent': reqData.headers['User-Agent'],
'http.request.header.referer': reqData.headers['Referer'],
});
Expand Down
12 changes: 10 additions & 2 deletions packages/browser/src/tracing/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,12 @@ export function instrumentOutgoingRequests(client: Client, _options?: Partial<Re
if (createdSpan) {
const fullUrl = getFullURL(handlerData.fetchData.url);
const host = fullUrl ? parseUrl(fullUrl).host : undefined;
const sanitizedFullUrl = fullUrl ? stripDataUrlContent(fullUrl) : undefined;
createdSpan.setAttributes({
'http.url': fullUrl ? stripDataUrlContent(fullUrl) : undefined,
'http.url': sanitizedFullUrl,
// `url.full` must match `http.url`. Setting it here ensures parentless `http.client`
// segment spans don't get `url.full` backfilled with the host page URL (see httpContextIntegration).
'url.full': sanitizedFullUrl,
Comment thread
sentry[bot] marked this conversation as resolved.
'server.address': host,
});

Expand Down Expand Up @@ -367,6 +371,7 @@ function xhrCallback(

const fullUrl = getFullURL(url);
const parsedUrl = fullUrl ? parseUrl(fullUrl) : parseUrl(url);
const sanitizedFullUrl = fullUrl ? stripDataUrlContent(fullUrl) : undefined;

const urlForSpanName = stripDataUrlContent(stripUrlQueryAndFragment(url));

Expand All @@ -383,7 +388,10 @@ function xhrCallback(
url: stripDataUrlContent(url),
type: 'xhr',
'http.method': method,
'http.url': fullUrl ? stripDataUrlContent(fullUrl) : undefined,
'http.url': sanitizedFullUrl,
// `url.full` must match `http.url`. Setting it here ensures parentless `http.client`
// segment spans don't get `url.full` backfilled with the host page URL (see httpContextIntegration).
'url.full': sanitizedFullUrl,
'server.address': parsedUrl?.host,
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.browser',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.client',
Expand Down
66 changes: 66 additions & 0 deletions packages/browser/test/integrations/httpcontext.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { describe, expect, it, vi } from 'vitest';
import { httpContextIntegration, SEMANTIC_ATTRIBUTE_SENTRY_OP } from '../../src/exports';
import type { StreamedSpanJSON } from '@sentry/core';
import { getDefaultBrowserClientOptions } from '../helper/browser-client-options';
import { BrowserClient } from '../../src/client';

describe('httpContextIntegration', () => {
globalThis.navigator = {
userAgent:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
} as unknown as Navigator;
globalThis.location = {
href: 'https://example.com',
} as unknown as Location;
globalThis.document = {
referrer: 'https://example.com',
addEventListener: vi.fn(),
location: {
href: 'https://example.com',
},
} as unknown as Document;

it("doesn't attach url.full to http.client segment spans", () => {
const integration = httpContextIntegration();

const span: Partial<StreamedSpanJSON> = {
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.client',
},
};

const browserClient = new BrowserClient(getDefaultBrowserClientOptions());

integration.processSegmentSpan!(span as StreamedSpanJSON, browserClient);

expect(span.attributes).not.toHaveProperty('url.full');
expect(span.attributes).toEqual({
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.client',
'http.request.header.referer': 'https://example.com',
'http.request.header.user_agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
});
});

it('attaches url.full to non-http.client segment spans', () => {
const integration = httpContextIntegration();

const span: Partial<StreamedSpanJSON> = {
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
},
};

const browserClient = new BrowserClient(getDefaultBrowserClientOptions());

integration.processSegmentSpan!(span as StreamedSpanJSON, browserClient);

expect(span.attributes).toEqual({
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
'http.request.header.referer': 'https://example.com',
'http.request.header.user_agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
'url.full': 'https://example.com',
});
});
});
Loading