Skip to content

Commit d6f8d84

Browse files
committed
fix: rename metadata to attributes
1 parent 9820343 commit d6f8d84

File tree

9 files changed

+87
-85
lines changed

9 files changed

+87
-85
lines changed

src/stories/mockComponents/App.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@ import {
1717
NavItemText,
1818
} from '@zendeskgarden/react-chrome'
1919
import { PALETTE } from '@zendeskgarden/react-theming'
20-
2120
import { ReactComponent as MenuTrayIcon } from '@zendeskgarden/svg-icons/src/16/grid-2x2-stroke.svg'
2221
import { ReactComponent as PersonIcon } from '@zendeskgarden/svg-icons/src/16/user-solo-stroke.svg'
22+
import { ReactComponent as ClearIcon } from '@zendeskgarden/svg-icons/src/26/arrow-right-left.svg'
2323
import { ReactComponent as ProductIcon } from '@zendeskgarden/svg-icons/src/26/garden.svg'
2424
import { ReactComponent as HomeIcon } from '@zendeskgarden/svg-icons/src/26/home-fill.svg'
25-
import { ReactComponent as ClearIcon } from '@zendeskgarden/svg-icons/src/26/arrow-right-left.svg'
2625
import { ReactComponent as ZendeskIcon } from '@zendeskgarden/svg-icons/src/26/zendesk.svg'
27-
import { TicketList } from './TicketList'
28-
import { TicketView } from './TicketView'
26+
import type { Operation } from '../../v2/operation'
2927
import { mockTickets } from './mockTickets'
3028
import { operationManager } from './operationManager'
31-
import type { Operation } from '../../v2/operation'
29+
import { TicketList } from './TicketList'
30+
import { TicketView } from './TicketView'
3231

3332
export const App: React.FC = () => {
3433
const [selectedTicketId, setSelectedTicketId] = useState<number | null>(null)
@@ -45,15 +44,15 @@ export const App: React.FC = () => {
4544
operationName: `ticket-activation`,
4645
track: [
4746
{
48-
match: { type: 'component-unmount', metadata: { ticketId: id } },
47+
match: { type: 'component-unmount', attributes: { ticketId: id } },
4948
interruptWhenSeen: true,
5049
},
5150
{
52-
match: { metadata: { ticketId: id } },
53-
debounceEndWhenSeen: { debounceBy: 1000 },
51+
match: { attributes: { ticketId: id } },
52+
debounceEndWhenSeen: { debounceBy: 1_000 },
5453
},
5554
{
56-
match: { metadata: { ticketId: id, visibleState: 'complete' } },
55+
match: { attributes: { ticketId: id, visibleState: 'complete' } },
5756
requiredToEnd: true,
5857
},
5958
],

src/stories/mockComponents/TicketView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const TicketView: React.FC<TicketViewProps> = ({
3636
}) => {
3737
useCaptureRenderBeaconTask({
3838
componentName: 'TicketView',
39-
metadata: { ticketId, loading: !cached },
39+
attributes: { ticketId, loading: !cached },
4040
visibleState: cached ? VISIBLE_STATE.COMPLETE : VISIBLE_STATE.LOADING,
4141
operationManager,
4242
})

src/v2/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ export const DEFAULT_OBSERVED_ENTRY_TYPES = [
4545
]
4646

4747
/** when present on 'detail' of a performance measure/mark, it will ignore that event */
48-
export const SKIP_PROCESSING = Symbol.for('SKIP_PROCESSING')
48+
export const SKIP_PROCESSING = '__SKIP_PROCESSING__'

src/v2/defaultEventProcessor.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ export const defaultEventProcessor: EventProcessor = (
1515
}
1616

1717
const detail = typeof entry.detail === 'object' && entry.detail
18-
const existingMetadata =
19-
'metadata' in entry && typeof entry.metadata === 'object'
20-
? entry.metadata
18+
const existingAttributes =
19+
'attributes' in entry && typeof entry.attributes === 'object'
20+
? entry.attributes
2121
: {}
22-
const metadata = detail
23-
? { ...detail, ...existingMetadata }
24-
: existingMetadata
22+
const attributes = detail
23+
? { ...detail, ...existingAttributes }
24+
: existingAttributes
2525

2626
const inputEvent = entry as InputEvent
2727

28-
inputEvent.metadata = metadata
28+
inputEvent.attributes = attributes
2929

3030
if (!('operations' in entry) || typeof entry.operations !== 'object') {
3131
inputEvent.operations = {}
@@ -43,14 +43,14 @@ export const defaultEventProcessor: EventProcessor = (
4343
if (entry.entryType === 'resource' || entry.entryType === 'navigation') {
4444
const { commonUrl, query, hash } = getCommonUrlForTracing(entry.name)
4545
commonName = commonUrl
46-
metadata.resourceQuery = query
47-
metadata.resourceHash = hash
46+
attributes.resourceQuery = query
47+
attributes.resourceHash = hash
4848

4949
if (entry.entryType === 'resource') {
5050
const resource =
51-
metadata.resource &&
52-
typeof metadata.resource === 'object' &&
53-
metadata.resource
51+
attributes.resource &&
52+
typeof attributes.resource === 'object' &&
53+
attributes.resource
5454
const resourceType =
5555
resource && typeof resource.type === 'string' && resource.type
5656
const statusCode =

src/v2/element.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ const visuallyHiddenButRenderable: React.CSSProperties = {
99
pointerEvents: 'none',
1010
} as const
1111

12-
export const TimingComponent = React.memo(({ name }: { name: string }) => {
13-
return (
14-
<p
15-
// @ts-ignore
16-
elementtiming={name}
17-
style={visuallyHiddenButRenderable}
18-
>
19-
&nbsp;
20-
</p>
21-
)
22-
})
12+
export const TimingComponent = React.memo(({ name }: { name: string }) => (
13+
<p
14+
// @ts-expect-error missing elementtiming from React types
15+
elementtiming={name}
16+
style={visuallyHiddenButRenderable}
17+
>
18+
&nbsp;
19+
</p>
20+
))

src/v2/hooks.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import { useEffect, useRef } from 'react'
44
import { useOnComponentUnmount } from '../ErrorBoundary'
55
import { VISIBLE_STATE } from './constants'
66
import { OperationManager } from './operation'
7-
import type { InputEvent, Metadata, OperationDefinition } from './types'
7+
import type { Attributes, InputEvent, OperationDefinition } from './types'
88

99
// TODO: make a getUseCaptureRenderBeaconTask, and provide OperationManager there
1010
export const useCaptureRenderBeaconTask = ({
1111
componentName,
12-
metadata: meta,
12+
attributes: attr,
1313
error,
1414
visibleState = VISIBLE_STATE.COMPLETE,
1515
operationManager,
1616
}: {
1717
componentName: string
18-
metadata: Record<string, unknown>
18+
attributes: Record<string, unknown>
1919
error?: object
2020
/**
2121
* what is the state of the UX that the user sees as part of this render?
@@ -25,18 +25,18 @@ export const useCaptureRenderBeaconTask = ({
2525
operationManager: OperationManager
2626
}) => {
2727
const renderCountRef = useRef(0)
28-
const metadata: Metadata = {
28+
const attributes: Attributes = {
2929
visibleState: error ? VISIBLE_STATE.ERROR : visibleState,
3030
renderCount: renderCountRef.current,
31-
...meta,
31+
...attr,
3232
}
3333
renderCountRef.current += 1
3434
const renderStartTask = {
3535
entryType: error ? 'component-render-error' : 'component-render-start',
3636
name: componentName,
3737
startTime: operationManager.performance.now(),
3838
duration: 0,
39-
metadata,
39+
attributes,
4040
} satisfies InputEvent
4141

4242
const nextStateObj = { visibleState, startTime: renderStartTask.startTime }
@@ -49,9 +49,9 @@ export const useCaptureRenderBeaconTask = ({
4949
name: componentName,
5050
startTime: previousState.startTime,
5151
duration: renderStartTask.startTime - previousState.startTime,
52-
metadata: {
52+
attributes: {
5353
previousVisibleState: previousState.visibleState,
54-
...metadata,
54+
...attributes,
5555
},
5656
} satisfies InputEvent)
5757
}
@@ -84,7 +84,7 @@ export const useCaptureRenderBeaconTask = ({
8484
name: componentName,
8585
startTime: renderStartTask.startTime,
8686
duration: operationManager.performance.now() - renderStartTask.startTime,
87-
metadata,
87+
attributes,
8888
} satisfies InputEvent)
8989
})
9090

@@ -97,7 +97,7 @@ export const useCaptureRenderBeaconTask = ({
9797
name: componentName,
9898
startTime: operationManager.performance.now(),
9999
duration: 0,
100-
metadata,
100+
attributes,
101101
event: {
102102
...(errorBoundaryMetadata
103103
? {
@@ -121,7 +121,7 @@ export const useCaptureRenderBeaconTask = ({
121121

122122
// records until all required render beacons are settled
123123
// (and until the page is interactive? or maybe that's the central manager's job)
124-
export const useCaptureOperationTiming = (
124+
export const useCaptureRenderTask = (
125125
operationDefinition: OperationDefinition & {
126126
// the operation will start once 'active' is true (or undefined)
127127
active?: boolean
@@ -139,8 +139,8 @@ export const useCaptureOperationTiming = (
139139
// starts an operation when:
140140
// - 'active' is true,
141141
// - all requiredToStart timings have been seen
142-
// all metadata from required tasks is merged into the operation metadata
143-
// the resulting task will have metadata that explains why it ended:
142+
// all attributes from required tasks is merged into the operation attributes
143+
// the resulting task will have attributes that explains why it ended:
144144
// - 'interrupted' if an interruptWhenSeen task was seen
145145
// - 'timeout' if the timeout was reached
146146
// - 'error'

src/v2/operation.test.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable jest/no-conditional-in-test */
2-
import { DEFAULT_DEBOUNCE_MS } from '../constants'
32
import ticketActivationFixtureData from './__fixtures__/ticket-activation-select-tab-1.json'
43
import { DEFAULT_DEBOUNCE_TIME, SKIP_PROCESSING } from './constants'
54
import { type Operation, OperationManager } from './operation'
@@ -26,7 +25,7 @@ describe('operation tracking', () => {
2625
duration: operation.durationTillInteractive || operation.duration,
2726
detail: {
2827
[SKIP_PROCESSING]: true,
29-
metadata: operation.metadata,
28+
attributes: operation.attributes,
3029
id: operation.id,
3130
name: operation.name,
3231
events: operation.getEvents().map((event) => ({
@@ -780,7 +779,7 @@ describe('operation tracking', () => {
780779
requiredToStart: true,
781780
},
782781
{
783-
match: { metadata: { ticketId: id } },
782+
match: { attributes: { ticketId: id } },
784783
debounceEndWhenSeen: { debounceBy },
785784
},
786785
{
@@ -810,7 +809,7 @@ describe('operation tracking', () => {
810809
name: `ticket-${state}`,
811810
startTime: time,
812811
duration: 0,
813-
metadata: { ticketId: id },
812+
attributes: { ticketId: id },
814813
},
815814
])
816815
jest.advanceTimersByTime(Math.max(0, time - getTimeNow()))
@@ -846,29 +845,29 @@ describe('operation tracking', () => {
846845
})
847846

848847
it(`correctly captures the operation's duration`, () => {
849-
const id = '13024'
848+
const ticketId = '13024'
850849
const operationName = 'ticket.activation'
851850
const lastEventRelativeEndTime = 1_706.599_999_999_627_5
852851
const operationDefinition: OperationDefinition = {
853852
operationName,
854853
interruptSelf: true,
855-
metadata: { ticketId: id },
854+
attributes: { ticketId },
856855
waitUntilInteractive: true,
857856
startTime: ticketActivationFixtureData.startTime,
858857
timeout: 60_000,
859858
track: [
860-
// debounce on anything that has ticketId metadata:
861-
{ match: { metadata: { ticketId: id } } },
859+
// debounce on anything that has ticketId attributes:
860+
{ match: { attributes: { ticketId } } },
862861
// any resource fetch should debounce the end of the operation:
863862
{ match: { type: 'resource' } },
864863
// debounce on element timing sentinels:
865-
{ match: { type: 'element', name: `ticket_workspace/${id}` } },
866-
{ match: { type: 'element', name: `omnilog/${id}` } },
864+
{ match: { type: 'element', name: `ticket_workspace/${ticketId}` } },
865+
{ match: { type: 'element', name: `omnilog/${ticketId}` } },
867866
// OmniLog must be rendered in 'complete' state to end the operation:
868867
{
869868
match: {
870869
name: 'OmniLog',
871-
metadata: { ticketId: id, visibleState: 'complete' },
870+
attributes: { ticketId, visibleState: 'complete' },
872871
},
873872
requiredToEnd: true,
874873
},

0 commit comments

Comments
 (0)