1 | /**
|
2 | * Create a new event from a logger
|
3 | *
|
4 | * @since 0.1.0
|
5 | *
|
6 | * @param {import("./logger.js").Logger} logger Logger should have a
|
7 | * context, like the default `ctx.log`
|
8 | * @param {AbortSignal|undefined} [signal]
|
9 | * @returns {InsightEvent}
|
10 | */
|
11 | export function newEvent(logger: import("./logger.js").Logger, signal?: AbortSignal | undefined): InsightEvent;
|
12 | /**
|
13 | * Create a 'child' event, reuses the logger, adds it als a child to the passed event
|
14 | *
|
15 | * @since 0.1.0
|
16 | *
|
17 | * @param {InsightEvent} event
|
18 | * @returns {InsightEvent}
|
19 | */
|
20 | export function newEventFromEvent(event: InsightEvent): InsightEvent;
|
21 | /**
|
22 | * Track event start times
|
23 | *
|
24 | * @since 0.1.0
|
25 | *
|
26 | * @param {InsightEvent} event
|
27 | * @param {string} name
|
28 | * @returns {void}
|
29 | */
|
30 | export function eventStart(event: InsightEvent, name: string): void;
|
31 | /**
|
32 | * Rename an event
|
33 | *
|
34 | * @since 0.1.0
|
35 | *
|
36 | * @param {InsightEvent} event
|
37 | * @param {string} name
|
38 | * @returns {void}
|
39 | */
|
40 | export function eventRename(event: InsightEvent, name: string): void;
|
41 | /**
|
42 | * Track event end times and log if necessary
|
43 | *
|
44 | * @since 0.1.0
|
45 | *
|
46 | * @param {InsightEvent} event
|
47 | * @returns {void}
|
48 | */
|
49 | export function eventStop(event: InsightEvent): void;
|
50 | export type InsightEventSpan = {
|
51 | name: string;
|
52 | duration?: number | undefined;
|
53 | startTime: number;
|
54 | stopTime?: number | undefined;
|
55 | abortedTime?: number | undefined;
|
56 | children: InsightEventSpan[];
|
57 | };
|
58 | /**
|
59 | * The insight event is a tool for tracking the duration of (async) functions manually.
|
60 | * By utilizing the insight event, you can gain access to a task or request-specific
|
61 | * logger and obtain insights into the execution time of your functions.
|
62 | *
|
63 | * How to use the Insight Event:
|
64 | *
|
65 | * Start by retrieving a root event. It can be created by calling {@link newEvent }
|
66 | * and passing it a logger. When you use the {@link getApp } from
|
67 | */
|
68 | export type InsightEvent = {
|
69 | log: import("@compas/stdlib").Logger;
|
70 | signal?: AbortSignal | undefined;
|
71 | rootEvent?: InsightEvent | undefined;
|
72 | name?: string | undefined;
|
73 | span: InsightEventSpan;
|
74 | _compasSentrySpan?: import("@sentry/node").Span | undefined;
|
75 | };
|