From 8b5b9f2230e5cca4d10a72b456906d5711f17cbd Mon Sep 17 00:00:00 2001 From: Evan Jenkins Date: Fri, 10 Jan 2025 09:56:51 -0800 Subject: [PATCH] feat: add team attribute to beacons --- src/stories/mockComponentsv3/TicketView.tsx | 1 + src/v3/hooks.ts | 14 ++++++++------ src/v3/hooksTypes.ts | 1 + src/v3/spanTypes.ts | 2 +- src/v3/types.test.ts | 3 +++ 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/stories/mockComponentsv3/TicketView.tsx b/src/stories/mockComponentsv3/TicketView.tsx index af5b41f0..07b5bc42 100644 --- a/src/stories/mockComponentsv3/TicketView.tsx +++ b/src/stories/mockComponentsv3/TicketView.tsx @@ -36,6 +36,7 @@ export const TicketView: React.FC = ({ }) => { useBeacon({ name: 'TicketView', + team: 'test', scope: { ticketId }, renderedOutput: cached ? 'content' : 'loading', isIdle: cached, diff --git a/src/v3/hooks.ts b/src/v3/hooks.ts index 5e12f7cf..16870746 100644 --- a/src/v3/hooks.ts +++ b/src/v3/hooks.ts @@ -12,7 +12,7 @@ import type { ScopeValue, Timestamp } from './types' type MakeEntryInput = Omit< ComponentRenderSpan, - 'startTime' + 'startTime' | 'team' > & { startTime?: Timestamp } @@ -40,17 +40,19 @@ export const generateUseBeacon = const renderCountRef = useRef(0) renderCountRef.current += 1 - const { attributes, renderedOutput } = config + // For ease of use we accept `team` as a separate field in the config, but we need to merge it into the attributes + const { attributes: _attributes, team, ...remainingConfig } = config + const attributes = { ..._attributes, team } const status = config.error ? 'error' : 'ok' const isIdle = config.isIdle ?? - (renderedOutput === 'content' || renderedOutput === 'error') + (config.renderedOutput === 'content' || config.renderedOutput === 'error') const renderStartTaskEntry: ComponentRenderSpan = makeEntry({ - ...config, + ...remainingConfig, type: 'component-render-start', duration: 0, attributes, @@ -68,7 +70,7 @@ export const generateUseBeacon = useEffect(() => { traceManager.processSpan( makeEntry({ - ...config, + ...remainingConfig, startTime: renderStartRef.current!, type: 'component-render', duration: performance.now() - renderStartRef.current!.now, @@ -85,7 +87,7 @@ export const generateUseBeacon = useOnComponentUnmount( (errorBoundaryMetadata) => { const unmountEntry = makeEntry({ - ...config, + ...remainingConfig, type: 'component-unmount', attributes, error: errorBoundaryMetadata?.error, diff --git a/src/v3/hooksTypes.ts b/src/v3/hooksTypes.ts index ec7bb014..74a7d0e7 100644 --- a/src/v3/hooksTypes.ts +++ b/src/v3/hooksTypes.ts @@ -8,6 +8,7 @@ export interface BeaconConfig { name: string scope: ScopeOnASpan renderedOutput: RenderedOutput + team: string isIdle?: boolean attributes?: Attributes error?: Error diff --git a/src/v3/spanTypes.ts b/src/v3/spanTypes.ts index b9cdc507..469726a7 100644 --- a/src/v3/spanTypes.ts +++ b/src/v3/spanTypes.ts @@ -105,7 +105,7 @@ export interface SpanBase { export interface ComponentRenderSpan extends Omit, 'scope' | 'attributes'>, - BeaconConfig { + Omit, 'team'> { type: ComponentLifecycleSpanType isIdle: boolean errorInfo?: ErrorInfo diff --git a/src/v3/types.test.ts b/src/v3/types.test.ts index 557dce3a..55ed62ee 100644 --- a/src/v3/types.test.ts +++ b/src/v3/types.test.ts @@ -101,6 +101,7 @@ describe.skip('type tests', () => { // valid beacon useBeacon({ name: 'OmniLog', + team: 'test', renderedOutput: 'content', scope: { ticketId: '123' }, }) @@ -108,6 +109,7 @@ describe.skip('type tests', () => { // valid beacon useBeacon({ name: 'UserPage', + team: 'test', renderedOutput: 'content', scope: { userId: '123' }, }) @@ -115,6 +117,7 @@ describe.skip('type tests', () => { // invalid useBeacon({ name: 'UserPage', + team: 'test', renderedOutput: 'content', // @ts-expect-error invalid scope scope: { invalid: '123' },