-
Notifications
You must be signed in to change notification settings - Fork 0
/
Diagnostics.ts
81 lines (74 loc) · 2.72 KB
/
Diagnostics.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Core
*/
import { ClientDiagnosticsHandler, ClientDiagnosticsOptions, DiagnosticsLoggerSeverity, DiagnosticsOptions } from "@itwin/presentation-common";
import { createCombinedDiagnosticsHandler } from "@itwin/presentation-frontend";
/**
* Settings for capturing diagnostics data.
* @public
*/
export interface DiagnosticsProps {
/**
* Settings for capturing rule diagnostics.
* @alpha
*/
ruleDiagnostics?: {
/** Severity of log messages to capture. Defaults to "error" when not set. */
severity?: DiagnosticsLoggerSeverity;
/** Handler of resulting logs. */
handler: ClientDiagnosticsHandler;
};
/**
* Settings for capturing rules engine diagnostics.
* @internal
*/
devDiagnostics?: {
/** Severity of log messages to capture. Defaults to "error" when not set. */
severity?: DiagnosticsLoggerSeverity;
/** Should performance metric be captured. */
perf?: boolean | { minimumDuration: number };
/** Get version of presentation backend. */
backendVersion?: boolean;
/** Handler of resulting logs. */
handler: ClientDiagnosticsHandler;
};
}
/**
* Creates diagnostics options that can be passed to presentation requests based on given
* diagnostics props.
*
* @alpha
*/
export function createDiagnosticsOptions(props: DiagnosticsProps): ClientDiagnosticsOptions | undefined {
if (!props.ruleDiagnostics && !props.devDiagnostics) {
return undefined;
}
const options: DiagnosticsOptions = {};
if (props.devDiagnostics?.perf) {
options.perf = props.devDiagnostics.perf;
}
if (props.devDiagnostics?.severity) {
options.dev = props.devDiagnostics.severity;
}
if (props.ruleDiagnostics?.severity) {
options.editor = props.ruleDiagnostics.severity;
}
let handler: ClientDiagnosticsHandler;
// istanbul ignore else
if (props.devDiagnostics && props.ruleDiagnostics && props.devDiagnostics.handler !== props.ruleDiagnostics.handler) {
handler = createCombinedDiagnosticsHandler([props.devDiagnostics.handler, props.ruleDiagnostics.handler]);
} else if (props.devDiagnostics) {
handler = props.devDiagnostics.handler;
} else if (props.ruleDiagnostics) {
handler = props.ruleDiagnostics.handler;
}
return {
...options,
...(props.devDiagnostics?.backendVersion ? { backendVersion: props.devDiagnostics.backendVersion } : undefined),
handler: handler!,
};
}