Skip to content

Commit a599b50

Browse files
xnanodaxbbrzoska
authored andcommitted
rename scope -> relation
1 parent c73f8fb commit a599b50

15 files changed

+88
-80
lines changed

src/v3/TraceManagerWithFixtures.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import {
1313
} from './testUtility/fixtures/relationSchemas'
1414
import { shouldCompleteAndHaveInteractiveTime } from './testUtility/fixtures/shouldCompleteAndHaveInteractiveTime'
1515
import { shouldNotEndWithInteractiveTimeout } from './testUtility/fixtures/shouldNotEndWithInteractiveTimeout'
16-
import { ticketActivationDefinition } from './testUtility/fixtures/ticket.activation'
16+
import { ticketActivatedDefinition } from './testUtility/fixtures/ticket.activated'
1717
import { TraceManager } from './TraceManager'
1818
import type { AnyPossibleReportFn } from './types'
1919

20-
interface TicketScope {
20+
interface TicketIdRelation {
2121
ticketId: string
2222
}
2323

@@ -31,7 +31,7 @@ describe('TraceManager with Fixtures', () => {
3131
})
3232

3333
beforeEach(() => {
34-
reportFn = jest.fn<AnyPossibleReportFn<TicketScope>>()
34+
reportFn = jest.fn<AnyPossibleReportFn<TicketIdRelation>>()
3535
generateId = jest.fn().mockReturnValue('trace-id')
3636
reportErrorFn = jest.fn()
3737
})
@@ -50,14 +50,14 @@ describe('TraceManager with Fixtures', () => {
5050
})
5151
const fixtureEntries = shouldCompleteAndHaveInteractiveTime
5252

53-
const scopeEntry = fixtureEntries.find(
53+
const relatedToEntry = fixtureEntries.find(
5454
(entry) => 'relatedTo' in entry.span,
5555
)!
5656
const relatedTo = {
57-
ticketId: scopeEntry.span.relatedTo!.ticketId!,
57+
ticketId: relatedToEntry.span.relatedTo!.ticketId!,
5858
}
5959

60-
const tracer = traceManager.createTracer(ticketActivationDefinition)
60+
const tracer = traceManager.createTracer(ticketActivatedDefinition)
6161
tracer.start({
6262
relatedTo,
6363
startTime: fixtureEntries[0]!.span.startTime,
@@ -114,7 +114,7 @@ describe('TraceManager with Fixtures', () => {
114114
"duration": 1504.4000000059605,
115115
"id": "trace-id",
116116
"interruptionReason": undefined,
117-
"name": "ticket.activation",
117+
"name": "ticket.activated",
118118
"relatedTo": {
119119
"ticketId": "74",
120120
},
@@ -139,13 +139,13 @@ describe('TraceManager with Fixtures', () => {
139139
reportErrorFn,
140140
})
141141
const fixtureEntries = shouldNotEndWithInteractiveTimeout
142-
const scopeEntry = fixtureEntries.find(
142+
const relatedToEntry = fixtureEntries.find(
143143
(entry) => 'relatedTo' in entry.span,
144144
)!
145145
const relatedTo = {
146-
ticketId: scopeEntry.span.relatedTo!.ticketId!,
146+
ticketId: relatedToEntry.span.relatedTo!.ticketId!,
147147
}
148-
const tracer = traceManager.createTracer(ticketActivationDefinition)
148+
const tracer = traceManager.createTracer(ticketActivatedDefinition)
149149
tracer.start({
150150
relatedTo,
151151
startTime: {
@@ -207,7 +207,7 @@ describe('TraceManager with Fixtures', () => {
207207
"duration": 1302.3999999910593,
208208
"id": "trace-id",
209209
"interruptionReason": undefined,
210-
"name": "ticket.activation",
210+
"name": "ticket.activated",
211211
"relatedTo": {
212212
"ticketId": "74",
213213
},

src/v3/convertToRum.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ export interface RumTraceRecording<RelationSchemaT>
5050
[key: string]: unknown
5151
}
5252

53-
export function isRenderEntry<ScopeT>(
54-
entry: Span<ScopeT>,
55-
): entry is ComponentRenderSpan<ScopeT> {
53+
export function isRenderEntry<RelationSchemasT>(
54+
entry: Span<RelationSchemasT>,
55+
): entry is ComponentRenderSpan<RelationSchemasT> {
5656
return (
5757
entry.type === 'component-render' ||
5858
entry.type === 'component-render-start' ||
5959
entry.type === 'component-unmount'
6060
)
6161
}
6262

63-
function updateEmbeddedEntry<ScopeT>(
63+
function updateEmbeddedEntry<RelationSchemasT>(
6464
embeddedEntry: EmbeddedEntry,
65-
spanAndAnnotation: SpanAndAnnotation<ScopeT>,
65+
spanAndAnnotation: SpanAndAnnotation<RelationSchemasT>,
6666
): EmbeddedEntry {
6767
const { annotation, span } = spanAndAnnotation
6868
return {
@@ -78,10 +78,10 @@ function updateEmbeddedEntry<ScopeT>(
7878
}
7979
}
8080

81-
function createEmbeddedEntry<ScopeT>({
81+
function createEmbeddedEntry<RelationSchemasT>({
8282
span,
8383
annotation,
84-
}: SpanAndAnnotation<ScopeT>): EmbeddedEntry {
84+
}: SpanAndAnnotation<RelationSchemasT>): EmbeddedEntry {
8585
return {
8686
count: 1,
8787
totalDuration: span.duration,
@@ -94,8 +94,8 @@ function createEmbeddedEntry<ScopeT>({
9494
}
9595
}
9696

97-
export const defaultEmbedSpanSelector = <ScopeT>(
98-
spanAndAnnotation: SpanAndAnnotation<ScopeT>,
97+
export const defaultEmbedSpanSelector = <RelationSchemasT>(
98+
spanAndAnnotation: SpanAndAnnotation<RelationSchemasT>,
9999
) => {
100100
const { span } = spanAndAnnotation
101101
return isRenderEntry(span)

src/v3/hooksTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export type BeaconConfig<RelationSchemasT, RequiredAttributesT = {}> = {
1414
? { attributes?: Attributes }
1515
: { attributes: RequiredAttributesT & Attributes })
1616

17-
export type UseBeacon<ScopeT, RequiredAttributesT> = (
18-
beaconConfig: BeaconConfig<ScopeT, RequiredAttributesT>,
17+
export type UseBeacon<RelationSchemasT, RequiredAttributesT> = (
18+
beaconConfig: BeaconConfig<RelationSchemasT, RequiredAttributesT>,
1919
) => void
2020

2121
export type GetRelationSchemasTFromTraceManager<

src/v3/idealApi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Valid state transitions:
224224
## Datatypes
225225

226226
```ts
227-
interface TraceEntryInput<ScopeT extends object> {
227+
interface TraceEntryInput<RelationSchemasT extends object> {
228228
type:
229229
| NativePerformanceEntryType
230230
| 'component-render-start'
@@ -247,7 +247,7 @@ interface TraceEntryInput<ScopeT extends object> {
247247

248248
status: 'ok' | 'error'
249249

250-
relatedTo: ScopeT
250+
relatedTo: RelationSchemasT
251251

252252
attributes: {
253253
[name: string]: unknown

src/v3/matchSpan.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ describe('matchSpan', () => {
335335
})
336336
})
337337

338-
describe('scopeKeys', () => {
338+
describe('matchingRelation', () => {
339339
it('should return true when relatedTo does match', () => {
340340
const matcher = matchSpan.withAllConditions<
341341
'ticket',

src/v3/matchSpan.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,16 @@ export function withMatchingRelations<
170170
// similarly, if the span doesn't have any relatedTo set
171171
const relatedToInput: Record<string, unknown> | undefined = r
172172
if (!span.relatedTo || !relatedToInput) return false
173-
const spanScope: Record<string, unknown> = span.relatedTo
173+
const spanRelatedTo: Record<string, unknown> = span.relatedTo
174174
const resolvedKeys =
175175
typeof keys === 'boolean' && keys
176176
? Object.keys(relationSchema as object)
177177
: (keys as string[])
178178

179179
if (!resolvedKeys) return false
180180
return resolvedKeys.every(
181-
(key) => key in spanScope && spanScope[key] === relatedToInput[key],
181+
(key) =>
182+
key in spanRelatedTo && spanRelatedTo[key] === relatedToInput[key],
182183
)
183184
}
184185
}

src/v3/observePerformanceWithTraceManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ export const observePerformanceWithTraceManager = <
3232
RelationSchemasT extends RelationSchemasBase<RelationSchemasT>,
3333
>({
3434
traceManager,
35-
deriveScopeFromPerformanceEntry,
35+
deriveRelationFromPerformanceEntry,
3636
entryTypes = getBestSupportedEntryTypes(),
3737
keep,
3838
}: {
3939
traceManager: TraceManager<RelationSchemasT>
40-
deriveScopeFromPerformanceEntry?: DeriveRelationsFromPerformanceEntryFn<RelationSchemasT>
40+
deriveRelationFromPerformanceEntry?: DeriveRelationsFromPerformanceEntryFn<RelationSchemasT>
4141
entryTypes?: NativePerformanceEntryType[]
4242
keep?: (entry: PerformanceEntry) => boolean
4343
}) => {
@@ -48,7 +48,7 @@ export const observePerformanceWithTraceManager = <
4848
}
4949
const traceEntry = getSpanFromPerformanceEntry<RelationSchemasT>(
5050
entry,
51-
deriveScopeFromPerformanceEntry,
51+
deriveRelationFromPerformanceEntry,
5252
)
5353
if (traceEntry !== undefined) {
5454
traceManager.processSpan(traceEntry)

src/v3/recordingComputeUtils.test.ts

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import {
1111
} from './testUtility/createMockFactory'
1212
import type { CompleteTraceDefinition } from './types'
1313

14-
interface AnyScope {
14+
interface AnyRelation {
1515
global: {}
1616
}
1717

1818
const baseDefinitionFixture: CompleteTraceDefinition<
1919
'global',
20-
AnyScope,
20+
AnyRelation,
2121
'origin'
2222
> = {
2323
name: 'test-trace',
@@ -155,7 +155,7 @@ describe('recordingComputeUtils', () => {
155155
describe('getComputedSpans', () => {
156156
const baseDefinition: CompleteTraceDefinition<
157157
'global',
158-
AnyScope,
158+
AnyRelation,
159159
'origin'
160160
> = {
161161
...baseDefinitionFixture,
@@ -195,16 +195,19 @@ describe('recordingComputeUtils', () => {
195195
})
196196

197197
it('should handle operation-start and operation-end special matchers', () => {
198-
const definition: CompleteTraceDefinition<'global', AnyScope, 'origin'> =
199-
{
200-
...baseDefinition,
201-
computedSpanDefinitions: {
202-
'operation-span': {
203-
startSpan: 'operation-start',
204-
endSpan: 'operation-end',
205-
},
198+
const definition: CompleteTraceDefinition<
199+
'global',
200+
AnyRelation,
201+
'origin'
202+
> = {
203+
...baseDefinition,
204+
computedSpanDefinitions: {
205+
'operation-span': {
206+
startSpan: 'operation-start',
207+
endSpan: 'operation-end',
206208
},
207-
}
209+
},
210+
}
208211

209212
const markedCompleteSpan = createMockSpanAndAnnotation(200, {
210213
name: 'end-span',
@@ -233,7 +236,7 @@ describe('recordingComputeUtils', () => {
233236
describe('getComputedValues', () => {
234237
const baseDefinition: CompleteTraceDefinition<
235238
'global',
236-
AnyScope,
239+
AnyRelation,
237240
'origin'
238241
> = {
239242
...baseDefinitionFixture,
@@ -266,20 +269,23 @@ describe('recordingComputeUtils', () => {
266269
})
267270

268271
it('should handle multiple matches in computeValueFromMatches', () => {
269-
const definition: CompleteTraceDefinition<'global', AnyScope, 'origin'> =
270-
{
271-
...baseDefinition,
272-
computedValueDefinitions: {
273-
'status-counts': {
274-
matches: [
275-
({ span }) => span.status === 'error',
276-
({ span }) => span.status === 'ok',
277-
],
278-
computeValueFromMatches: (errors, oks) =>
279-
errors.length + oks.length,
280-
},
272+
const definition: CompleteTraceDefinition<
273+
'global',
274+
AnyRelation,
275+
'origin'
276+
> = {
277+
...baseDefinition,
278+
computedValueDefinitions: {
279+
'status-counts': {
280+
matches: [
281+
({ span }) => span.status === 'error',
282+
({ span }) => span.status === 'ok',
283+
],
284+
computeValueFromMatches: (errors, oks) =>
285+
errors.length + oks.length,
281286
},
282-
}
287+
},
288+
}
283289

284290
const result = getComputedValues({
285291
definition,

src/v3/recordingComputeUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function getComputedRenderBeaconSpans<
192192
}
193193
>()
194194

195-
const scopeKeys = Object.keys(input.relatedTo)
195+
const relatedToKey = Object.keys(input.relatedTo)
196196

197197
// Group render spans by beacon and compute firstStart and lastEnd
198198
for (const entry of recordedItems) {
@@ -213,12 +213,12 @@ function getComputedRenderBeaconSpans<
213213
const relatedTo = r as Record<string, unknown> | undefined
214214
const inputRelatedTo: Record<string, unknown> = input.relatedTo
215215

216-
const scopeMatch = scopeKeys.every(
216+
const relationMatch = relatedToKey.every(
217217
(key) =>
218218
relatedTo?.[key] === undefined ||
219219
inputRelatedTo[key] === relatedTo[key],
220220
)
221-
if (!scopeMatch) continue
221+
if (!relationMatch) continue
222222

223223
const start = startTime.now
224224
const contentfulRenderEnd =

src/v3/spanTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export interface SpanBase<RelationSchemasT> {
8383
startTime: Timestamp
8484

8585
// for non performance entries, relatedTo is set explicitly in the span, something like ticket id or user id
86-
// performance entries can derive relatedTo based using `deriveScopeFromPerformanceEntry`
86+
// performance entries can derive relatedTo based using `deriveRelationFromPerformanceEntry`
8787
relatedTo?: RelationsOnASpan<RelationSchemasT>
8888

8989
attributes: Attributes

src/v3/testUtility/createMockFactory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ export const createTimestamp = (now: number): Timestamp => ({
99
now,
1010
})
1111

12-
export type AnyScope = Record<string, unknown>
12+
export type AnyRelation = Record<string, unknown>
1313

1414
export const createAnnotation = (
15-
span: Span<AnyScope>,
15+
span: Span<AnyRelation>,
1616
traceStartTime: Timestamp,
1717
partial: Partial<SpanAnnotation> = {},
1818
): SpanAnnotation => ({
@@ -26,7 +26,7 @@ export const createAnnotation = (
2626
...partial,
2727
})
2828

29-
export const createMockSpan = <TSpan extends Span<AnyScope>>(
29+
export const createMockSpan = <TSpan extends Span<AnyRelation>>(
3030
startTimeNow: number,
3131
partial: Partial<TSpan>,
3232
): TSpan =>

src/v3/testUtility/fixtures/shouldNotEndWithInteractiveTimeout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
22
// @ts-nocheck
33
import type { SpanAndAnnotation } from '../spanAnnotationTypes'
4-
import type { TicketIdScope } from './fixtures/ticket.activation'
4+
import type { TicketAndUserAndGlobalRelationSchemasFixture } from './relationSchemas'
55

6-
export const shouldNotEndWithInteractiveTimeout: SpanAndAnnotation<TicketIdScope>[] =
6+
export const shouldNotEndWithInteractiveTimeout: SpanAndAnnotation<TicketAndUserAndGlobalRelationSchemasFixture>[] =
77
[
88
{
99
span: {

src/v3/testUtility/fixtures/shouldNotEndWithInterruption.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
22
// @ts-nocheck
3-
import type { SpanAndAnnotation } from '../spanAnnotationTypes'
4-
import type { TicketIdScope } from './fixtures/ticket.activation'
53

6-
export const shouldNotEndWithInterruption: SpanAndAnnotation<TicketIdScope>[] =
4+
import type { SpanAndAnnotation } from '../../spanAnnotationTypes'
5+
import type { TicketAndUserAndGlobalRelationSchemasFixture } from './relationSchemas'
6+
7+
export const shouldNotEndWithInterruption: SpanAndAnnotation<TicketAndUserAndGlobalRelationSchemasFixture>[] =
78
[
89
{
910
span: {

0 commit comments

Comments
 (0)