-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Handle missing root transactions (#93)
There are (currently unknown) situations where a span batch may not be able to identify a root transaction. That is, all spans available in the transaction group are siblings. This may not be the ideal fix, and we'll revisit shortly. This is simply to unblock UI errors. Refs GH-90, GH-61
- Loading branch information
Showing
9 changed files
with
760 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
- name: Install deps | ||
run: pnpm install | ||
- name: Build packages | ||
run: pnpm build | ||
- name: Run tests | ||
run: pnpm test:ci | ||
- name: Publish Test Report | ||
uses: mikepenz/action-junit-report@v4 | ||
if: success() || failure() | ||
with: | ||
report_paths: '**/junit.xml' | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/codecov-action@v3 | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,6 @@ dist-ssr | |
.yalc | ||
yalc.lock | ||
.vite-inspect | ||
.vercel | ||
.vercel | ||
|
||
junit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
packages/core/src/integrations/sentry/utils/traces.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { createId } from '@paralleldrive/cuid2'; | ||
import { describe, expect, test } from 'vitest'; | ||
import { Span } from '../types'; | ||
import { groupSpans } from './traces'; | ||
|
||
function mockSpan({ duration, ...span }: Partial<Span> & { duration?: number } = {}): Span { | ||
const defaultTimestamp = new Date().getTime(); | ||
return { | ||
trace_id: createId(), | ||
span_id: createId(), | ||
op: 'unknown', | ||
status: 'unknown', | ||
start_timestamp: defaultTimestamp, | ||
timestamp: duration ? (span.start_timestamp || defaultTimestamp) + duration : defaultTimestamp, | ||
...span, | ||
}; | ||
} | ||
|
||
describe('groupSpans', () => { | ||
test('empty span list', () => { | ||
expect(groupSpans([])).toEqual([]); | ||
}); | ||
|
||
test('simple parent and child relationship', () => { | ||
const parent1 = mockSpan({}); | ||
const span1 = mockSpan({ | ||
parent_span_id: parent1.span_id, | ||
trace_id: parent1.trace_id, | ||
}); | ||
const span2 = mockSpan({ | ||
parent_span_id: parent1.span_id, | ||
trace_id: parent1.trace_id, | ||
}); | ||
const result = groupSpans([parent1, span1, span2]); | ||
console.debug(result); | ||
expect(result.length).toEqual(1); | ||
expect(result[0].span_id).toEqual(parent1.span_id); | ||
expect(result[0].children?.length).toEqual(2); | ||
expect(result[0].children![0].span_id).toEqual(span1.span_id); | ||
expect(result[0].children![1].span_id).toEqual(span2.span_id); | ||
}); | ||
|
||
test('multiple parent and child relationship both parents as root', () => { | ||
const parent1 = mockSpan({ | ||
start_timestamp: new Date().getTime() - 1, | ||
}); | ||
|
||
const span1 = mockSpan({ | ||
parent_span_id: parent1.span_id, | ||
trace_id: parent1.trace_id, | ||
}); | ||
const span2 = mockSpan({ | ||
parent_span_id: parent1.span_id, | ||
trace_id: parent1.trace_id, | ||
}); | ||
|
||
const parent2 = mockSpan({}); | ||
const span3 = mockSpan({ | ||
parent_span_id: parent2.span_id, | ||
trace_id: parent2.trace_id, | ||
}); | ||
const span4 = mockSpan({ | ||
parent_span_id: parent2.span_id, | ||
trace_id: parent2.trace_id, | ||
}); | ||
const result = groupSpans([parent1, span1, span2, parent2, span3, span4]); | ||
console.debug(result); | ||
expect(result.length).toEqual(2); | ||
expect(result[0].span_id).toEqual(parent1.span_id); | ||
expect(result[0].children?.length).toEqual(2); | ||
expect(result[0].children![0].span_id).toEqual(span1.span_id); | ||
expect(result[0].children![1].span_id).toEqual(span2.span_id); | ||
expect(result[1].span_id).toEqual(parent2.span_id); | ||
expect(result[1].children?.length).toEqual(2); | ||
expect(result[1].children![0].span_id).toEqual(span3.span_id); | ||
expect(result[1].children![1].span_id).toEqual(span4.span_id); | ||
}); | ||
|
||
test('missing root transactions as siblings, creates faux parent', () => { | ||
const parent_span_id = createId(); | ||
const span1 = mockSpan({ | ||
parent_span_id, | ||
}); | ||
const span2 = mockSpan({ | ||
parent_span_id, | ||
trace_id: span1.trace_id, | ||
}); | ||
const result = groupSpans([span1, span2]); | ||
console.debug(result); | ||
expect(result.length).toEqual(1); | ||
expect(result[0].op).toEqual('orphan'); | ||
expect(result[0].description).toEqual('missing or unknown parent span'); | ||
expect(result[0].status).toEqual('unknown'); | ||
expect(result[0].parent_span_id).toBe(null); | ||
console.debug(result[0].children); | ||
expect(result[0].children?.length).toEqual(2); | ||
expect(result[0].children![0].span_id).toEqual(span1.span_id); | ||
expect(result[0].children![1].span_id).toEqual(span2.span_id); | ||
}); | ||
|
||
test('missing root transactions as independent children, creates faux parents', () => { | ||
const span1 = mockSpan({ | ||
parent_span_id: createId(), | ||
}); | ||
const span2 = mockSpan({ | ||
parent_span_id: createId(), | ||
trace_id: span1.trace_id, | ||
}); | ||
const result = groupSpans([span1, span2]); | ||
console.debug(result); | ||
expect(result.length).toEqual(2); | ||
expect(result[0].span_id).toEqual(span1.parent_span_id); | ||
expect(result[0].op).toEqual('orphan'); | ||
expect(result[0].description).toEqual('missing or unknown parent span'); | ||
expect(result[0].status).toEqual('unknown'); | ||
expect(result[0].parent_span_id).toBe(null); | ||
console.debug(result[0].children); | ||
expect(result[0].children?.length).toEqual(1); | ||
expect(result[0].children![0].span_id).toEqual(span1.span_id); | ||
|
||
expect(result[1].span_id).toEqual(span2.parent_span_id); | ||
expect(result[1].op).toEqual('orphan'); | ||
expect(result[1].description).toEqual('missing or unknown parent span'); | ||
expect(result[1].status).toEqual('unknown'); | ||
expect(result[1].parent_span_id).toBe(null); | ||
console.debug(result[1].children); | ||
expect(result[1].children?.length).toEqual(1); | ||
expect(result[1].children![0].span_id).toEqual(span2.span_id); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/// <reference types="vitest" /> | ||
|
||
// import tsconfigPaths from "vite-tsconfig-paths"; | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
// plugins: [tsconfigPaths()], | ||
test: { | ||
coverage: { | ||
provider: 'v8', | ||
reporter: ['json'], | ||
}, | ||
globals: true, | ||
// setupFiles: ["./src/test/setup-test-env.ts"], | ||
include: ['./src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], | ||
watchExclude: ['.*\\/node_modules\\/.*', '.*\\/dist\\/.*'], | ||
}, | ||
}); |
Empty file.
Oops, something went wrong.