123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- import {
- makeEventTransaction,
- makeSpan,
- makeTrace,
- makeTransaction,
- } from 'sentry/views/performance/newTraceDetails/traceModels/traceTreeTestUtils';
- import {isMissingInstrumentationNode} from './../traceGuards';
- import {TraceTree} from './traceTree';
- const start = new Date('2024-02-29T00:00:00Z').getTime() / 1e3;
- const traceMetadata = {replay: null, meta: null};
- const singleTransactionTrace = makeTrace({
- transactions: [
- makeTransaction({
- start_timestamp: start,
- timestamp: start + 2,
- children: [],
- }),
- ],
- orphan_errors: [],
- });
- const missingInstrumentationSpans = [
- makeSpan({
- op: 'db',
- description: 'redis',
- start_timestamp: start,
- timestamp: start + 1,
- }),
- makeSpan({
- op: 'db',
- description: 'redis',
- start_timestamp: start + 2,
- timestamp: start + 4,
- }),
- ];
- const childrenMissingInstrumentationSpans = [
- makeSpan({
- op: 'db',
- description: 'redis',
- span_id: 'redis',
- start_timestamp: start,
- timestamp: start + 1,
- }),
- makeSpan({
- op: 'http',
- description: 'request',
- span_id: 'other redis',
- parent_span_id: 'redis',
- start_timestamp: start + 2,
- timestamp: start + 4,
- }),
- ];
- describe('missing instrumentation', () => {
- it('adds missing instrumentation between sibling spans', () => {
- const tree = TraceTree.FromTrace(singleTransactionTrace, traceMetadata);
- TraceTree.FromSpans(
- tree.root.children[0].children[0],
- missingInstrumentationSpans,
- makeEventTransaction()
- );
- TraceTree.DetectMissingInstrumentation(tree.root);
- expect(tree.build().serialize()).toMatchSnapshot();
- });
- it('adds missing instrumentation between children spans', () => {
- const tree = TraceTree.FromTrace(singleTransactionTrace, traceMetadata);
- TraceTree.FromSpans(
- tree.root.children[0].children[0],
- childrenMissingInstrumentationSpans,
- makeEventTransaction()
- );
- TraceTree.DetectMissingInstrumentation(tree.root);
- expect(tree.build().serialize()).toMatchSnapshot();
- });
- it('adds missing instrumentation between two spans that share a common root', () => {
- const tree = TraceTree.FromTrace(
- makeTrace({
- transactions: [
- makeTransaction({
- span_id: 'parent-transaction',
- }),
- ],
- }),
- traceMetadata
- );
- TraceTree.FromSpans(
- tree.root.children[0].children[0],
- [
- makeSpan({
- op: 'http',
- description: 'request',
- span_id: '0000',
- parent_span_id: 'parent-transaction',
- start_timestamp: start,
- timestamp: start + 2,
- }),
- makeSpan({
- op: 'db',
- description: 'redis',
- span_id: '0001',
- parent_span_id: '0000',
- start_timestamp: start,
- timestamp: start + 2,
- }),
- makeSpan({
- op: 'cache',
- description: 'redis',
- span_id: '0002',
- parent_span_id: 'parent-transaction',
- start_timestamp: start + 3,
- timestamp: start + 4,
- }),
- ],
- makeEventTransaction()
- );
- TraceTree.DetectMissingInstrumentation(tree.root);
- expect(tree.build().serialize()).toMatchSnapshot();
- });
- it('removes missing instrumentation nodes', () => {
- const tree = TraceTree.FromTrace(singleTransactionTrace, traceMetadata);
- TraceTree.FromSpans(
- tree.root.children[0].children[0],
- missingInstrumentationSpans,
- makeEventTransaction()
- );
- const snapshot = tree.build().serialize();
- TraceTree.DetectMissingInstrumentation(tree.root);
- // Assert that missing instrumentation nodes exist
- expect(
- TraceTree.Find(tree.root, c => isMissingInstrumentationNode(c))
- ).not.toBeNull();
- // Remove it and assert that the tree is back to the original state
- TraceTree.RemoveMissingInstrumentationNodes(tree.root);
- expect(tree.build().serialize()).toEqual(snapshot);
- expect(tree.build().serialize()).toMatchSnapshot();
- });
- it('does not add missing instrumentation for browser SDKs', () => {
- const tree = TraceTree.FromTrace(singleTransactionTrace, traceMetadata);
- TraceTree.FromSpans(
- tree.root.children[0].children[0],
- missingInstrumentationSpans,
- makeEventTransaction({sdk: {name: 'sentry.javascript.browser', version: '1.0.0'}})
- );
- TraceTree.DetectMissingInstrumentation(tree.root);
- expect(TraceTree.Find(tree.root, c => isMissingInstrumentationNode(c))).toBeNull();
- expect(tree.build().serialize()).toMatchSnapshot();
- });
- it.each([
- ['children', childrenMissingInstrumentationSpans],
- ['siblings', missingInstrumentationSpans],
- ])('idempotent - %s', (_type, setup) => {
- const tree = TraceTree.FromTrace(singleTransactionTrace, traceMetadata);
- TraceTree.FromSpans(tree.root.children[0].children[0], setup, makeEventTransaction());
- TraceTree.DetectMissingInstrumentation(tree.root);
- const initial = tree.build().serialize();
- expect(tree.build().serialize()).toMatchSnapshot();
- expect(tree.build().serialize()).toEqual(initial);
- });
- });
|