Skip to content

Commit bb0d71f

Browse files
committed
tests
1 parent dfd9dfc commit bb0d71f

3 files changed

Lines changed: 37 additions & 33 deletions

File tree

  • dev-packages
    • browser-integration-tests/suites/tracing/no-parent-span-client-report-streamed
    • node-integration-tests/suites/tracing/no-parent-span-client-report-streamed
  • packages/opentelemetry/test
Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
import { expect } from '@playwright/test';
2-
import type { ClientReport } from '@sentry/core';
32
import { sentryTest } from '../../../utils/fixtures';
4-
import {
5-
envelopeRequestParser,
6-
hidePage,
7-
shouldSkipTracingTest,
8-
testingCdnBundle,
9-
waitForClientReportRequest,
10-
} from '../../../utils/helpers';
3+
import { shouldSkipTracingTest, testingCdnBundle } from '../../../utils/helpers';
4+
import { getSpanOp, waitForStreamedSpan } from '../../../utils/spanUtils';
115

126
sentryTest(
13-
'records no_parent_span client report for fetch requests without an active span',
7+
'sends http.client span for fetch requests without an active span when span streaming is enabled',
148
async ({ getLocalTestUrl, page }) => {
159
sentryTest.skip(shouldSkipTracingTest() || testingCdnBundle());
1610

@@ -24,22 +18,14 @@ sentryTest(
2418

2519
const url = await getLocalTestUrl({ testDir: __dirname });
2620

27-
const clientReportPromise = waitForClientReportRequest(page, report => {
28-
return report.discarded_events.some(e => e.reason === 'no_parent_span');
29-
});
21+
const spanPromise = waitForStreamedSpan(page, span => getSpanOp(span) === 'http.client');
3022

3123
await page.goto(url);
3224

33-
await hidePage(page);
34-
35-
const clientReport = envelopeRequestParser<ClientReport>(await clientReportPromise);
25+
const span = await spanPromise;
3626

37-
expect(clientReport.discarded_events).toEqual([
38-
{
39-
category: 'span',
40-
quantity: 1,
41-
reason: 'no_parent_span',
42-
},
43-
]);
27+
expect(span.name).toMatch(/^GET /);
28+
expect(span.attributes?.['sentry.origin']).toEqual({ type: 'string', value: 'auto.http.browser' });
29+
expect(span.attributes?.['sentry.op']).toEqual({ type: 'string', value: 'http.client' });
4430
},
4531
);

dev-packages/node-integration-tests/suites/tracing/no-parent-span-client-report-streamed/test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import { afterAll, describe, expect } from 'vitest';
22
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
33

4-
describe('no_parent_span client report (streaming)', () => {
4+
describe('no_parent_span with streaming enabled', () => {
55
afterAll(() => {
66
cleanupChildProcesses();
77
});
88

99
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
10-
test('records no_parent_span outcome for http.client span without a local parent', async () => {
10+
test('sends http.client span without a local parent when span streaming is enabled', async () => {
1111
const runner = createRunner()
12-
.unignore('client_report')
1312
.expect({
14-
client_report: report => {
15-
expect(report.discarded_events).toEqual([
16-
{
17-
category: 'span',
18-
quantity: 1,
19-
reason: 'no_parent_span',
20-
},
21-
]);
13+
span: span => {
14+
const httpClientSpan = span.items.find(item =>
15+
item.attributes?.['sentry.op']
16+
? item.attributes['sentry.op'].type === 'string' && item.attributes['sentry.op'].value === 'http.client'
17+
: false,
18+
);
19+
20+
expect(httpClientSpan).toBeDefined();
21+
expect(httpClientSpan?.name).toMatch(/^GET /);
2222
},
2323
})
2424
.start();

packages/opentelemetry/test/sampler.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,5 +348,23 @@ describe('SentrySampler', () => {
348348
expect(spyOnDroppedEvent).toHaveBeenCalledTimes(1);
349349
expect(spyOnDroppedEvent).toHaveBeenCalledWith('sample_rate', 'span');
350350
});
351+
352+
it('always emits streamed http.client spans without a local parent', () => {
353+
const client = new TestClient(getDefaultTestClientOptions({ tracesSampleRate: 1, traceLifecycle: 'stream' }));
354+
const spyOnDroppedEvent = vi.spyOn(client, 'recordDroppedEvent');
355+
const sampler = new SentrySampler(client);
356+
357+
const ctx = context.active();
358+
const traceId = generateTraceId();
359+
const spanName = 'GET http://example.com/api';
360+
const spanKind = SpanKind.CLIENT;
361+
const spanAttributes = {
362+
[ATTR_HTTP_REQUEST_METHOD]: 'GET',
363+
};
364+
365+
const actual = sampler.shouldSample(ctx, traceId, spanName, spanKind, spanAttributes, undefined);
366+
expect(actual.decision).toBe(SamplingDecision.RECORD_AND_SAMPLED);
367+
expect(spyOnDroppedEvent).not.toHaveBeenCalled();
368+
});
351369
});
352370
});

0 commit comments

Comments
 (0)