From f5d8949f19c43c6614bd09bc678e24de4525bfea Mon Sep 17 00:00:00 2001 From: Yousif Ahmed Date: Wed, 18 Dec 2024 15:12:58 +0000 Subject: [PATCH] refactor(core): allow span factory class to be provided in client options --- packages/core/lib/core.ts | 7 ++++++- packages/core/lib/span-factory.ts | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/core/lib/core.ts b/packages/core/lib/core.ts index f259e35ea..83f53a486 100644 --- a/packages/core/lib/core.ts +++ b/packages/core/lib/core.ts @@ -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 { new(): T, prototype: T } @@ -46,6 +47,7 @@ export interface ClientOptions persistence: Persistence retryQueueFactory: RetryQueueFactory spanContextStorage?: SpanContextStorage + spanFactory?: SpanFactoryConstructor platformExtensions?: (spanFactory: SpanFactory, spanContextStorage: SpanContextStorage) => T } @@ -57,7 +59,10 @@ export function createClient ( 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, diff --git a/packages/core/lib/span-factory.ts b/packages/core/lib/span-factory.ts index 071542f20..23465dedf 100644 --- a/packages/core/lib/span-factory.ts +++ b/packages/core/lib/span-factory.ts @@ -16,7 +16,11 @@ import { isObject, isParentContext } from './validation' export const DISCARD_END_TIME = -1 -export class SpanFactory { +export type SpanFactoryConstructor = new ( + ...args: ConstructorParameters> +) => InstanceType> + +export class SpanFactory { private processor: Processor readonly sampler: ReadonlySampler private readonly idGenerator: IdGenerator