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 @@ -39,7 +39,7 @@ const NO_HTTP_SERVER_SPANS = [
// project runs these suites, except the ones in `SENTRY_BUN_EXCLUDE`.
const NO_FETCH_INSTRUMENTATION = [
'suites/tracing/double-baggage/**',
'suites/tracing/http-client-span-streamed/test.ts',
'suites/tracing/http-client-span/test.ts',
'suites/tracing/http-client-spans/fetch-basic-streamed/test.ts',
'suites/tracing/http-client-spans/fetch-basic/test.ts',
'suites/tracing/http-client-spans/fetch-error/test.ts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const NODE_ONLY = ['suites/anr/test.ts', 'suites/breadcrumbs/**', 'suites/thread
// spans, breadcrumbs or headers of outgoing `fetch` requests.
const NO_FETCH_INSTRUMENTATION = [
'suites/tracing/double-baggage/**',
'suites/tracing/http-client-span-streamed/test.ts',
'suites/tracing/http-client-span/test.ts',
'suites/tracing/http-client-spans/fetch-basic-streamed/test.ts',
'suites/tracing/http-client-spans/fetch-basic/test.ts',
'suites/tracing/http-client-spans/fetch-error/test.ts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ Sentry.init({
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
traceLifecycle: 'stream',
clientReportFlushInterval: 1_000,
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';

describe('http.client span with streaming enabled', () => {
describe('http.client span without a local parent', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

l: just as an addition, in this test we should assert on span.is_segment: true.

afterAll(() => {
cleanupChildProcesses();
});
Expand All @@ -18,6 +18,7 @@ describe('http.client span with streaming enabled', () => {
);

expect(httpClientSpan).toBeDefined();
expect(httpClientSpan?.is_segment).toBe(true);
// The URL path is high cardinality, so a streamed span name keeps only the domain.
expect(httpClientSpan?.name).toBe('GET localhost');
expect(httpClientSpan?.attributes['url.domain']?.value).toBe('localhost');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
traceLifecycle: 'stream',
transport: loggingTransport,
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { HTTP_CLIENT } from '@sentry/conventions/op';
import { SENTRY_OP, SENTRY_ORIGIN, URL_FULL } from '@sentry/conventions/attributes';
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createCjsTests } from '../../../../utils/runner';

Expand All @@ -10,16 +12,21 @@ describe('outgoing fetch spans - error', () => {
test('captures an errored span for a failed outgoing fetch request', async () => {
await createRunner()
.expect({
transaction: {
transaction: 'test_transaction',
spans: expect.arrayContaining([
expect.objectContaining({
description: expect.stringMatching(/GET http:\/\/localhost:\d+\//),
op: 'http.client',
origin: 'auto.http.node_fetch',
status: 'internal_error',
}),
]),
span: container => {
expect(container.items.find(span => span.is_segment)?.name).toBe('test_transaction');
expect(container.items.filter(span => !span.is_segment)).toEqual(
expect.arrayContaining([
expect.objectContaining({
name: 'GET localhost',
status: 'error',
attributes: expect.objectContaining({
[URL_FULL]: { type: 'string', value: expect.stringMatching(/http:\/\/localhost:\d+\//) },
[SENTRY_OP]: { type: 'string', value: HTTP_CLIENT },
[SENTRY_ORIGIN]: { type: 'string', value: 'auto.http.node_fetch' },
}),
}),
]),
);
},
})
.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { HTTP_CLIENT } from '@sentry/conventions/op';
import { HTTP_RESPONSE_STATUS_CODE, SENTRY_OP, SENTRY_ORIGIN, URL_FULL } from '@sentry/conventions/attributes';
import { createTestServer } from '@sentry-internal/test-utils';
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createCjsTests } from '../../../../utils/runner';
Expand All @@ -9,7 +11,7 @@ describe('outgoing fetch spans - request/response hooks', () => {

createCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
test('adds requestHook and responseHook attributes to spans of outgoing fetch requests', async () => {
expect.assertions(3);
expect.assertions(4);

const [SERVER_URL, closeTestServer] = await createTestServer()
.get('/api/v0', () => {
Expand All @@ -29,33 +31,35 @@ describe('outgoing fetch spans - request/response hooks', () => {
await createRunner()
.withEnv({ SERVER_URL })
.expect({
transaction: {
transaction: 'test_transaction',
spans: [
span: container => {
expect(container.items.find(span => span.is_segment)?.name).toBe('test_transaction');
expect(container.items.filter(span => !span.is_segment)).toEqual([
expect.objectContaining({
description: expect.stringMatching(/GET .*\/api\/v0/),
op: 'http.client',
origin: 'auto.http.node_fetch',
name: 'GET localhost',
status: 'ok',
data: expect.objectContaining({
'sentry.request.hook': '/api/v0',
'sentry.response.hook.path': '/api/v0',
'sentry.response.hook.status_code': 200,
attributes: expect.objectContaining({
[URL_FULL]: { type: 'string', value: expect.stringMatching(/.*\/api\/v0/) },
[SENTRY_OP]: { type: 'string', value: HTTP_CLIENT },
[SENTRY_ORIGIN]: { type: 'string', value: 'auto.http.node_fetch' },
'sentry.request.hook': { type: 'string', value: '/api/v0' },
'sentry.response.hook.path': { type: 'string', value: '/api/v0' },
'sentry.response.hook.status_code': { type: 'integer', value: 200 },
}),
}),
expect.objectContaining({
description: expect.stringMatching(/GET .*\/api\/v1/),
op: 'http.client',
origin: 'auto.http.node_fetch',
status: 'not_found',
data: expect.objectContaining({
'sentry.request.hook': '/api/v1',
'sentry.response.hook.path': '/api/v1',
'sentry.response.hook.status_code': 404,
'http.response.status_code': 404,
name: 'GET localhost',
status: 'error',
attributes: expect.objectContaining({
[URL_FULL]: { type: 'string', value: expect.stringMatching(/.*\/api\/v1/) },
[SENTRY_OP]: { type: 'string', value: HTTP_CLIENT },
[SENTRY_ORIGIN]: { type: 'string', value: 'auto.http.node_fetch' },
'sentry.request.hook': { type: 'string', value: '/api/v1' },
'sentry.response.hook.path': { type: 'string', value: '/api/v1' },
'sentry.response.hook.status_code': { type: 'integer', value: 404 },
[HTTP_RESPONSE_STATUS_CODE]: { type: 'integer', value: 404 },
}),
}),
],
]);
},
})
.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { HTTP_CLIENT } from '@sentry/conventions/op';
import {
HTTP_RESPONSE_HEADER_CONTENT_LENGTH,
SENTRY_OP,
SENTRY_ORIGIN,
URL_FULL,
} from '@sentry/conventions/attributes';
import { createTestServer } from '@sentry-internal/test-utils';
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createCjsTests } from '../../../../utils/runner';
Expand All @@ -9,7 +16,7 @@ describe('outgoing fetch spans - headers to span attributes', () => {

createCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
test('maps configured request & response headers to span attributes', async () => {
expect.assertions(2);
expect.assertions(3);

const [SERVER_URL, closeTestServer] = await createTestServer()
.get('/api/v0', headers => {
Expand All @@ -20,24 +27,27 @@ describe('outgoing fetch spans - headers to span attributes', () => {
await createRunner()
.withEnv({ SERVER_URL })
.expect({
transaction: {
transaction: 'test_transaction',
spans: expect.arrayContaining([
expect.objectContaining({
description: expect.stringMatching(/GET .*\/api\/v0/),
op: 'http.client',
origin: 'auto.http.node_fetch',
data: expect.objectContaining({
'http.request.header.x-test-header': ['test-value'],
// Listed in `headersToSpanAttributes`, but the built-in denylist still wins.
'http.request.header.authorization': ['[Filtered]'],
// Listed in `headersToSpanAttributes`, but denied via `dataCollection.httpHeaders`.
'http.request.header.x-tenant-id': ['[Filtered]'],
'http.response.header.x-powered-by': ['Express'],
'http.response.header.content-length': ['[Filtered]'],
span: container => {
expect(container.items.find(span => span.is_segment)?.name).toBe('test_transaction');
expect(container.items.filter(span => !span.is_segment)).toEqual(
expect.arrayContaining([
expect.objectContaining({
name: 'GET localhost',
attributes: expect.objectContaining({
[URL_FULL]: { type: 'string', value: expect.stringMatching(/.*\/api\/v0/) },
[SENTRY_OP]: { type: 'string', value: HTTP_CLIENT },
[SENTRY_ORIGIN]: { type: 'string', value: 'auto.http.node_fetch' },
'http.request.header.x-test-header': { type: 'array', value: ['test-value'] },
// Listed in `headersToSpanAttributes`, but the built-in denylist still wins.
'http.request.header.authorization': { type: 'array', value: ['[Filtered]'] },
// Listed in `headersToSpanAttributes`, but denied via `dataCollection.httpHeaders`.
'http.request.header.x-tenant-id': { type: 'array', value: ['[Filtered]'] },
'http.response.header.x-powered-by': { type: 'array', value: ['Express'] },
[HTTP_RESPONSE_HEADER_CONTENT_LENGTH]: { type: 'array', value: ['[Filtered]'] },
}),
}),
}),
]),
]),
);
},
})
.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
import { HTTP_CLIENT } from '@sentry/conventions/op';
import {
HTTP_REQUEST_METHOD,
HTTP_RESPONSE_STATUS_CODE,
NETWORK_PEER_ADDRESS,
NETWORK_PEER_PORT,
SENTRY_KIND,
SENTRY_OP,
SENTRY_ORIGIN,
SERVER_ADDRESS,
SERVER_PORT,
URL_FULL,
URL_PATH,
URL_QUERY,
URL_SCHEME,
USER_AGENT_ORIGINAL,
} from '@sentry/conventions/attributes';
import { createTestServer } from '@sentry-internal/test-utils';
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createCjsTests } from '../../../../utils/runner';
Expand All @@ -21,34 +38,34 @@ describe('outgoing fetch spans - strip query', () => {
await createRunner()
.withEnv({ SERVER_URL })
.expect({
transaction: txn => {
expect(txn.transaction).toEqual('test_transaction');
expect(txn.spans).toHaveLength(1);
expect(txn.spans?.[0]).toMatchObject({
data: {
'url.full': `${SERVER_URL}/api/v0/users?id=1`,
'url.path': '/api/v0/users',
'url.query': 'id=1',
'url.scheme': 'http',
'http.request.method': 'GET',
'http.request.method_original': 'GET',
'http.response.status_code': 200,
'network.peer.address': '::1',
'network.peer.port': expect.any(Number),
'sentry.kind': 'client',
'server.port': expect.any(Number),
'user_agent.original': 'node',
'sentry.op': 'http.client',
'sentry.origin': 'auto.http.node_fetch',
'server.address': 'localhost',
span: container => {
const segment = container.items.find(span => span.is_segment);
const spans = container.items.filter(span => !span.is_segment);
expect(segment?.name).toEqual('test_transaction');
expect(spans).toHaveLength(1);
expect(spans[0]).toMatchObject({
attributes: {
[URL_FULL]: { type: 'string', value: `${SERVER_URL}/api/v0/users?id=1` },
[URL_PATH]: { type: 'string', value: '/api/v0/users' },
[URL_QUERY]: { type: 'string', value: 'id=1' },
[URL_SCHEME]: { type: 'string', value: 'http' },
[HTTP_REQUEST_METHOD]: { type: 'string', value: 'GET' },
'http.request.method_original': { type: 'string', value: 'GET' },
[HTTP_RESPONSE_STATUS_CODE]: { type: 'integer', value: 200 },
[NETWORK_PEER_ADDRESS]: { type: 'string', value: '::1' },
[NETWORK_PEER_PORT]: { type: 'integer', value: expect.any(Number) },
[SENTRY_KIND]: { type: 'string', value: 'client' },
[SERVER_PORT]: { type: 'integer', value: expect.any(Number) },
[USER_AGENT_ORIGINAL]: { type: 'string', value: 'node' },
[SENTRY_OP]: { type: 'string', value: HTTP_CLIENT },
[SENTRY_ORIGIN]: { type: 'string', value: 'auto.http.node_fetch' },
[SERVER_ADDRESS]: { type: 'string', value: 'localhost' },
},
description: `GET ${SERVER_URL}/api/v0/users`,
op: 'http.client',
origin: 'auto.http.node_fetch',
name: 'GET localhost',
status: 'ok',
parent_span_id: txn.contexts?.trace?.span_id,
parent_span_id: segment?.span_id,
span_id: expect.stringMatching(/[a-f\d]{16}/),
trace_id: txn.contexts?.trace?.trace_id,
trace_id: segment?.trace_id,
});
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
Expand Down
Loading
Loading