abxbus 2.5.6 → 2.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/cjs/BaseEvent.d.ts +12 -32
  2. package/dist/cjs/BaseEvent.js +20 -17
  3. package/dist/cjs/BaseEvent.js.map +2 -2
  4. package/dist/cjs/CoreClient.d.ts +167 -0
  5. package/dist/cjs/CoreEventBus.d.ts +334 -0
  6. package/dist/cjs/LockManager.js +1 -1
  7. package/dist/cjs/LockManager.js.map +2 -2
  8. package/dist/cjs/base_event.d.ts +2 -2
  9. package/dist/cjs/event_handler.d.ts +0 -1
  10. package/dist/cjs/events_suck.d.ts +7 -14
  11. package/dist/cjs/events_suck.js +1 -1
  12. package/dist/cjs/events_suck.js.map +2 -2
  13. package/dist/cjs/retry.d.ts +2 -0
  14. package/dist/cjs/retry.js +110 -35
  15. package/dist/cjs/retry.js.map +3 -3
  16. package/dist/cjs/types.d.ts +3 -6
  17. package/dist/cjs/types.js +1 -1
  18. package/dist/cjs/types.js.map +2 -2
  19. package/dist/esm/BaseEvent.js +20 -17
  20. package/dist/esm/BaseEvent.js.map +2 -2
  21. package/dist/esm/LockManager.js +1 -1
  22. package/dist/esm/LockManager.js.map +2 -2
  23. package/dist/esm/events_suck.js +1 -1
  24. package/dist/esm/events_suck.js.map +2 -2
  25. package/dist/esm/retry.js +110 -35
  26. package/dist/esm/retry.js.map +3 -3
  27. package/dist/esm/types.js +1 -1
  28. package/dist/esm/types.js.map +2 -2
  29. package/dist/types/BaseEvent.d.ts +12 -32
  30. package/dist/types/CoreClient.d.ts +167 -0
  31. package/dist/types/CoreEventBus.d.ts +334 -0
  32. package/dist/types/base_event.d.ts +2 -2
  33. package/dist/types/event_handler.d.ts +0 -1
  34. package/dist/types/events_suck.d.ts +7 -14
  35. package/dist/types/retry.d.ts +2 -0
  36. package/dist/types/types.d.ts +3 -6
  37. package/package.json +1 -1
  38. package/src/BaseEvent.ts +93 -75
  39. package/src/LockManager.ts +1 -1
  40. package/src/events_suck.ts +17 -20
  41. package/src/retry.ts +132 -38
  42. package/src/types.ts +4 -5
  43. package/dist/cjs/bridge_ipc.d.ts +0 -45
  44. package/dist/cjs/middleware_otel_tracing.d.ts +0 -49
  45. package/dist/types/bridge_ipc.d.ts +0 -45
  46. package/dist/types/middleware_otel_tracing.d.ts +0 -49
@@ -283,7 +283,7 @@ export class LockManager {
283
283
  this.idle_waiters.push(finish)
284
284
  this.scheduleIdleCheck()
285
285
 
286
- if (timeout_seconds === null || timeout_seconds === undefined) {
286
+ if (timeout_seconds === null || timeout_seconds === undefined || timeout_seconds <= 0) {
287
287
  return
288
288
  }
289
289
 
@@ -3,28 +3,22 @@ import { BaseEvent } from './BaseEvent.js'
3
3
 
4
4
  import type { EventClass, EventResultType } from './types.js'
5
5
 
6
- type EventMap = Record<string, EventClass<BaseEvent>>
7
- type AnyFn = (...args: any[]) => any
8
- type FunctionMap = Record<string, AnyFn>
6
+ type EventMap = Record<string, EventClass<BaseEvent, never>>
7
+ type FunctionMap = Record<string, (...args: never[]) => unknown>
9
8
  type ExtraDict = Record<string, unknown>
10
9
 
11
- type EventFieldsFromFn<TFunc extends AnyFn> =
12
- Parameters<TFunc> extends [infer TArg] ? (TArg extends Record<string, unknown> ? TArg : ExtraDict) : ExtraDict
13
-
14
- type GeneratedEvent<TFunc extends AnyFn> = {
15
- (
16
- data: EventFieldsFromFn<TFunc> & ExtraDict
17
- ): BaseEvent & EventFieldsFromFn<TFunc> & { __event_result_type__?: Awaited<ReturnType<TFunc>> }
18
- new (
19
- data: EventFieldsFromFn<TFunc> & ExtraDict
20
- ): BaseEvent & EventFieldsFromFn<TFunc> & { __event_result_type__?: Awaited<ReturnType<TFunc>> }
21
- event_type?: string
22
- }
10
+ type EventFieldsFromFn<TFunc extends FunctionMap[string]> =
11
+ Parameters<TFunc> extends [infer TArg, ...unknown[]] ? (TArg extends Record<string, unknown> ? TArg : ExtraDict) : ExtraDict
12
+
13
+ type EventFromFn<TFunc extends FunctionMap[string]> = BaseEvent &
14
+ EventFieldsFromFn<TFunc> & {
15
+ __event_result_type__?: Awaited<ReturnType<TFunc>>
16
+ }
23
17
 
24
18
  export type GeneratedEvents<TEvents extends FunctionMap> = {
25
- by_name: { [K in keyof TEvents]: GeneratedEvent<TEvents[K]> }
19
+ by_name: { [K in keyof TEvents]: EventClass<EventFromFn<TEvents[K]>, EventFieldsFromFn<TEvents[K]> & ExtraDict> }
26
20
  } & {
27
- [K in keyof TEvents]: GeneratedEvent<TEvents[K]>
21
+ [K in keyof TEvents]: EventClass<EventFromFn<TEvents[K]>, EventFieldsFromFn<TEvents[K]> & ExtraDict>
28
22
  }
29
23
 
30
24
  type EventInit<TEventClass extends EventClass<BaseEvent>> = [ConstructorParameters<TEventClass>[0]] extends [undefined]
@@ -51,12 +45,12 @@ type DynamicWrappedClient = {
51
45
  } & Record<string, (...args: unknown[]) => Promise<unknown>>
52
46
 
53
47
  export const make_events = <TEvents extends FunctionMap>(events: TEvents): GeneratedEvents<TEvents> => {
54
- const by_name = {} as { [K in keyof TEvents]: GeneratedEvent<TEvents[K]> }
48
+ const by_name = {} as GeneratedEvents<TEvents>['by_name']
55
49
  for (const [event_name] of Object.entries(events) as Array<[keyof TEvents, TEvents[keyof TEvents]]>) {
56
50
  if (!/^[A-Za-z_$][\w$]*$/.test(String(event_name))) {
57
51
  throw new Error(`Invalid event name: ${String(event_name)}`)
58
52
  }
59
- by_name[event_name] = BaseEvent.extend(String(event_name), {}) as unknown as GeneratedEvent<TEvents[keyof TEvents]>
53
+ by_name[event_name] = BaseEvent.extend(String(event_name), {}) as unknown as GeneratedEvents<TEvents>['by_name'][typeof event_name]
60
54
  }
61
55
  return Object.assign({ by_name }, by_name) as GeneratedEvents<TEvents>
62
56
  }
@@ -76,7 +70,10 @@ export const wrap = <TEvents extends EventMap>(class_name: string, methods: TEve
76
70
  Object.defineProperty(WrappedClient.prototype, method_name, {
77
71
  value: async function (this: DynamicWrappedClient, init?: Record<string, unknown>, extra?: Record<string, unknown>) {
78
72
  const payload = { ...(init ?? {}), ...(extra ?? {}) }
79
- return await this.bus.emit(new EventCtor(payload)).now({ first_result: true }).eventResult()
73
+ return await this.bus
74
+ .emit((EventCtor as EventClass<BaseEvent, Record<string, unknown>>)(payload))
75
+ .now({ first_result: true })
76
+ .eventResult()
80
77
  },
81
78
  writable: true,
82
79
  configurable: true,
package/src/retry.ts CHANGED
@@ -21,6 +21,8 @@ type RetryDecorator = {
21
21
 
22
22
  const MULTIPROCESS_SEMAPHORE_DIRNAME = 'browser_use_semaphores'
23
23
  const MULTIPROCESS_STALE_LOCK_MS = 5 * 60 * 1000
24
+ const RETRY_SLOW_WARNING_THROTTLE_MS = 2000
25
+ const RETRY_SLOW_WARNING_ARGS_MAX_LENGTH = 80
24
26
 
25
27
  let multiprocess_fallback_reason_logged: string | null = null
26
28
 
@@ -44,6 +46,9 @@ export interface RetryOptions {
44
46
  /** Per-attempt timeout in seconds. Default: undefined (no per-attempt timeout) */
45
47
  timeout?: number | null
46
48
 
49
+ /** Emit a warning when a decorated call exceeds this many seconds. Default: undefined (disabled) */
50
+ slow_timeout?: number | null
51
+
47
52
  /** Maximum concurrent executions sharing this semaphore. Default: undefined (no concurrency limit) */
48
53
  semaphore_limit?: number | null
49
54
 
@@ -238,6 +243,7 @@ export function retry(options: RetryOptions = {}): RetryDecorator {
238
243
  retry_backoff_factor = 1.0,
239
244
  retry_on_errors,
240
245
  timeout,
246
+ slow_timeout,
241
247
  semaphore_limit,
242
248
  semaphore_name: semaphore_name_option,
243
249
  semaphore_lax = true,
@@ -245,10 +251,13 @@ export function retry(options: RetryOptions = {}): RetryDecorator {
245
251
  semaphore_timeout,
246
252
  } = options
247
253
 
248
- const decorateFunction = <T extends AnyFunction>(target: T, _context?: ClassMethodDecoratorContext): T => {
249
- const fn_name = target.name || (_context?.name as string) || 'anonymous'
254
+ const decorateFunction = <T extends AnyFunction>(target: T, _context?: ClassMethodDecoratorContext, owner_name?: string | null): T => {
255
+ const base_fn_name = target.name || (_context?.name as string) || 'anonymous'
256
+ let fn_name = owner_name ? `${owner_name}.${base_fn_name}` : base_fn_name
250
257
  const effective_max_attempts = Math.max(1, max_attempts)
251
258
  const effective_retry_after = Math.max(0, retry_after)
259
+ const effective_slow_timeout_ms = slow_timeout != null && slow_timeout > 0 ? slow_timeout * 1000 : null
260
+ let last_slow_warning_at = 0
252
261
 
253
262
  const shouldRetry = (error: unknown): boolean => {
254
263
  if (!retry_on_errors || retry_on_errors.length === 0) return true
@@ -275,6 +284,14 @@ export function retry(options: RetryOptions = {}): RetryDecorator {
275
284
  }
276
285
  }
277
286
 
287
+ const emitSlowWarningIfDue = (args: any[], start_time: number): void => {
288
+ if (effective_slow_timeout_ms == null) return
289
+ const now = Date.now()
290
+ if (now - last_slow_warning_at < RETRY_SLOW_WARNING_THROTTLE_MS) return
291
+ last_slow_warning_at = now
292
+ console.warn(`Warning: ${fn_name}(${formatRetrySlowWarningArgs(args)}) slow (${((now - start_time) / 1000).toFixed(1)}s)`)
293
+ }
294
+
278
295
  const runRetryLoopFromThenable = async (
279
296
  this_arg: any,
280
297
  args: any[],
@@ -373,26 +390,45 @@ export function retry(options: RetryOptions = {}): RetryDecorator {
373
390
 
374
391
  // ── Retry loop (runs inside the semaphore and re-entrancy context) ──
375
392
  const runRetryLoop = async (): Promise<any> => {
376
- for (let attempt = 1; attempt <= effective_max_attempts; attempt++) {
377
- try {
378
- if (timeout != null && timeout > 0) {
379
- return await _runWithTimeout(() => Promise.resolve(target.apply(this, args)), timeout * 1000, attempt)
380
- } else {
381
- return await Promise.resolve(target.apply(this, args))
382
- }
383
- } catch (error) {
384
- if (!shouldRetry(error)) throw error
393
+ const call_started_at = Date.now()
394
+ const warning_args = [...args]
395
+ const slow_warning_timer =
396
+ effective_slow_timeout_ms == null
397
+ ? null
398
+ : setTimeout(() => emitSlowWarningIfDue(warning_args, call_started_at), effective_slow_timeout_ms)
399
+ const finishSlowWarning = (): void => {
400
+ if (slow_warning_timer !== null) {
401
+ clearTimeout(slow_warning_timer)
402
+ }
403
+ if (effective_slow_timeout_ms != null && Date.now() - call_started_at >= effective_slow_timeout_ms) {
404
+ emitSlowWarningIfDue(warning_args, call_started_at)
405
+ }
406
+ }
385
407
 
386
- // Last attempt: rethrow
387
- if (attempt >= effective_max_attempts) throw error
408
+ try {
409
+ for (let attempt = 1; attempt <= effective_max_attempts; attempt++) {
410
+ try {
411
+ if (timeout != null && timeout > 0) {
412
+ return await _runWithTimeout(() => Promise.resolve(target.apply(this, args)), timeout * 1000, attempt)
413
+ } else {
414
+ return await Promise.resolve(target.apply(this, args))
415
+ }
416
+ } catch (error) {
417
+ if (!shouldRetry(error)) throw error
418
+
419
+ // Last attempt: rethrow
420
+ if (attempt >= effective_max_attempts) throw error
388
421
 
389
- // Wait before next attempt with exponential backoff
390
- await asyncRetryDelay(attempt)
422
+ // Wait before next attempt with exponential backoff
423
+ await asyncRetryDelay(attempt)
424
+ }
391
425
  }
392
- }
393
426
 
394
- // Unreachable, but satisfies the type checker
395
- throw new Error(`retry(${fn_name}): unexpected end of retry loop`)
427
+ // Unreachable, but satisfies the type checker
428
+ throw new Error(`retry(${fn_name}): unexpected end of retry loop`)
429
+ } finally {
430
+ finishSlowWarning()
431
+ }
396
432
  }
397
433
 
398
434
  try {
@@ -452,27 +488,52 @@ export function retry(options: RetryOptions = {}): RetryDecorator {
452
488
  }
453
489
 
454
490
  const runRetryLoop = (): any => {
455
- for (let attempt = 1; attempt <= effective_max_attempts; attempt++) {
456
- const attempt_started_at = Date.now()
457
- try {
458
- const result = target.apply(this, args)
459
- if (isThenable(result)) {
460
- return runRetryLoopFromThenable(this, args, result, attempt)
461
- }
462
- if (timeout != null && timeout > 0 && Date.now() - attempt_started_at > timeout * 1000) {
463
- throw new RetryTimeoutError(`Timed out after ${timeout}s (attempt ${attempt})`, {
464
- timeout_seconds: timeout,
465
- attempt,
466
- })
491
+ const call_started_at = Date.now()
492
+ const warning_args = [...args]
493
+ const slow_warning_timer =
494
+ effective_slow_timeout_ms == null
495
+ ? null
496
+ : setTimeout(() => emitSlowWarningIfDue(warning_args, call_started_at), effective_slow_timeout_ms)
497
+ const finishSlowWarning = (): void => {
498
+ if (slow_warning_timer !== null) {
499
+ clearTimeout(slow_warning_timer)
500
+ }
501
+ if (effective_slow_timeout_ms != null && Date.now() - call_started_at >= effective_slow_timeout_ms) {
502
+ emitSlowWarningIfDue(warning_args, call_started_at)
503
+ }
504
+ }
505
+
506
+ let finish_on_return = true
507
+ try {
508
+ for (let attempt = 1; attempt <= effective_max_attempts; attempt++) {
509
+ const attempt_started_at = Date.now()
510
+ try {
511
+ const result = target.apply(this, args)
512
+ if (isThenable(result)) {
513
+ finish_on_return = false
514
+ return runRetryLoopFromThenable(this, args, result, attempt).finally(finishSlowWarning)
515
+ }
516
+ if (timeout != null && timeout > 0 && Date.now() - attempt_started_at > timeout * 1000) {
517
+ throw new RetryTimeoutError(`Timed out after ${timeout}s (attempt ${attempt})`, {
518
+ timeout_seconds: timeout,
519
+ attempt,
520
+ })
521
+ }
522
+ return result
523
+ } catch (error) {
524
+ if (!shouldRetry(error)) throw error
525
+ if (attempt >= effective_max_attempts) {
526
+ throw error
527
+ }
528
+ syncRetryDelay(attempt)
467
529
  }
468
- return result
469
- } catch (error) {
470
- if (!shouldRetry(error)) throw error
471
- if (attempt >= effective_max_attempts) throw error
472
- syncRetryDelay(attempt)
530
+ }
531
+ throw new Error(`retry(${fn_name}): unexpected end of retry loop`)
532
+ } finally {
533
+ if (finish_on_return) {
534
+ finishSlowWarning()
473
535
  }
474
536
  }
475
- throw new Error(`retry(${fn_name}): unexpected end of retry loop`)
476
537
  }
477
538
 
478
539
  try {
@@ -494,7 +555,8 @@ export function retry(options: RetryOptions = {}): RetryDecorator {
494
555
  _context.addInitializer(function (this: unknown) {
495
556
  const owner_name = findDecoratedMethodOwnerName(this, _context, retryWrapper)
496
557
  if (owner_name) {
497
- Object.defineProperty(retryWrapper, 'name', { value: `${owner_name}.${fn_name}`, configurable: true })
558
+ fn_name = `${owner_name}.${target.name || (_context.name as string) || 'anonymous'}`
559
+ Object.defineProperty(retryWrapper, 'name', { value: fn_name, configurable: true })
498
560
  }
499
561
  })
500
562
  }
@@ -507,7 +569,13 @@ export function retry(options: RetryOptions = {}): RetryDecorator {
507
569
  descriptor?: LegacyMethodDescriptor
508
570
  ): T | LegacyMethodDescriptor {
509
571
  if (descriptor?.value && typeof descriptor.value === 'function') {
510
- descriptor.value = decorateFunction(descriptor.value)
572
+ const owner_name =
573
+ target && (typeof target === 'object' || typeof target === 'function')
574
+ ? typeof target === 'function'
575
+ ? target.name
576
+ : (target as { constructor?: { name?: string } }).constructor?.name
577
+ : null
578
+ descriptor.value = decorateFunction(descriptor.value, undefined, owner_name)
511
579
  return descriptor
512
580
  }
513
581
  if (typeof target === 'function') {
@@ -569,6 +637,32 @@ function isThenable(value: unknown): value is PromiseLike<unknown> {
569
637
  )
570
638
  }
571
639
 
640
+ function formatRetrySlowWarningArgs(args: any[]): string {
641
+ const preview = args.map(formatRetrySlowWarningValue).join(', ')
642
+ if (preview.length > RETRY_SLOW_WARNING_ARGS_MAX_LENGTH) {
643
+ return `${preview.slice(0, RETRY_SLOW_WARNING_ARGS_MAX_LENGTH - 3).replace(/,?\s*$/, '')}...`
644
+ }
645
+ return preview
646
+ }
647
+
648
+ function formatRetrySlowWarningValue(value: unknown): string {
649
+ let text: string
650
+ if (typeof value === 'string') {
651
+ text = value
652
+ } else if (value === null || value === undefined) {
653
+ text = String(value)
654
+ } else if (typeof value === 'object') {
655
+ try {
656
+ text = JSON.stringify(value)
657
+ } catch {
658
+ text = String(value)
659
+ }
660
+ } else {
661
+ text = String(value)
662
+ }
663
+ return text.replace(/['"]/g, '').slice(0, 3)
664
+ }
665
+
572
666
  /**
573
667
  * Try to acquire a semaphore within a timeout. Returns true if acquired, false if timed out.
574
668
  * If the semaphore is acquired after the timeout (due to the waiter remaining queued),
package/src/types.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  import { z } from 'zod'
2
- import type { BaseEvent } from './BaseEvent.js'
2
+ import type { BaseEvent, EventClass as BaseEventClass } from './BaseEvent.js'
3
3
  import { fromJsonSchema, isJsonSchema, type JsonSchema } from './jsonschema.js'
4
4
 
5
5
  export type EventStatus = 'pending' | 'started' | 'completed'
6
+ export type { EventClass } from './BaseEvent.js'
6
7
 
7
- export type EventClass<T extends BaseEvent = BaseEvent> = { event_type?: string } & (new (...args: any[]) => T)
8
-
9
- export type EventPattern<T extends BaseEvent = BaseEvent> = string | EventClass<T>
8
+ export type EventPattern<T extends BaseEvent = BaseEvent> = string | BaseEventClass<T>
10
9
 
11
10
  export type EventWithResultSchema<TResult> = BaseEvent & { __event_result_type__?: TResult }
12
11
 
@@ -75,7 +74,7 @@ export const normalizeEventPattern = (event_pattern: EventPattern | '*'): string
75
74
  } catch {
76
75
  preview = String(event_pattern).slice(0, 30)
77
76
  }
78
- throw new Error('bus.on(match_pattern, ...) must be a string event type, "*", or a BaseEvent class, got: ' + preview)
77
+ throw new Error('bus.on(match_pattern, ...) must be a string event type, "*", or a BaseEvent.extend() event class, got: ' + preview)
79
78
  }
80
79
 
81
80
  export const isZodSchema = (value: unknown): value is z.ZodTypeAny => !!value && typeof (value as z.ZodTypeAny).safeParse === 'function'
@@ -1,45 +0,0 @@
1
- import { BaseEvent } from './base_event.js';
2
- import { EventBus } from './event_bus.js';
3
- import type { EventClass, EventHandlerCallable, UntypedEventHandlerFunction } from './types.js';
4
- type EndpointScheme = 'unix' | 'http' | 'https';
5
- type ParsedEndpoint = {
6
- raw: string;
7
- scheme: EndpointScheme;
8
- host?: string;
9
- port?: number;
10
- path?: string;
11
- };
12
- export type HTTPEventBridgeOptions = {
13
- send_to?: string | null;
14
- listen_on?: string | null;
15
- name?: string;
16
- };
17
- export declare class EventBridge {
18
- readonly send_to: ParsedEndpoint | null;
19
- readonly listen_on: ParsedEndpoint | null;
20
- readonly name: string;
21
- protected readonly inbound_bus: EventBus;
22
- private start_promise;
23
- private node_server;
24
- constructor(send_to?: string | null, listen_on?: string | null, name?: string);
25
- on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>): void;
26
- on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>): void;
27
- emit<T extends BaseEvent>(event: T): Promise<void>;
28
- dispatch<T extends BaseEvent>(event: T): Promise<void>;
29
- start(): Promise<void>;
30
- close(): Promise<void>;
31
- private ensureListenerStarted;
32
- private handleIncomingPayload;
33
- private sendHttp;
34
- private sendUnix;
35
- private startHttpListener;
36
- private startUnixListener;
37
- }
38
- export declare class HTTPEventBridge extends EventBridge {
39
- constructor(send_to?: string | null, listen_on?: string | null, name?: string);
40
- constructor(options?: HTTPEventBridgeOptions);
41
- }
42
- export declare class SocketEventBridge extends EventBridge {
43
- constructor(path?: string | null, name?: string);
44
- }
45
- export {};
@@ -1,49 +0,0 @@
1
- import { trace, type Span, type SpanAttributes, type SpanContext, type TimeInput, type Tracer } from '@opentelemetry/api';
2
- import type { BaseEvent } from './base_event.js';
3
- import type { EventBus } from './event_bus.js';
4
- import type { EventResult } from './event_result.js';
5
- import type { EventBusMiddleware } from './middlewares.js';
6
- import type { EventStatus } from './types.js';
7
- type OpenTelemetryTraceApi = Pick<typeof trace, 'getTracer' | 'setSpan'> & Partial<Pick<typeof trace, 'setSpanContext'>>;
8
- export type OtelTracingSpanFactoryInput = {
9
- name: string;
10
- span_context: SpanContext;
11
- parent_span_context?: SpanContext;
12
- attributes: SpanAttributes;
13
- start_time?: TimeInput;
14
- };
15
- export type OtelTracingSpanFactory = (input: OtelTracingSpanFactoryInput) => Span;
16
- export type OtelTracingSpanProvider = object;
17
- export type OtelTracingMiddlewareOptions = {
18
- tracer?: Tracer;
19
- trace_api?: OpenTelemetryTraceApi;
20
- span_provider?: OtelTracingSpanProvider;
21
- span_factory?: OtelTracingSpanFactory;
22
- otlp_endpoint?: string;
23
- service_name?: string;
24
- instrumentation_name?: string;
25
- root_span_attributes?: SpanAttributes | ((eventbus: EventBus, event: BaseEvent) => SpanAttributes);
26
- };
27
- export declare class OtelTracingMiddleware implements EventBusMiddleware {
28
- private readonly tracer;
29
- private readonly trace_api;
30
- private readonly span_factory?;
31
- private readonly span_provider?;
32
- private readonly root_span_attributes;
33
- private readonly event_spans;
34
- private readonly event_contexts;
35
- private readonly handler_spans;
36
- private readonly handler_contexts;
37
- constructor(options?: OtelTracingMiddlewareOptions);
38
- onEventChange(eventbus: EventBus, event: BaseEvent, status: EventStatus): void;
39
- onEventResultChange(eventbus: EventBus, event: BaseEvent, event_result: EventResult, status: EventStatus): void;
40
- private startEventSpan;
41
- private completeEventSpan;
42
- private startHandlerSpan;
43
- private completeHandlerSpan;
44
- private parentContextForEvent;
45
- private completeEventSpanWithFactory;
46
- private exportEventTreeWithFactory;
47
- private exportHandlerSpanWithFactory;
48
- }
49
- export {};
@@ -1,45 +0,0 @@
1
- import { BaseEvent } from './base_event.js';
2
- import { EventBus } from './event_bus.js';
3
- import type { EventClass, EventHandlerCallable, UntypedEventHandlerFunction } from './types.js';
4
- type EndpointScheme = 'unix' | 'http' | 'https';
5
- type ParsedEndpoint = {
6
- raw: string;
7
- scheme: EndpointScheme;
8
- host?: string;
9
- port?: number;
10
- path?: string;
11
- };
12
- export type HTTPEventBridgeOptions = {
13
- send_to?: string | null;
14
- listen_on?: string | null;
15
- name?: string;
16
- };
17
- export declare class EventBridge {
18
- readonly send_to: ParsedEndpoint | null;
19
- readonly listen_on: ParsedEndpoint | null;
20
- readonly name: string;
21
- protected readonly inbound_bus: EventBus;
22
- private start_promise;
23
- private node_server;
24
- constructor(send_to?: string | null, listen_on?: string | null, name?: string);
25
- on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>): void;
26
- on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>): void;
27
- emit<T extends BaseEvent>(event: T): Promise<void>;
28
- dispatch<T extends BaseEvent>(event: T): Promise<void>;
29
- start(): Promise<void>;
30
- close(): Promise<void>;
31
- private ensureListenerStarted;
32
- private handleIncomingPayload;
33
- private sendHttp;
34
- private sendUnix;
35
- private startHttpListener;
36
- private startUnixListener;
37
- }
38
- export declare class HTTPEventBridge extends EventBridge {
39
- constructor(send_to?: string | null, listen_on?: string | null, name?: string);
40
- constructor(options?: HTTPEventBridgeOptions);
41
- }
42
- export declare class SocketEventBridge extends EventBridge {
43
- constructor(path?: string | null, name?: string);
44
- }
45
- export {};
@@ -1,49 +0,0 @@
1
- import { trace, type Span, type SpanAttributes, type SpanContext, type TimeInput, type Tracer } from '@opentelemetry/api';
2
- import type { BaseEvent } from './base_event.js';
3
- import type { EventBus } from './event_bus.js';
4
- import type { EventResult } from './event_result.js';
5
- import type { EventBusMiddleware } from './middlewares.js';
6
- import type { EventStatus } from './types.js';
7
- type OpenTelemetryTraceApi = Pick<typeof trace, 'getTracer' | 'setSpan'> & Partial<Pick<typeof trace, 'setSpanContext'>>;
8
- export type OtelTracingSpanFactoryInput = {
9
- name: string;
10
- span_context: SpanContext;
11
- parent_span_context?: SpanContext;
12
- attributes: SpanAttributes;
13
- start_time?: TimeInput;
14
- };
15
- export type OtelTracingSpanFactory = (input: OtelTracingSpanFactoryInput) => Span;
16
- export type OtelTracingSpanProvider = object;
17
- export type OtelTracingMiddlewareOptions = {
18
- tracer?: Tracer;
19
- trace_api?: OpenTelemetryTraceApi;
20
- span_provider?: OtelTracingSpanProvider;
21
- span_factory?: OtelTracingSpanFactory;
22
- otlp_endpoint?: string;
23
- service_name?: string;
24
- instrumentation_name?: string;
25
- root_span_attributes?: SpanAttributes | ((eventbus: EventBus, event: BaseEvent) => SpanAttributes);
26
- };
27
- export declare class OtelTracingMiddleware implements EventBusMiddleware {
28
- private readonly tracer;
29
- private readonly trace_api;
30
- private readonly span_factory?;
31
- private readonly span_provider?;
32
- private readonly root_span_attributes;
33
- private readonly event_spans;
34
- private readonly event_contexts;
35
- private readonly handler_spans;
36
- private readonly handler_contexts;
37
- constructor(options?: OtelTracingMiddlewareOptions);
38
- onEventChange(eventbus: EventBus, event: BaseEvent, status: EventStatus): void;
39
- onEventResultChange(eventbus: EventBus, event: BaseEvent, event_result: EventResult, status: EventStatus): void;
40
- private startEventSpan;
41
- private completeEventSpan;
42
- private startHandlerSpan;
43
- private completeHandlerSpan;
44
- private parentContextForEvent;
45
- private completeEventSpanWithFactory;
46
- private exportEventTreeWithFactory;
47
- private exportHandlerSpanWithFactory;
48
- }
49
- export {};