Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add team attribute as required on Render Beacon #19

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/stories/mockComponentsv3/TicketView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const TicketView: React.FC<TicketViewProps> = ({
}) => {
useBeacon({
name: 'TicketView',
team: 'test',
scope: { ticketId },
renderedOutput: cached ? 'content' : 'loading',
isIdle: cached,
Expand Down
14 changes: 8 additions & 6 deletions src/v3/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { ScopeValue, Timestamp } from './types'

type MakeEntryInput<AllPossibleScopesT> = Omit<
ComponentRenderSpan<AllPossibleScopesT>,
'startTime'
'startTime' | 'team'
> & {
startTime?: Timestamp
}
Expand Down Expand Up @@ -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<AllPossibleScopesT> =
makeEntry({
...config,
...remainingConfig,
type: 'component-render-start',
duration: 0,
attributes,
Expand All @@ -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,
Expand All @@ -85,7 +87,7 @@ export const generateUseBeacon =
useOnComponentUnmount(
(errorBoundaryMetadata) => {
const unmountEntry = makeEntry({
...config,
...remainingConfig,
type: 'component-unmount',
attributes,
error: errorBoundaryMetadata?.error,
Expand Down
1 change: 1 addition & 0 deletions src/v3/hooksTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface BeaconConfig<AllPossibleScopesT> {
name: string
scope: ScopeOnASpan<AllPossibleScopesT>
renderedOutput: RenderedOutput
team: string
isIdle?: boolean
attributes?: Attributes
error?: Error
Expand Down
2 changes: 1 addition & 1 deletion src/v3/spanTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export interface SpanBase<AllPossibleScopesT> {

export interface ComponentRenderSpan<AllPossibleScopesT>
extends Omit<SpanBase<AllPossibleScopesT>, 'scope' | 'attributes'>,
BeaconConfig<AllPossibleScopesT> {
Omit<BeaconConfig<AllPossibleScopesT>, 'team'> {
type: ComponentLifecycleSpanType
isIdle: boolean
errorInfo?: ErrorInfo
Expand Down
3 changes: 3 additions & 0 deletions src/v3/types.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,23 @@ describe('type tests', () => {
// valid beacon
useBeacon({
name: 'OmniLog',
team: 'test',
renderedOutput: 'content',
scope: { ticketId: '123' },
})

// valid beacon
useBeacon({
name: 'UserPage',
team: 'test',
renderedOutput: 'content',
scope: { userId: '123' },
})

// invalid
useBeacon({
name: 'UserPage',
team: 'test',
renderedOutput: 'content',
// @ts-expect-error invalid scope
scope: { invalid: '123' },
Expand Down
Loading