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
@@ -0,0 +1,12 @@
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,
transport: loggingTransport,
});

Sentry.startSpan({ name: 'test_span' }, () => undefined);
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { SENTRY_SEGMENT_NAME_SOURCE } from '@sentry/conventions/attributes';
import { afterAll, expect, test } from 'vitest';
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';

afterAll(() => {
cleanupChildProcesses();
});

test('sends a manually started root span with source custom', async () => {
await createRunner(__dirname, 'scenario.ts')
.expect({
transaction: {
transaction: 'test_span',
transaction_info: { source: 'custom' },
contexts: {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
data: { [SENTRY_SEGMENT_NAME_SOURCE]: 'custom' },
},
},
},
})
.start()
.completed();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as Sentry from '@sentry/node';
import { SENTRY_LINK_TYPE } from '@sentry/conventions/attributes';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
tracesSampleRate: 1.0,
transport: loggingTransport,
release: '1.0.0',
});

Sentry.startSpan({ name: 'test-span', op: 'test' }, segmentSpan => {
Sentry.startSpan({ name: 'test-child-span', op: 'test-child' }, () => {
// noop
});

const inactiveSpan = Sentry.startInactiveSpan({
name: 'test-inactive-span',
links: [{ context: segmentSpan.spanContext(), attributes: { [SENTRY_LINK_TYPE]: 'some_relation' } }],
});
inactiveSpan.end();

Sentry.startSpanManual({ name: 'test-manual-span' }, span => {
span.end();
});
});

void Sentry.flush();
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE } from '@sentry/core';
import { SENTRY_LINK_TYPE, SENTRY_OP, SENTRY_ORIGIN, SENTRY_SEGMENT_NAME_SOURCE } from '@sentry/conventions/attributes';
import { expect, test } from 'vitest';
import { EXPECTED_SDK_NAME } from '../../../../../utils';
import { assertSentryTransaction } from '../../../../../utils/assertions';
import { createRunner } from '../../../../../utils/runner';

test('sends a transaction envelope with correct envelope header', async () => {
await createRunner(__dirname, 'scenario.ts')
.expectHeader({
transaction: {
sent_at: expect.any(String),
sdk: {
name: EXPECTED_SDK_NAME,
version: SDK_VERSION,
},
trace: expect.objectContaining({
public_key: 'public',
sample_rate: '1',
sampled: 'true',
trace_id: expect.stringMatching(/^[\da-f]{32}$/),
transaction: 'test-span',
}),
},
})
.start()
.completed();
});

test('sends a transaction with correct spans for a manually started span with children', async () => {
await createRunner(__dirname, 'scenario.ts')
.expect({
transaction: transaction => {
const rootSpanId = transaction.contexts?.trace?.span_id;
const traceId = transaction.contexts?.trace?.trace_id;

assertSentryTransaction(transaction, {
transaction: 'test-span',
transaction_info: { source: 'custom' },
release: '1.0.0',
environment: 'production',
sdk: { name: EXPECTED_SDK_NAME, version: SDK_VERSION },
contexts: {
trace: {
span_id: expect.stringMatching(/^[\da-f]{16}$/),
trace_id: expect.stringMatching(/^[\da-f]{32}$/),
op: 'test',
origin: 'manual',
status: 'ok',
data: {
[SENTRY_OP]: 'test',
[SENTRY_ORIGIN]: 'manual',
[SENTRY_SEGMENT_NAME_SOURCE]: 'custom',
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1,
},
},
},
});

expect(transaction.spans).toEqual([
{
description: 'test-child-span',
op: 'test-child',
origin: 'manual',
data: { [SENTRY_OP]: 'test-child', [SENTRY_ORIGIN]: 'manual' },
parent_span_id: rootSpanId,
trace_id: traceId,
span_id: expect.stringMatching(/^[\da-f]{16}$/),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
status: 'ok',
},
{
description: 'test-inactive-span',
origin: 'manual',
data: { [SENTRY_ORIGIN]: 'manual' },
parent_span_id: rootSpanId,
trace_id: traceId,
span_id: expect.stringMatching(/^[\da-f]{16}$/),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
status: 'ok',
links: [
{
attributes: { [SENTRY_LINK_TYPE]: 'some_relation' },
sampled: true,
span_id: rootSpanId,
trace_id: traceId,
},
],
},
{
description: 'test-manual-span',
origin: 'manual',
data: { [SENTRY_ORIGIN]: 'manual' },
parent_span_id: rootSpanId,
trace_id: traceId,
span_id: expect.stringMatching(/^[\da-f]{16}$/),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
status: 'ok',
},
]);
},
})
.start()
.completed();
});
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
Expand Up @@ -9,35 +9,14 @@ afterAll(() => {
test('sends a manually started root span with source custom', async () => {
await createRunner(__dirname, 'scenario.ts')
.expect({
transaction: {
transaction: 'test_span',
transaction_info: { source: 'custom' },
contexts: {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
data: { [SENTRY_SEGMENT_NAME_SOURCE]: 'custom' },
},
},
},
})
.start()
.completed();
});

test("doesn't change the name for manually started spans even if attributes triggering inference are set", async () => {
await createRunner(__dirname, 'scenario.ts')
.expect({
transaction: {
transaction: 'test_span',
transaction_info: { source: 'custom' },
contexts: {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
data: { [SENTRY_SEGMENT_NAME_SOURCE]: 'custom' },
},
},
span: container => {
const segment = container.items.find(span => span.is_segment);
expect(segment?.name).toBe('test_span');
expect(segment?.span_id).toEqual(expect.any(String));
expect(segment?.trace_id).toEqual(expect.any(String));
expect(segment?.start_timestamp).toEqual(expect.any(Number));
expect(segment?.end_timestamp).toEqual(expect.any(Number));
expect(segment?.attributes[SENTRY_SEGMENT_NAME_SOURCE]).toEqual({ type: 'string', value: 'custom' });
},
})
.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { loggingTransport } from '@sentry-internal/node-integration-tests';
Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
tracesSampleRate: 1.0,
traceLifecycle: 'stream',
integrations: [Sentry.spanStreamingIntegration()],
transport: loggingTransport,
release: '1.0.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
SENTRY_ORIGIN,
} from '@sentry/conventions/attributes';
import { expect, test } from 'vitest';
import { createRunner } from '../../../../utils/runner';
import { EXPECTED_SDK_NAME } from '../../../../utils';
import { createRunner } from '../../../../../utils/runner';
import { EXPECTED_SDK_NAME } from '../../../../../utils';

test('sends a streamed span envelope with correct envelope header', async () => {
await createRunner(__dirname, 'scenario.ts')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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,
transport: loggingTransport,
});

Sentry.startSpan({ name: 'root_span' }, () => {
Sentry.startSpan(
{
name: 'span_1',
attributes: {
foo: 'bar',
baz: [1, 2, 3],
},
},
() => undefined,
);

// span_2 doesn't finish
Sentry.startInactiveSpan({ name: 'span_2' });

Sentry.startSpan({ name: 'span_3' }, () => {
// span_4 is the child of span_3 but doesn't finish.
Sentry.startInactiveSpan({ name: 'span_4', attributes: { qux: 'quux' } });

// span_5 is another child of span_3 but finishes.
Sentry.startSpan({ name: 'span_5' }, () => undefined);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { SpanJSON } from '@sentry/core';
import { afterAll, expect, test } from 'vitest';
import { assertSentryTransaction } from '../../../../utils/assertions';
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';

afterAll(() => {
cleanupChildProcesses();
});

test('should report finished spans as children of the root transaction.', async () => {
await createRunner(__dirname, 'scenario.ts')
.expect({
transaction: transaction => {
const rootSpanId = transaction.contexts?.trace?.span_id;
const span3Id = transaction.spans?.[1]?.span_id;

expect(rootSpanId).toEqual(expect.any(String));
expect(span3Id).toEqual(expect.any(String));

assertSentryTransaction(transaction, {
transaction: 'root_span',
spans: [
{
description: 'span_1',
data: {
foo: 'bar',
baz: [1, 2, 3],
},
parent_span_id: rootSpanId,
},
{
description: 'span_3',
parent_span_id: rootSpanId,
data: {},
},
{
description: 'span_5',
parent_span_id: span3Id,
data: {},
},
] as SpanJSON[],
});
},
})
.start()
.completed();
});
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