Skip to content

Commit f05b618

Browse files
niieanibbrzoska
authored andcommitted
feat: TraceManagerDebugger
1 parent 56db9b3 commit f05b618

13 files changed

+1596
-105
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,8 @@
200200
"cjs",
201201
"esm",
202202
"docs"
203-
]
203+
],
204+
"dependencies": {
205+
"rxjs": "^7.8.2"
206+
}
204207
}

src/main.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,6 @@ export { performanceMark, performanceMeasure } from './performanceMark'
2929
export { switchFn } from './switchFn'
3030
export { getCurrentBrowserSupportForNonResponsiveStateDetection } from './utilities'
3131

32-
// visualizer
33-
// export {
34-
// getTimingDisplayModule,
35-
// onActionAddedCallback,
36-
// useVisualizer,
37-
// } from './lazyVisualizer'
38-
39-
// operation tracking (v2)
40-
// export * from './v2/constants'
41-
// export * from './v2/defaultEventProcessor'
42-
// export * from './v2/element'
43-
// export * from './v2/getCommonUrlForTracing'
44-
// export * from './v2/hooks'
45-
// export * from './v2/operation'
46-
// export type * from './v2/types'
47-
4832
// v3
4933
export * from './v3/constants'
5034
export * from './v3/convertToRum'
@@ -60,6 +44,8 @@ export * from './v3/Tracer'
6044
// eslint-disable-next-line import/first, import/newline-after-import
6145
import * as match from './v3/matchSpan'
6246
export { match }
47+
export * from './v3/ConsoleTraceLogger'
48+
export type * from './v3/debugTypes'
6349
export type {
6450
NameMatcher,
6551
SpanMatch,
@@ -72,6 +58,7 @@ export * from './v3/recordingComputeUtils'
7258
export type * from './v3/spanAnnotationTypes'
7359
export type * from './v3/spanTypes'
7460
export * from './v3/TraceManager'
61+
export * from './v3/TraceManagerDebugger'
7562
export type * from './v3/traceRecordingTypes'
7663
export type * from './v3/types'
7764
export type * from './v3/typeUtils'

src/stories/mockComponentsv3/App.stories.tsx

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import React from 'react'
1+
import React, { useEffect } from 'react'
22
import type { Meta, StoryObj } from '@storybook/react'
3+
import { createConsoleTraceLogger } from '../../v3/ConsoleTraceLogger'
4+
import { TraceManagerDebugger } from '../../v3/TraceManagerDebugger'
35
import { App } from './App'
6+
import { traceManager } from './traceManager'
47

58
const meta: Meta<typeof App> = {
69
component: App,
@@ -13,3 +16,57 @@ type Story = StoryObj<typeof App>
1316
export const Primary: Story = {
1417
render: () => <App />,
1518
}
19+
20+
export const WithDebugger: Story = {
21+
render: () => (
22+
<div>
23+
<div style={{ marginBottom: '20px' }}>
24+
<TraceManagerDebugger traceManager={traceManager} />
25+
</div>
26+
<App />
27+
</div>
28+
),
29+
}
30+
31+
export const WithFloatingDebugger: Story = {
32+
render: () => (
33+
<div>
34+
<App />
35+
<TraceManagerDebugger traceManager={traceManager} float={true} />
36+
</div>
37+
),
38+
}
39+
40+
export const WithConsoleTraceLogger: Story = {
41+
render: () => {
42+
// Initialize the console trace logger when the story renders
43+
useEffect(() => {
44+
const consoleLogger = createConsoleTraceLogger(traceManager, {
45+
verbose: true,
46+
})
47+
48+
// Log a message to explain how to use the console
49+
console.info(
50+
'ConsoleTraceLogger is active. Open your browser console to see trace events. ' +
51+
'Try clicking on tickets to see trace events logged in real-time.',
52+
)
53+
54+
// Example of custom logger function if needed
55+
// consoleLogger.setOptions({
56+
// logFn: (message) => {
57+
// console.log(`%c${message}`, 'color: blue');
58+
// }
59+
// });
60+
61+
// Clean up the logger when the component unmounts
62+
return () => {
63+
consoleLogger.cleanup()
64+
console.info(
65+
'ConsoleTraceLogger has been cleaned up and unsubscribed from all events.',
66+
)
67+
}
68+
}, [])
69+
70+
return <App />
71+
},
72+
}

src/stories/mockComponentsv3/App.tsx

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,8 @@ import { ReactComponent as ZendeskIcon } from '@zendeskgarden/svg-icons/src/26/z
2121
// CYN: NEED UPDATE
2222
import { mockTickets } from './mockTickets'
2323
import { TicketList } from './TicketList'
24+
import { ticketOperationTracer } from './ticketOperationTracer'
2425
import { TicketView } from './TicketView'
25-
import { traceManager } from './traceManager'
26-
27-
const ticketOperationTracer = traceManager.createTracer({
28-
name: `ticket-activation`,
29-
type: 'operation',
30-
requiredSpans: [
31-
{
32-
name: 'TicketView',
33-
matchingRelations: ['ticketId'],
34-
type: 'component-render',
35-
isIdle: true,
36-
},
37-
],
38-
relationSchemaName: 'ticket',
39-
variants: {
40-
click: { timeout: 45_000 },
41-
},
42-
// debounceWindow: 1_000,
43-
debounceOnSpans: [
44-
{
45-
name: 'TicketView',
46-
matchingRelations: ['ticketId'],
47-
},
48-
],
49-
interruptOnSpans: [
50-
{
51-
name: 'TicketView',
52-
matchingRelations: ['ticketId'],
53-
type: 'component-unmount',
54-
},
55-
],
56-
captureInteractive: true,
57-
})
5826

5927
// simulate an event every 2 seconds
6028
const simulateEventPeriodically = (ticketId: number | null) => {
@@ -74,27 +42,6 @@ export const App: React.FC = () => {
7442
)
7543

7644
const handleTicketClick = (id: number) => {
77-
// traceManager.startOperation({
78-
// operationName: `ticket-activation`,
79-
// track: [
80-
// {
81-
// match: { type: 'component-unmount', attributes: { ticketId: id } },
82-
// interruptWhenSeen: true,
83-
// },
84-
// {
85-
// match: { attributes: { ticketId: id } },
86-
// debounceEndWhenSeen: { debounceBy: 1_000 },
87-
// },
88-
// {
89-
// match: { attributes: { ticketId: id, visibleState: 'complete' } },
90-
// requiredToEnd: true,
91-
// },
92-
// ],
93-
// onTracked,
94-
// onEnd: onTracked,
95-
// waitUntilInteractive: true,
96-
// interruptSelf: true,
97-
// })
9845
ticketOperationTracer.start({
9946
relatedTo: { ticketId: id },
10047
variant: 'click',

src/stories/mockComponentsv3/simulateLongTasks.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-console */
21
export function triggerLongTasks({
32
minTime,
43
maxTime,
@@ -20,25 +19,25 @@ export function triggerLongTasks({
2019
const endTime = Date.now()
2120

2221
if (controller.signal.aborted) {
23-
console.log('Cluster aborted.')
22+
// console.log('Cluster aborted.')
2423
return
2524
}
2625

2726
if (endTime - startTime < totalClusterDuration) {
28-
console.log(`Starting long task for ${taskDuration} ms`)
27+
// console.log(`Starting long task for ${taskDuration} ms`)
2928
const taskEnd = Date.now() + taskDuration
3029

3130
// Simulating a blocking long task
3231
while (Date.now() < taskEnd) {
3332
if (controller.signal.aborted) {
34-
console.log('Task aborted.')
33+
// console.log('Task aborted.')
3534
return
3635
}
3736
}
3837

3938
executeLongTask() // Trigger the next task
4039
} else {
41-
console.log('Completed all tasks within the cluster duration.')
40+
// console.log('Completed all tasks within the cluster duration.')
4241
}
4342
}
4443

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { traceManager } from './traceManager'
2+
3+
export const ticketOperationTracer = traceManager.createTracer({
4+
name: `ticket-activation`,
5+
type: 'operation',
6+
requiredSpans: [
7+
{
8+
name: 'TicketView',
9+
matchingRelations: true,
10+
type: 'component-render',
11+
isIdle: true,
12+
},
13+
],
14+
relationSchemaName: 'ticket',
15+
variants: {
16+
click: { timeout: 45_000 },
17+
},
18+
// debounceWindow: 1_000,
19+
debounceOnSpans: [
20+
{
21+
name: 'TicketView',
22+
matchingRelations: true,
23+
},
24+
],
25+
interruptOnSpans: [
26+
{
27+
name: 'TicketView',
28+
matchingRelations: true,
29+
type: 'component-unmount',
30+
},
31+
],
32+
captureInteractive: true,
33+
})

0 commit comments

Comments
 (0)