Skip to content

Commit

Permalink
refactor(core): allow span factory class to be provided in client opt…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
yousif-bugsnag committed Dec 18, 2024
1 parent 83883e5 commit f5d8949
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/core/lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { Span, SpanOptions } from './span'
import type { SpanContext, SpanContextStorage } from './span-context'
import { DefaultSpanContextStorage } from './span-context'
import { SpanFactory } from './span-factory'
import type { SpanFactoryConstructor } from './span-factory'
import { timeToNumber } from './time'

interface Constructor<T> { new(): T, prototype: T }
Expand All @@ -46,6 +47,7 @@ export interface ClientOptions<S extends CoreSchema, C extends Configuration, T>
persistence: Persistence
retryQueueFactory: RetryQueueFactory
spanContextStorage?: SpanContextStorage
spanFactory?: SpanFactoryConstructor<C>
platformExtensions?: (spanFactory: SpanFactory<C>, spanContextStorage: SpanContextStorage) => T
}

Expand All @@ -57,7 +59,10 @@ export function createClient<S extends CoreSchema, C extends Configuration, T> (
const spanContextStorage = options.spanContextStorage || new DefaultSpanContextStorage(options.backgroundingListener)
let logger = options.schema.logger.defaultValue
const sampler = new Sampler(1.0)
const spanFactory = new SpanFactory(

const SpanFactoryClass = options.spanFactory || SpanFactory

const spanFactory = new SpanFactoryClass(
processor,
sampler,
options.idGenerator,
Expand Down
6 changes: 5 additions & 1 deletion packages/core/lib/span-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import { isObject, isParentContext } from './validation'

export const DISCARD_END_TIME = -1

export class SpanFactory <C extends Configuration> {
export type SpanFactoryConstructor<C extends Configuration> = new (
...args: ConstructorParameters<typeof SpanFactory<C>>
) => InstanceType<typeof SpanFactory<C>>

export class SpanFactory<C extends Configuration> {
private processor: Processor
readonly sampler: ReadonlySampler
private readonly idGenerator: IdGenerator
Expand Down

0 comments on commit f5d8949

Please sign in to comment.