@fluidframework/telemetry-utils 2.0.0-internal.7.3.0 → 2.0.0-internal.7.4.0
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.
- package/CHANGELOG.md +15 -0
- package/api-extractor-lint.json +13 -0
- package/api-extractor.json +3 -3
- package/api-report/telemetry-utils.api.md +64 -57
- package/dist/config.d.ts +37 -10
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +30 -0
- package/dist/config.js.map +1 -1
- package/dist/error.d.ts +12 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +18 -1
- package/dist/error.js.map +1 -1
- package/dist/errorLogging.d.ts +7 -2
- package/dist/errorLogging.d.ts.map +1 -1
- package/dist/errorLogging.js +7 -2
- package/dist/errorLogging.js.map +1 -1
- package/dist/eventEmitterWithErrorHandling.d.ts +6 -0
- package/dist/eventEmitterWithErrorHandling.d.ts.map +1 -1
- package/dist/eventEmitterWithErrorHandling.js +6 -0
- package/dist/eventEmitterWithErrorHandling.js.map +1 -1
- package/dist/events.d.ts +15 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +16 -0
- package/dist/events.js.map +1 -1
- package/dist/fluidErrorBase.d.ts +8 -0
- package/dist/fluidErrorBase.d.ts.map +1 -1
- package/dist/fluidErrorBase.js +6 -0
- package/dist/fluidErrorBase.js.map +1 -1
- package/dist/index.d.ts +20 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +117 -17
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +82 -12
- package/dist/logger.js.map +1 -1
- package/dist/mockLogger.d.ts +2 -0
- package/dist/mockLogger.d.ts.map +1 -1
- package/dist/mockLogger.js +2 -0
- package/dist/mockLogger.js.map +1 -1
- package/dist/sampledTelemetryHelper.d.ts +7 -3
- package/dist/sampledTelemetryHelper.d.ts.map +1 -1
- package/dist/sampledTelemetryHelper.js +7 -3
- package/dist/sampledTelemetryHelper.js.map +1 -1
- package/dist/telemetry-utils-alpha.d.ts +270 -0
- package/dist/telemetry-utils-beta.d.ts +205 -0
- package/dist/telemetry-utils-public.d.ts +205 -0
- package/dist/telemetry-utils-untrimmed.d.ts +1123 -0
- package/dist/telemetryTypes.d.ts +27 -8
- package/dist/telemetryTypes.d.ts.map +1 -1
- package/dist/telemetryTypes.js.map +1 -1
- package/dist/thresholdCounter.d.ts +3 -2
- package/dist/thresholdCounter.d.ts.map +1 -1
- package/dist/thresholdCounter.js +3 -2
- package/dist/thresholdCounter.js.map +1 -1
- package/dist/utils.d.ts +6 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +6 -0
- package/dist/utils.js.map +1 -1
- package/lib/config.d.ts +37 -10
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +30 -0
- package/lib/config.js.map +1 -1
- package/lib/error.d.ts +12 -0
- package/lib/error.d.ts.map +1 -1
- package/lib/error.js +16 -0
- package/lib/error.js.map +1 -1
- package/lib/errorLogging.d.ts +7 -2
- package/lib/errorLogging.d.ts.map +1 -1
- package/lib/errorLogging.js +7 -2
- package/lib/errorLogging.js.map +1 -1
- package/lib/eventEmitterWithErrorHandling.d.ts +6 -0
- package/lib/eventEmitterWithErrorHandling.d.ts.map +1 -1
- package/lib/eventEmitterWithErrorHandling.js +6 -0
- package/lib/eventEmitterWithErrorHandling.js.map +1 -1
- package/lib/events.d.ts +15 -0
- package/lib/events.d.ts.map +1 -1
- package/lib/events.js +16 -0
- package/lib/events.js.map +1 -1
- package/lib/fluidErrorBase.d.ts +8 -0
- package/lib/fluidErrorBase.d.ts.map +1 -1
- package/lib/fluidErrorBase.js +6 -0
- package/lib/fluidErrorBase.js.map +1 -1
- package/lib/index.d.ts +20 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/logger.d.ts +117 -17
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +82 -12
- package/lib/logger.js.map +1 -1
- package/lib/mockLogger.d.ts +2 -0
- package/lib/mockLogger.d.ts.map +1 -1
- package/lib/mockLogger.js +2 -0
- package/lib/mockLogger.js.map +1 -1
- package/lib/sampledTelemetryHelper.d.ts +7 -3
- package/lib/sampledTelemetryHelper.d.ts.map +1 -1
- package/lib/sampledTelemetryHelper.js +7 -3
- package/lib/sampledTelemetryHelper.js.map +1 -1
- package/lib/telemetry-utils-alpha.d.ts +270 -0
- package/lib/telemetry-utils-beta.d.ts +205 -0
- package/lib/telemetry-utils-public.d.ts +205 -0
- package/lib/telemetry-utils-untrimmed.d.ts +1123 -0
- package/lib/telemetryTypes.d.ts +27 -8
- package/lib/telemetryTypes.d.ts.map +1 -1
- package/lib/telemetryTypes.js.map +1 -1
- package/lib/thresholdCounter.d.ts +3 -2
- package/lib/thresholdCounter.d.ts.map +1 -1
- package/lib/thresholdCounter.js +3 -2
- package/lib/thresholdCounter.js.map +1 -1
- package/lib/utils.d.ts +6 -0
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +6 -0
- package/lib/utils.js.map +1 -1
- package/package.json +29 -10
- package/src/config.ts +41 -12
- package/src/error.ts +21 -0
- package/src/errorLogging.ts +7 -2
- package/src/eventEmitterWithErrorHandling.ts +6 -0
- package/src/events.ts +18 -0
- package/src/fluidErrorBase.ts +8 -0
- package/src/index.ts +21 -2
- package/src/logger.ts +125 -17
- package/src/mockLogger.ts +2 -0
- package/src/sampledTelemetryHelper.ts +7 -3
- package/src/telemetryTypes.ts +27 -8
- package/src/thresholdCounter.ts +3 -2
- package/src/utils.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @fluidframework/telemetry-utils
|
|
2
2
|
|
|
3
|
+
## 2.0.0-internal.7.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- telemetry-utils: Deprecate ConfigTypes and IConfigProviderBase ([#18597](https://github.com/microsoft/FluidFramework/issues/18597)) [39b9ff57c0](https://github.com/microsoft/FluidFramework/commits/39b9ff57c0184b72f0e3f9425922dda944995265)
|
|
8
|
+
|
|
9
|
+
The types `ConfigTypes` and `IConfigProviderBase` have been deprecated in the @fluidframework/telemetry-utils package.
|
|
10
|
+
The types can now be found in the @fluidframework/core-interfaces package. Please replace any uses with the types from
|
|
11
|
+
@fluidframework/core-interfaces.
|
|
12
|
+
|
|
13
|
+
- telemetry-utils: Deprecated logIfFalse ([#18047](https://github.com/microsoft/FluidFramework/issues/18047)) [57614ffdc6](https://github.com/microsoft/FluidFramework/commits/57614ffdc6e3fbd22ddbe5ed589c75d3d195aa48)
|
|
14
|
+
|
|
15
|
+
This functionality was not intended for export and will be removed in a future release.
|
|
16
|
+
No replacement API is offered because the logic is trivial to reproduce as needed.
|
|
17
|
+
|
|
3
18
|
## 2.0.0-internal.7.3.0
|
|
4
19
|
|
|
5
20
|
Dependency updates only.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
"extends": "../../../common/build/build-common/api-extractor-lint.json",
|
|
4
|
+
"messages": {
|
|
5
|
+
"extractorMessageReporting": {
|
|
6
|
+
// TODO: remove once base config has this enabled as an error
|
|
7
|
+
"ae-incompatible-release-tags": {
|
|
8
|
+
"logLevel": "error",
|
|
9
|
+
"addToApiReportFile": false
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
package/api-extractor.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
-
"extends": "
|
|
3
|
+
"extends": "../../../common/build/build-common/api-extractor-base.json",
|
|
4
4
|
"messages": {
|
|
5
5
|
"extractorMessageReporting": {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
// TODO: Add missing documentation and remove this rule override
|
|
7
|
+
"ae-undocumented": {
|
|
8
8
|
"logLevel": "none"
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { EventEmitter } from 'events';
|
|
10
10
|
import { EventEmitterEventType } from '@fluid-internal/client-utils';
|
|
11
|
+
import { IConfigProviderBase as IConfigProviderBase_2 } from '@fluidframework/core-interfaces';
|
|
11
12
|
import { IDisposable } from '@fluidframework/core-interfaces';
|
|
12
13
|
import { IErrorBase } from '@fluidframework/core-interfaces';
|
|
13
14
|
import { IEvent } from '@fluidframework/core-interfaces';
|
|
@@ -29,29 +30,24 @@ import { TelemetryBaseEventPropertyType } from '@fluidframework/core-interfaces'
|
|
|
29
30
|
import { TelemetryEventPropertyType } from '@fluidframework/core-interfaces';
|
|
30
31
|
import { TypedEventEmitter } from '@fluid-internal/client-utils';
|
|
31
32
|
|
|
32
|
-
// @
|
|
33
|
+
// @internal @deprecated
|
|
33
34
|
export type ConfigTypes = string | number | boolean | number[] | string[] | boolean[] | undefined;
|
|
34
35
|
|
|
35
|
-
// @
|
|
36
|
+
// @internal (undocumented)
|
|
36
37
|
export const connectedEventName = "connected";
|
|
37
38
|
|
|
38
|
-
// @
|
|
39
|
+
// @internal
|
|
39
40
|
export function createChildLogger(props?: {
|
|
40
41
|
logger?: ITelemetryBaseLogger;
|
|
41
42
|
namespace?: string;
|
|
42
43
|
properties?: ITelemetryLoggerPropertyBags;
|
|
43
44
|
}): ITelemetryLoggerExt;
|
|
44
45
|
|
|
45
|
-
// @
|
|
46
|
+
// @internal
|
|
46
47
|
export function createChildMonitoringContext(props: Parameters<typeof createChildLogger>[0]): MonitoringContext;
|
|
47
48
|
|
|
48
|
-
// @
|
|
49
|
-
export function createMultiSinkLogger(props:
|
|
50
|
-
namespace?: string;
|
|
51
|
-
properties?: ITelemetryLoggerPropertyBags;
|
|
52
|
-
loggers?: (ITelemetryBaseLogger | undefined)[];
|
|
53
|
-
tryInheritProperties?: true;
|
|
54
|
-
}): ITelemetryLoggerExt;
|
|
49
|
+
// @internal
|
|
50
|
+
export function createMultiSinkLogger(props: MultiSinkLoggerProperties): ITelemetryLoggerExt;
|
|
55
51
|
|
|
56
52
|
// @internal
|
|
57
53
|
export function createSampledLogger(logger: ITelemetryLoggerExt, eventSampler?: IEventSampler): ISampledTelemetryLogger;
|
|
@@ -74,17 +70,17 @@ export class DataProcessingError extends LoggingError implements IErrorBase, IFl
|
|
|
74
70
|
static wrapIfUnrecognized(originalError: unknown, dataProcessingCodepath: string, messageLike?: Partial<Pick<ISequencedDocumentMessage, "clientId" | "sequenceNumber" | "clientSequenceNumber" | "referenceSequenceNumber" | "minimumSequenceNumber" | "timestamp">>): IFluidErrorBase;
|
|
75
71
|
}
|
|
76
72
|
|
|
77
|
-
// @
|
|
73
|
+
// @internal (undocumented)
|
|
78
74
|
export const disconnectedEventName = "disconnected";
|
|
79
75
|
|
|
80
|
-
// @
|
|
76
|
+
// @alpha
|
|
81
77
|
export class EventEmitterWithErrorHandling<TEvent extends IEvent = IEvent> extends TypedEventEmitter<TEvent> {
|
|
82
78
|
constructor(errorHandler: (eventName: EventEmitterEventType, error: any) => void);
|
|
83
79
|
// (undocumented)
|
|
84
80
|
emit(event: EventEmitterEventType, ...args: unknown[]): boolean;
|
|
85
81
|
}
|
|
86
82
|
|
|
87
|
-
// @
|
|
83
|
+
// @internal
|
|
88
84
|
export const eventNamespaceSeparator: ":";
|
|
89
85
|
|
|
90
86
|
// @internal
|
|
@@ -94,7 +90,7 @@ export function extractLogSafeErrorProperties(error: unknown, sanitizeStack: boo
|
|
|
94
90
|
stack?: string | undefined;
|
|
95
91
|
};
|
|
96
92
|
|
|
97
|
-
// @
|
|
93
|
+
// @internal
|
|
98
94
|
export const extractSafePropertiesFromMessage: (messageLike: Partial<Pick<ISequencedDocumentMessage, "clientId" | "sequenceNumber" | "clientSequenceNumber" | "referenceSequenceNumber" | "minimumSequenceNumber" | "timestamp">>) => {
|
|
99
95
|
messageClientId: string | undefined;
|
|
100
96
|
messageSequenceNumber: number | undefined;
|
|
@@ -104,7 +100,7 @@ export const extractSafePropertiesFromMessage: (messageLike: Partial<Pick<ISeque
|
|
|
104
100
|
messageTimestamp: number | undefined;
|
|
105
101
|
};
|
|
106
102
|
|
|
107
|
-
// @
|
|
103
|
+
// @internal (undocumented)
|
|
108
104
|
export function formatTick(tick: number): number;
|
|
109
105
|
|
|
110
106
|
// @internal
|
|
@@ -125,13 +121,13 @@ export class GenericError extends LoggingError implements IGenericError, IFluidE
|
|
|
125
121
|
// @internal
|
|
126
122
|
export const getCircularReplacer: () => (key: string, value: unknown) => any;
|
|
127
123
|
|
|
128
|
-
// @
|
|
124
|
+
// @internal
|
|
129
125
|
export const hasErrorInstanceId: (x: unknown) => x is {
|
|
130
126
|
errorInstanceId: string;
|
|
131
127
|
};
|
|
132
128
|
|
|
133
|
-
// @
|
|
134
|
-
export interface IConfigProvider extends
|
|
129
|
+
// @internal
|
|
130
|
+
export interface IConfigProvider extends IConfigProviderBase_2 {
|
|
135
131
|
// (undocumented)
|
|
136
132
|
getBoolean(name: string): boolean | undefined;
|
|
137
133
|
// (undocumented)
|
|
@@ -146,7 +142,7 @@ export interface IConfigProvider extends IConfigProviderBase {
|
|
|
146
142
|
getStringArray(name: string): string[] | undefined;
|
|
147
143
|
}
|
|
148
144
|
|
|
149
|
-
// @
|
|
145
|
+
// @internal @deprecated
|
|
150
146
|
export interface IConfigProviderBase {
|
|
151
147
|
// (undocumented)
|
|
152
148
|
getRawConfig(name: string): ConfigTypes;
|
|
@@ -163,7 +159,7 @@ export interface IFluidErrorAnnotations {
|
|
|
163
159
|
props?: ITelemetryBaseProperties;
|
|
164
160
|
}
|
|
165
161
|
|
|
166
|
-
// @
|
|
162
|
+
// @internal
|
|
167
163
|
export interface IFluidErrorBase extends Error {
|
|
168
164
|
addTelemetryProperties: (props: ITelemetryProperties) => void;
|
|
169
165
|
readonly errorInstanceId: string;
|
|
@@ -174,7 +170,7 @@ export interface IFluidErrorBase extends Error {
|
|
|
174
170
|
readonly stack?: string;
|
|
175
171
|
}
|
|
176
172
|
|
|
177
|
-
// @
|
|
173
|
+
// @internal
|
|
178
174
|
export interface IPerformanceEventMarkers {
|
|
179
175
|
// (undocumented)
|
|
180
176
|
cancel?: "generic" | "error";
|
|
@@ -192,19 +188,19 @@ export interface ISampledTelemetryLogger extends ITelemetryLoggerExt {
|
|
|
192
188
|
// @internal
|
|
193
189
|
export function isExternalError(error: unknown): boolean;
|
|
194
190
|
|
|
195
|
-
// @
|
|
191
|
+
// @internal
|
|
196
192
|
export function isFluidError(error: unknown): error is IFluidErrorBase;
|
|
197
193
|
|
|
198
|
-
// @
|
|
194
|
+
// @internal
|
|
199
195
|
export const isILoggingError: (x: unknown) => x is ILoggingError;
|
|
200
196
|
|
|
201
|
-
// @
|
|
197
|
+
// @internal
|
|
202
198
|
export function isTaggedTelemetryPropertyValue(x: Tagged<TelemetryEventPropertyTypeExt> | TelemetryEventPropertyTypeExt): x is Tagged<TelemetryEventPropertyTypeExt>;
|
|
203
199
|
|
|
204
|
-
// @
|
|
200
|
+
// @internal
|
|
205
201
|
export function isValidLegacyError(error: unknown): error is Omit<IFluidErrorBase, "errorInstanceId">;
|
|
206
202
|
|
|
207
|
-
// @
|
|
203
|
+
// @internal @deprecated
|
|
208
204
|
export interface ITaggedTelemetryPropertyTypeExt {
|
|
209
205
|
// (undocumented)
|
|
210
206
|
tag: string;
|
|
@@ -212,13 +208,13 @@ export interface ITaggedTelemetryPropertyTypeExt {
|
|
|
212
208
|
value: TelemetryEventPropertyTypeExt;
|
|
213
209
|
}
|
|
214
210
|
|
|
215
|
-
// @
|
|
211
|
+
// @alpha
|
|
216
212
|
export interface ITelemetryErrorEventExt extends ITelemetryPropertiesExt {
|
|
217
213
|
// (undocumented)
|
|
218
214
|
eventName: string;
|
|
219
215
|
}
|
|
220
216
|
|
|
221
|
-
// @
|
|
217
|
+
// @internal
|
|
222
218
|
export interface ITelemetryEventExt extends ITelemetryPropertiesExt {
|
|
223
219
|
// (undocumented)
|
|
224
220
|
category: string;
|
|
@@ -226,7 +222,7 @@ export interface ITelemetryEventExt extends ITelemetryPropertiesExt {
|
|
|
226
222
|
eventName: string;
|
|
227
223
|
}
|
|
228
224
|
|
|
229
|
-
// @
|
|
225
|
+
// @alpha
|
|
230
226
|
export interface ITelemetryGenericEventExt extends ITelemetryPropertiesExt {
|
|
231
227
|
// (undocumented)
|
|
232
228
|
category?: TelemetryEventCategory;
|
|
@@ -234,20 +230,20 @@ export interface ITelemetryGenericEventExt extends ITelemetryPropertiesExt {
|
|
|
234
230
|
eventName: string;
|
|
235
231
|
}
|
|
236
232
|
|
|
237
|
-
// @
|
|
233
|
+
// @alpha
|
|
238
234
|
export interface ITelemetryLoggerExt extends ITelemetryBaseLogger {
|
|
239
235
|
sendErrorEvent(event: ITelemetryErrorEventExt, error?: unknown): void;
|
|
240
236
|
sendPerformanceEvent(event: ITelemetryPerformanceEventExt, error?: unknown, logLevel?: typeof LogLevel.verbose | typeof LogLevel.default): void;
|
|
241
237
|
sendTelemetryEvent(event: ITelemetryGenericEventExt, error?: unknown, logLevel?: typeof LogLevel.verbose | typeof LogLevel.default): void;
|
|
242
238
|
}
|
|
243
239
|
|
|
244
|
-
// @
|
|
240
|
+
// @internal (undocumented)
|
|
245
241
|
export interface ITelemetryLoggerPropertyBag {
|
|
246
242
|
// (undocumented)
|
|
247
243
|
[index: string]: TelemetryEventPropertyTypes | (() => TelemetryEventPropertyTypes);
|
|
248
244
|
}
|
|
249
245
|
|
|
250
|
-
// @
|
|
246
|
+
// @internal (undocumented)
|
|
251
247
|
export interface ITelemetryLoggerPropertyBags {
|
|
252
248
|
// (undocumented)
|
|
253
249
|
all?: ITelemetryLoggerPropertyBag;
|
|
@@ -255,19 +251,19 @@ export interface ITelemetryLoggerPropertyBags {
|
|
|
255
251
|
error?: ITelemetryLoggerPropertyBag;
|
|
256
252
|
}
|
|
257
253
|
|
|
258
|
-
// @
|
|
254
|
+
// @alpha
|
|
259
255
|
export interface ITelemetryPerformanceEventExt extends ITelemetryGenericEventExt {
|
|
260
256
|
// (undocumented)
|
|
261
257
|
duration?: number;
|
|
262
258
|
}
|
|
263
259
|
|
|
264
|
-
// @
|
|
260
|
+
// @alpha
|
|
265
261
|
export interface ITelemetryPropertiesExt {
|
|
266
262
|
// (undocumented)
|
|
267
263
|
[index: string]: TelemetryEventPropertyTypeExt | Tagged<TelemetryEventPropertyTypeExt>;
|
|
268
264
|
}
|
|
269
265
|
|
|
270
|
-
// @
|
|
266
|
+
// @internal
|
|
271
267
|
export function loggerToMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(logger: L): MonitoringContext<L>;
|
|
272
268
|
|
|
273
269
|
// @internal
|
|
@@ -282,13 +278,13 @@ export class LoggingError extends Error implements ILoggingError, Omit<IFluidErr
|
|
|
282
278
|
static typeCheck(object: unknown): object is LoggingError;
|
|
283
279
|
}
|
|
284
280
|
|
|
285
|
-
// @
|
|
281
|
+
// @internal @deprecated
|
|
286
282
|
export function logIfFalse(condition: unknown, logger: ITelemetryBaseLogger, event: string | ITelemetryGenericEvent): condition is true;
|
|
287
283
|
|
|
288
|
-
// @
|
|
289
|
-
export function mixinMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(logger: L, ...configs: (
|
|
284
|
+
// @internal
|
|
285
|
+
export function mixinMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(logger: L, ...configs: (IConfigProviderBase_2 | undefined)[]): MonitoringContext<L>;
|
|
290
286
|
|
|
291
|
-
// @
|
|
287
|
+
// @internal
|
|
292
288
|
export class MockLogger implements ITelemetryBaseLogger {
|
|
293
289
|
constructor(minLogLevel?: LogLevel | undefined);
|
|
294
290
|
assertMatch(expectedEvents: Omit<ITelemetryBaseEvent, "category">[], message?: string, inlineDetailsProp?: boolean): void;
|
|
@@ -310,7 +306,7 @@ export class MockLogger implements ITelemetryBaseLogger {
|
|
|
310
306
|
toTelemetryLogger(): ITelemetryLoggerExt;
|
|
311
307
|
}
|
|
312
308
|
|
|
313
|
-
// @
|
|
309
|
+
// @internal
|
|
314
310
|
export interface MonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt> {
|
|
315
311
|
// (undocumented)
|
|
316
312
|
config: IConfigProvider;
|
|
@@ -318,19 +314,27 @@ export interface MonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLo
|
|
|
318
314
|
logger: L;
|
|
319
315
|
}
|
|
320
316
|
|
|
317
|
+
// @internal
|
|
318
|
+
export interface MultiSinkLoggerProperties {
|
|
319
|
+
loggers?: (ITelemetryBaseLogger | undefined)[];
|
|
320
|
+
namespace?: string;
|
|
321
|
+
properties?: ITelemetryLoggerPropertyBags;
|
|
322
|
+
tryInheritProperties?: true;
|
|
323
|
+
}
|
|
324
|
+
|
|
321
325
|
// @internal
|
|
322
326
|
export const NORMALIZED_ERROR_TYPE = "genericError";
|
|
323
327
|
|
|
324
328
|
// @internal
|
|
325
329
|
export function normalizeError(error: unknown, annotations?: IFluidErrorAnnotations): IFluidErrorBase;
|
|
326
330
|
|
|
327
|
-
// @
|
|
331
|
+
// @internal
|
|
328
332
|
export function numberFromString(str: string | null | undefined): string | number | undefined;
|
|
329
333
|
|
|
330
334
|
// @internal
|
|
331
335
|
export function overwriteStack(error: IFluidErrorBase | LoggingError, stack: string): void;
|
|
332
336
|
|
|
333
|
-
// @
|
|
337
|
+
// @internal
|
|
334
338
|
export class PerformanceEvent {
|
|
335
339
|
protected constructor(logger: ITelemetryLoggerExt, event: ITelemetryGenericEvent, markers?: IPerformanceEventMarkers, recordHeapSize?: boolean, emitLogs?: boolean);
|
|
336
340
|
// (undocumented)
|
|
@@ -347,13 +351,13 @@ export class PerformanceEvent {
|
|
|
347
351
|
static timedExecAsync<T>(logger: ITelemetryLoggerExt, event: ITelemetryGenericEvent, callback: (event: PerformanceEvent) => Promise<T>, markers?: IPerformanceEventMarkers, recordHeapSize?: boolean, sampleThreshold?: number): Promise<T>;
|
|
348
352
|
}
|
|
349
353
|
|
|
350
|
-
// @
|
|
354
|
+
// @internal
|
|
351
355
|
export function raiseConnectedEvent(logger: ITelemetryLoggerExt, emitter: EventEmitter, connected: boolean, clientId?: string, disconnectedReason?: string): void;
|
|
352
356
|
|
|
353
|
-
// @
|
|
357
|
+
// @internal (undocumented)
|
|
354
358
|
export function safeRaiseEvent(emitter: EventEmitter, logger: ITelemetryLoggerExt, event: string, ...args: unknown[]): void;
|
|
355
359
|
|
|
356
|
-
// @
|
|
360
|
+
// @internal
|
|
357
361
|
export class SampledTelemetryHelper implements IDisposable {
|
|
358
362
|
constructor(eventBase: ITelemetryGenericEvent, logger: ITelemetryLoggerExt, sampleThreshold: number, includeAggregateMetrics?: boolean, perBucketProperties?: Map<string, ITelemetryProperties>);
|
|
359
363
|
// (undocumented)
|
|
@@ -363,10 +367,10 @@ export class SampledTelemetryHelper implements IDisposable {
|
|
|
363
367
|
measure<T>(codeToMeasure: () => T, bucket?: string): T;
|
|
364
368
|
}
|
|
365
369
|
|
|
366
|
-
// @
|
|
367
|
-
export const sessionStorageConfigProvider: Lazy<
|
|
370
|
+
// @internal
|
|
371
|
+
export const sessionStorageConfigProvider: Lazy<IConfigProviderBase_2>;
|
|
368
372
|
|
|
369
|
-
// @
|
|
373
|
+
// @internal
|
|
370
374
|
export const tagCodeArtifacts: <T extends Record<string, TelemetryEventPropertyType | (() => TelemetryBaseEventPropertyType)>>(values: T) => { [P in keyof T]: (T[P] extends () => TelemetryBaseEventPropertyType ? () => {
|
|
371
375
|
value: ReturnType<T[P]>;
|
|
372
376
|
tag: TelemetryDataTag.CodeArtifact;
|
|
@@ -375,7 +379,7 @@ export const tagCodeArtifacts: <T extends Record<string, TelemetryEventPropertyT
|
|
|
375
379
|
tag: TelemetryDataTag.CodeArtifact;
|
|
376
380
|
}) | (T[P] extends undefined ? undefined : never); };
|
|
377
381
|
|
|
378
|
-
// @
|
|
382
|
+
// @internal
|
|
379
383
|
export const tagData: <T extends TelemetryDataTag, V extends Record<string, TelemetryEventPropertyType | (() => TelemetryBaseEventPropertyType)>>(tag: T, values: V) => { [P in keyof V]: (V[P] extends () => TelemetryBaseEventPropertyType ? () => {
|
|
380
384
|
value: ReturnType<V[P]>;
|
|
381
385
|
tag: T;
|
|
@@ -384,32 +388,32 @@ export const tagData: <T extends TelemetryDataTag, V extends Record<string, Tele
|
|
|
384
388
|
tag: T;
|
|
385
389
|
}) | (V[P] extends undefined ? undefined : never); };
|
|
386
390
|
|
|
387
|
-
// @
|
|
391
|
+
// @internal @deprecated (undocumented)
|
|
388
392
|
export class TaggedLoggerAdapter implements ITelemetryBaseLogger {
|
|
389
393
|
constructor(logger: ITelemetryBaseLogger);
|
|
390
394
|
// (undocumented)
|
|
391
395
|
send(eventWithTagsMaybe: ITelemetryBaseEvent): void;
|
|
392
396
|
}
|
|
393
397
|
|
|
394
|
-
// @
|
|
398
|
+
// @internal
|
|
395
399
|
export enum TelemetryDataTag {
|
|
396
400
|
CodeArtifact = "CodeArtifact",
|
|
397
401
|
UserData = "UserData"
|
|
398
402
|
}
|
|
399
403
|
|
|
400
|
-
// @
|
|
404
|
+
// @alpha
|
|
401
405
|
export type TelemetryEventCategory = "generic" | "error" | "performance";
|
|
402
406
|
|
|
403
|
-
// @
|
|
407
|
+
// @alpha
|
|
404
408
|
export type TelemetryEventPropertyTypeExt = string | number | boolean | undefined | (string | number | boolean)[] | {
|
|
405
409
|
[key: string]: // Flat objects can have the same properties as the event itself
|
|
406
410
|
string | number | boolean | undefined | (string | number | boolean)[];
|
|
407
411
|
};
|
|
408
412
|
|
|
409
|
-
// @
|
|
413
|
+
// @internal (undocumented)
|
|
410
414
|
export type TelemetryEventPropertyTypes = ITelemetryBaseProperties[string];
|
|
411
415
|
|
|
412
|
-
// @
|
|
416
|
+
// @internal @deprecated
|
|
413
417
|
export class TelemetryNullLogger implements ITelemetryLoggerExt {
|
|
414
418
|
// (undocumented)
|
|
415
419
|
send(event: ITelemetryBaseEvent): void;
|
|
@@ -421,7 +425,7 @@ export class TelemetryNullLogger implements ITelemetryLoggerExt {
|
|
|
421
425
|
sendTelemetryEvent(event: ITelemetryGenericEvent, error?: unknown): void;
|
|
422
426
|
}
|
|
423
427
|
|
|
424
|
-
// @
|
|
428
|
+
// @internal
|
|
425
429
|
export class ThresholdCounter {
|
|
426
430
|
constructor(threshold: number, logger: ITelemetryLoggerExt, thresholdMultiple?: number);
|
|
427
431
|
send(eventName: string, value: number): void;
|
|
@@ -435,6 +439,9 @@ export class UsageError extends LoggingError implements IUsageError, IFluidError
|
|
|
435
439
|
readonly errorType: "usageError";
|
|
436
440
|
}
|
|
437
441
|
|
|
442
|
+
// @internal
|
|
443
|
+
export function validatePrecondition(condition: boolean, message: string, props?: ITelemetryBaseProperties): asserts condition;
|
|
444
|
+
|
|
438
445
|
// @internal
|
|
439
446
|
export function wrapError<T extends LoggingError>(innerError: unknown, newErrorFn: (message: string) => T): T;
|
|
440
447
|
|
package/dist/config.d.ts
CHANGED
|
@@ -2,19 +2,14 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
|
|
5
|
+
import { ITelemetryBaseLogger, IConfigProviderBase, ConfigTypes } from "@fluidframework/core-interfaces";
|
|
6
6
|
import { Lazy } from "@fluidframework/core-utils";
|
|
7
7
|
import { createChildLogger } from "./logger";
|
|
8
8
|
import { ITelemetryLoggerExt } from "./telemetryTypes";
|
|
9
|
-
export type ConfigTypes = string | number | boolean | number[] | string[] | boolean[] | undefined;
|
|
10
9
|
/**
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
getRawConfig(name: string): ConfigTypes;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Explicitly typed interface for reading configurations
|
|
10
|
+
* Explicitly typed interface for reading configurations.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
18
13
|
*/
|
|
19
14
|
export interface IConfigProvider extends IConfigProviderBase {
|
|
20
15
|
getBoolean(name: string): boolean | undefined;
|
|
@@ -28,6 +23,8 @@ export interface IConfigProvider extends IConfigProviderBase {
|
|
|
28
23
|
* Creates a base configuration provider based on `sessionStorage`
|
|
29
24
|
*
|
|
30
25
|
* @returns A lazy initialized base configuration provider with `sessionStorage` as the underlying config store
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
31
28
|
*/
|
|
32
29
|
export declare const sessionStorageConfigProvider: Lazy<IConfigProviderBase>;
|
|
33
30
|
/**
|
|
@@ -56,14 +53,44 @@ export declare class CachedConfigProvider implements IConfigProvider {
|
|
|
56
53
|
private getCacheEntry;
|
|
57
54
|
}
|
|
58
55
|
/**
|
|
59
|
-
* A type containing both a telemetry logger and a configuration provider
|
|
56
|
+
* A type containing both a telemetry logger and a configuration provider.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
60
59
|
*/
|
|
61
60
|
export interface MonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt> {
|
|
62
61
|
config: IConfigProvider;
|
|
63
62
|
logger: L;
|
|
64
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Determines whether or not the provided object is a {@link MonitoringContext}.
|
|
66
|
+
* @remarks Can be used for type-narrowing.
|
|
67
|
+
*
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
65
70
|
export declare function loggerIsMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(obj: L): obj is L & MonitoringContext<L>;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a {@link MonitoringContext} from the provided logger, if it isn't already one.
|
|
73
|
+
*
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
66
76
|
export declare function loggerToMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(logger: L): MonitoringContext<L>;
|
|
77
|
+
/**
|
|
78
|
+
* Creates a {@link MonitoringContext} from the provided logger.
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* Assumes that the provided logger is not itself already a {@link MonitoringContext}, and will throw an error if it is.
|
|
82
|
+
* If you are unsure, use {@link loggerToMonitoringContext} instead.
|
|
83
|
+
*
|
|
84
|
+
* @throws If the provided logger is already a {@link MonitoringContext}.
|
|
85
|
+
*
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
67
88
|
export declare function mixinMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(logger: L, ...configs: (IConfigProviderBase | undefined)[]): MonitoringContext<L>;
|
|
89
|
+
/**
|
|
90
|
+
* Creates a child logger with a {@link MonitoringContext}.
|
|
91
|
+
*
|
|
92
|
+
* @see {@link loggerToMonitoringContext}
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
68
95
|
export declare function createChildMonitoringContext(props: Parameters<typeof createChildLogger>[0]): MonitoringContext;
|
|
69
96
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACN,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACX,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAoB,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,eAAgB,SAAQ,mBAAmB;IAC3D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;IAC9C,SAAS,CAAC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AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,oBAAoB,GAAG,mBAAmB;IACtF,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,EAAE,CAAC,CAAC;CACV;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,oBAAoB,GAAG,mBAAmB,EAC7F,GAAG,EAAE,CAAC,GACJ,GAAG,IAAI,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAGjC;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,oBAAoB,GAAG,mBAAmB,EAC7F,MAAM,EAAE,CAAC,GACP,iBAAiB,CAAC,CAAC,CAAC,CAKtB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,oBAAoB,GAAG,mBAAmB,EAC1F,MAAM,EAAE,CAAC,EACT,GAAG,OAAO,EAAE,CAAC,mBAAmB,GAAG,SAAS,CAAC,EAAE,GAC7C,iBAAiB,CAAC,CAAC,CAAC,CAgBtB;AAOD;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC3C,KAAK,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAC5C,iBAAiB,CAEnB"}
|
package/dist/config.js
CHANGED
|
@@ -7,6 +7,8 @@ const logger_1 = require("./logger");
|
|
|
7
7
|
* Creates a base configuration provider based on `sessionStorage`
|
|
8
8
|
*
|
|
9
9
|
* @returns A lazy initialized base configuration provider with `sessionStorage` as the underlying config store
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
10
12
|
*/
|
|
11
13
|
exports.sessionStorageConfigProvider = new core_utils_1.Lazy(() => (0, exports.inMemoryConfigProvider)(safeSessionStorage()));
|
|
12
14
|
const NullConfigProvider = {
|
|
@@ -191,11 +193,22 @@ class CachedConfigProvider {
|
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
exports.CachedConfigProvider = CachedConfigProvider;
|
|
196
|
+
/**
|
|
197
|
+
* Determines whether or not the provided object is a {@link MonitoringContext}.
|
|
198
|
+
* @remarks Can be used for type-narrowing.
|
|
199
|
+
*
|
|
200
|
+
* @internal
|
|
201
|
+
*/
|
|
194
202
|
function loggerIsMonitoringContext(obj) {
|
|
195
203
|
const maybeConfig = obj;
|
|
196
204
|
return isConfigProviderBase(maybeConfig?.config) && maybeConfig?.logger !== undefined;
|
|
197
205
|
}
|
|
198
206
|
exports.loggerIsMonitoringContext = loggerIsMonitoringContext;
|
|
207
|
+
/**
|
|
208
|
+
* Creates a {@link MonitoringContext} from the provided logger, if it isn't already one.
|
|
209
|
+
*
|
|
210
|
+
* @internal
|
|
211
|
+
*/
|
|
199
212
|
function loggerToMonitoringContext(logger) {
|
|
200
213
|
if (loggerIsMonitoringContext(logger)) {
|
|
201
214
|
return logger;
|
|
@@ -203,6 +216,17 @@ function loggerToMonitoringContext(logger) {
|
|
|
203
216
|
return mixinMonitoringContext(logger, exports.sessionStorageConfigProvider.value);
|
|
204
217
|
}
|
|
205
218
|
exports.loggerToMonitoringContext = loggerToMonitoringContext;
|
|
219
|
+
/**
|
|
220
|
+
* Creates a {@link MonitoringContext} from the provided logger.
|
|
221
|
+
*
|
|
222
|
+
* @remarks
|
|
223
|
+
* Assumes that the provided logger is not itself already a {@link MonitoringContext}, and will throw an error if it is.
|
|
224
|
+
* If you are unsure, use {@link loggerToMonitoringContext} instead.
|
|
225
|
+
*
|
|
226
|
+
* @throws If the provided logger is already a {@link MonitoringContext}.
|
|
227
|
+
*
|
|
228
|
+
* @internal
|
|
229
|
+
*/
|
|
206
230
|
function mixinMonitoringContext(logger, ...configs) {
|
|
207
231
|
if (loggerIsMonitoringContext(logger)) {
|
|
208
232
|
throw new Error("Logger is already a monitoring context");
|
|
@@ -225,6 +249,12 @@ function isConfigProviderBase(obj) {
|
|
|
225
249
|
const maybeConfig = obj;
|
|
226
250
|
return typeof maybeConfig?.getRawConfig === "function";
|
|
227
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Creates a child logger with a {@link MonitoringContext}.
|
|
254
|
+
*
|
|
255
|
+
* @see {@link loggerToMonitoringContext}
|
|
256
|
+
* @internal
|
|
257
|
+
*/
|
|
228
258
|
function createChildMonitoringContext(props) {
|
|
229
259
|
return loggerToMonitoringContext((0, logger_1.createChildLogger)(props));
|
|
230
260
|
}
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAKA,2DAAkD;AAClD,qCAA+D;AAuB/D;;;;GAIG;AACU,QAAA,4BAA4B,GAAG,IAAI,iBAAI,CAAsB,GAAG,EAAE,CAC9E,IAAA,8BAAsB,EAAC,kBAAkB,EAAE,CAAC,CAC5C,CAAC;AAEF,MAAM,kBAAkB,GAAwB;IAC/C,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS;CAC7B,CAAC;AAEF;;;;;;GAMG;AACI,MAAM,sBAAsB,GAAG,CAAC,OAA4B,EAAuB,EAAE;IAC3F,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE;QAC9C,OAAO,IAAI,oBAAoB,CAAC,SAAS,EAAE;YAC1C,YAAY,EAAE,CAAC,IAAY,EAA2B,EAAE;gBACvD,IAAI;oBACH,OAAO,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,EAAE,GAAG,CAAC;iBACnE;gBAAC,MAAM;oBACP,OAAO,SAAS,CAAC;iBACjB;YACF,CAAC;SACD,CAAC,CAAC;KACH;IACD,OAAO,kBAAkB,CAAC;AAC3B,CAAC,CAAC;AAbW,QAAA,sBAAsB,0BAajC;AAaF,SAAS,eAAe,CAAC,IAAY;IACpC,QAAQ,IAAI,EAAE;QACb,KAAK,SAAS,CAAC;QACf,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ,CAAC,CAAC;YACd,OAAO,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K,UAAU,CAAC;AACxD,CAAC;AAED,SAAgB,4BAA4B,CAC3C,KAA8C;IAE9C,OAAO,yBAAyB,CAAC,IAAA,0BAAiB,EAAC,KAAK,CAAC,CAAC,CAAC;AAC5D,CAAC;AAJD,oEAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { Lazy } from \"@fluidframework/core-utils\";\nimport { createChildLogger, tagCodeArtifacts } from \"./logger\";\nimport { ITelemetryLoggerExt } from \"./telemetryTypes\";\n\nexport type ConfigTypes = string | number | boolean | number[] | string[] | boolean[] | undefined;\n\n/**\n * Base interface for providing configurations to enable/disable/control features\n */\nexport interface IConfigProviderBase {\n\tgetRawConfig(name: string): ConfigTypes;\n}\n\n/**\n * Explicitly typed interface for reading configurations\n */\nexport interface IConfigProvider extends IConfigProviderBase {\n\tgetBoolean(name: string): boolean | undefined;\n\tgetNumber(name: string): number | undefined;\n\tgetString(name: string): string | undefined;\n\tgetBooleanArray(name: string): boolean[] | undefined;\n\tgetNumberArray(name: string): number[] | undefined;\n\tgetStringArray(name: string): string[] | undefined;\n}\n/**\n * Creates a base configuration provider based on `sessionStorage`\n *\n * @returns A lazy initialized base configuration provider with `sessionStorage` as the underlying config store\n */\nexport const sessionStorageConfigProvider = new Lazy<IConfigProviderBase>(() =>\n\tinMemoryConfigProvider(safeSessionStorage()),\n);\n\nconst NullConfigProvider: IConfigProviderBase = {\n\tgetRawConfig: () => undefined,\n};\n\n/**\n * Creates a base configuration provider based on the supplied `Storage` instance\n *\n * @param storage - instance of `Storage` to be used as storage media for the config\n * @returns A base configuration provider with\n * the supplied `Storage` instance as the underlying config store\n */\nexport const inMemoryConfigProvider = (storage: Storage | undefined): IConfigProviderBase => {\n\tif (storage !== undefined && storage !== null) {\n\t\treturn new CachedConfigProvider(undefined, {\n\t\t\tgetRawConfig: (name: string): ConfigTypes | undefined => {\n\t\t\t\ttry {\n\t\t\t\t\treturn stronglyTypedParse(storage.getItem(name) ?? undefined)?.raw;\n\t\t\t\t} catch {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t}\n\treturn NullConfigProvider;\n};\n\ninterface ConfigTypeStringToType {\n\tnumber: number;\n\tstring: string;\n\tboolean: boolean;\n\t[\"number[]\"]: number[];\n\t[\"string[]\"]: string[];\n\t[\"boolean[]\"]: boolean[];\n}\n\ntype PrimitiveTypeStrings = \"number\" | \"string\" | \"boolean\";\n\nfunction isPrimitiveType(type: string): type is PrimitiveTypeStrings {\n\tswitch (type) {\n\t\tcase \"boolean\":\n\t\tcase \"number\":\n\t\tcase \"string\": {\n\t\t\treturn true;\n\t\t}\n\t\tdefault: {\n\t\t\treturn false;\n\t\t}\n\t}\n}\n\ninterface StronglyTypedValue extends Partial<ConfigTypeStringToType> {\n\traw: ConfigTypes;\n}\n/**\n * Takes any supported config type, and returns the value with a strong type. If the type of\n * the config is not a supported type undefined will be returned.\n * The user of this function should cache the result to avoid duplicated work.\n *\n * Strings will be attempted to be parsed and coerced into a strong config type.\n * if it is not possible to parsed and coerce a string to a strong config type the original string\n * will be return with a string type for the consumer to handle further if necessary.\n */\nfunction stronglyTypedParse(input: ConfigTypes): StronglyTypedValue | undefined {\n\tlet output: ConfigTypes = input;\n\tlet defaultReturn: Pick<StronglyTypedValue, \"raw\" | \"string\"> | undefined;\n\t// we do special handling for strings to try and coerce\n\t// them into a config type if we can. This makes it easy\n\t// for config sources like sessionStorage which only\n\t// holds strings\n\tif (typeof input === \"string\") {\n\t\ttry {\n\t\t\toutput = JSON.parse(input) as ConfigTypes;\n\t\t\t// we succeeded in parsing, but we don't support parsing\n\t\t\t// for any object as we can't do it type safely\n\t\t\t// so in this case, the default return will be string\n\t\t\t// rather than undefined, and the consumer\n\t\t\t// can parse, as we don't want to provide\n\t\t\t// a false sense of security by just\n\t\t\t// casting.\n\t\t\tdefaultReturn = { raw: input, string: input };\n\t\t} catch {\n\t\t\t// No-op\n\t\t}\n\t}\n\n\tif (output === undefined) {\n\t\treturn defaultReturn;\n\t}\n\n\tconst outputType = typeof output;\n\tif (isPrimitiveType(outputType)) {\n\t\treturn { ...defaultReturn, raw: input, [outputType]: output };\n\t}\n\n\tif (Array.isArray(output)) {\n\t\tconst firstType = typeof output[0];\n\t\t// ensure the first elements is a primitive type\n\t\tif (!isPrimitiveType(firstType)) {\n\t\t\treturn defaultReturn;\n\t\t}\n\t\t// ensue all the elements types are homogeneous\n\t\t// aka they all have the same type as the first\n\t\tfor (const v of output) {\n\t\t\tif (typeof v !== firstType) {\n\t\t\t\treturn defaultReturn;\n\t\t\t}\n\t\t}\n\t\treturn { ...defaultReturn, raw: input, [`${firstType}[]`]: output };\n\t}\n\n\treturn defaultReturn;\n}\n\n/**\n * `sessionStorage` is undefined in some environments such as Node and web pages with session storage disabled.\n */\nconst safeSessionStorage = (): Storage | undefined => {\n\t// For some configurations accessing \"globalThis.sessionStorage\" throws\n\t// \"'sessionStorage' property from 'Window': Access is denied for this document\" rather than returning undefined.\n\t// Therefor check for it before accessing.\n\ttry {\n\t\t// Using globalThis and checking for undefined is preferred over just accessing global sessionStorage\n\t\t// since it avoids an exception when running in node.\n\t\t// In some cases this has returned null when disabled in the browser, so ensure its undefined in that case:\n\t\treturn globalThis.sessionStorage ?? undefined;\n\t} catch {\n\t\t// For browsers which error on the above when session storage is disabled:\n\t\treturn undefined;\n\t}\n};\n\n/**\n * Implementation of {@link IConfigProvider} which contains nested {@link IConfigProviderBase} instances\n */\nexport class CachedConfigProvider implements IConfigProvider {\n\tprivate readonly configCache = new Map<string, StronglyTypedValue>();\n\tprivate readonly orderedBaseProviders: (IConfigProviderBase | undefined)[];\n\n\tconstructor(\n\t\tprivate readonly logger?: ITelemetryBaseLogger,\n\t\t...orderedBaseProviders: (IConfigProviderBase | undefined)[]\n\t) {\n\t\tthis.orderedBaseProviders = [];\n\t\tconst knownProviders = new Set<IConfigProviderBase>();\n\t\tconst candidateProviders = [...orderedBaseProviders];\n\t\twhile (candidateProviders.length > 0) {\n\t\t\tconst baseProvider = candidateProviders.shift()!;\n\t\t\tif (\n\t\t\t\tbaseProvider !== undefined &&\n\t\t\t\tisConfigProviderBase(baseProvider) &&\n\t\t\t\t!knownProviders.has(baseProvider)\n\t\t\t) {\n\t\t\t\tknownProviders.add(baseProvider);\n\t\t\t\tif (baseProvider instanceof CachedConfigProvider) {\n\t\t\t\t\tcandidateProviders.push(...baseProvider.orderedBaseProviders);\n\t\t\t\t} else {\n\t\t\t\t\tthis.orderedBaseProviders.push(baseProvider);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tgetBoolean(name: string): boolean | undefined {\n\t\treturn this.getCacheEntry(name)?.boolean;\n\t}\n\tgetNumber(name: string): number | undefined {\n\t\treturn this.getCacheEntry(name)?.number;\n\t}\n\tgetString(name: string): string | undefined {\n\t\treturn this.getCacheEntry(name)?.string;\n\t}\n\tgetBooleanArray(name: string): boolean[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"boolean[]\"];\n\t}\n\tgetNumberArray(name: string): number[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"number[]\"];\n\t}\n\tgetStringArray(name: string): string[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"string[]\"];\n\t}\n\n\tgetRawConfig(name: string): ConfigTypes {\n\t\treturn this.getCacheEntry(name)?.raw;\n\t}\n\n\tprivate getCacheEntry(name: string): StronglyTypedValue | undefined {\n\t\tif (!this.configCache.has(name)) {\n\t\t\tfor (const provider of this.orderedBaseProviders) {\n\t\t\t\tconst parsed = stronglyTypedParse(provider?.getRawConfig(name));\n\t\t\t\tif (parsed !== undefined) {\n\t\t\t\t\tthis.configCache.set(name, parsed);\n\t\t\t\t\tthis.logger?.send({\n\t\t\t\t\t\tcategory: \"generic\",\n\t\t\t\t\t\teventName: \"ConfigRead\",\n\t\t\t\t\t\t...tagCodeArtifacts({\n\t\t\t\t\t\t\tconfigName: name,\n\t\t\t\t\t\t\tconfigValue: JSON.stringify(parsed),\n\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\t\t\t\t\treturn parsed;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// configs are immutable, if the first lookup returned no results, all lookups should\n\t\t\tthis.configCache.set(name, { raw: undefined });\n\t\t}\n\t\treturn this.configCache.get(name);\n\t}\n}\n\n/**\n * A type containing both a telemetry logger and a configuration provider\n */\nexport interface MonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt> {\n\tconfig: IConfigProvider;\n\tlogger: L;\n}\n\nexport function loggerIsMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tobj: L,\n): obj is L & MonitoringContext<L> {\n\tconst maybeConfig = obj as Partial<MonitoringContext<L>> | undefined;\n\treturn isConfigProviderBase(maybeConfig?.config) && maybeConfig?.logger !== undefined;\n}\n\nexport function loggerToMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tlogger: L,\n): MonitoringContext<L> {\n\tif (loggerIsMonitoringContext<L>(logger)) {\n\t\treturn logger;\n\t}\n\treturn mixinMonitoringContext<L>(logger, sessionStorageConfigProvider.value);\n}\n\nexport function mixinMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tlogger: L,\n\t...configs: (IConfigProviderBase | undefined)[]\n): MonitoringContext<L> {\n\tif (loggerIsMonitoringContext<L>(logger)) {\n\t\tthrow new Error(\"Logger is already a monitoring context\");\n\t}\n\t/**\n\t * this is the tricky bit we use for now to smuggle monitoring context around.\n\t * To the logger we mixin both config and itself, so mc.logger === logger as it is self-referential.\n\t * We then expose it as a Monitoring context, so via types we hide the outer logger methods.\n\t * To layers that expect just a logger we can pass mc.logger, but this is still a MonitoringContext\n\t * so if a deeper layer then converts that logger to a monitoring context it can find the smuggled properties\n\t * of the MonitoringContext and get the config provider.\n\t */\n\tconst mc: L & Partial<MonitoringContext<L>> = logger;\n\tmc.config = new CachedConfigProvider(logger, ...configs);\n\tmc.logger = logger;\n\treturn mc as MonitoringContext<L>;\n}\n\nfunction isConfigProviderBase(obj: unknown): obj is IConfigProviderBase {\n\tconst maybeConfig = obj as Partial<IConfigProviderBase> | undefined;\n\treturn typeof maybeConfig?.getRawConfig === \"function\";\n}\n\nexport function createChildMonitoringContext(\n\tprops: Parameters<typeof createChildLogger>[0],\n): MonitoringContext {\n\treturn loggerToMonitoringContext(createChildLogger(props));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AASA,2DAAkD;AAClD,qCAA+D;AAgB/D;;;;;;GAMG;AACU,QAAA,4BAA4B,GAAG,IAAI,iBAAI,CAAsB,GAAG,EAAE,CAC9E,IAAA,8BAAsB,EAAC,kBAAkB,EAAE,CAAC,CAC5C,CAAC;AAEF,MAAM,kBAAkB,GAAwB;IAC/C,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS;CAC7B,CAAC;AAEF;;;;;;GAMG;AACI,MAAM,sBAAsB,GAAG,CAAC,OAA4B,EAAuB,EAAE;IAC3F,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE;QAC9C,OAAO,IAAI,oBAAoB,CAAC,SAAS,EAAE;YAC1C,YAAY,EAAE,CAAC,IAAY,EAA2B,EAAE;gBACvD,IAAI;oBACH,OAAO,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,EAAE,GAAG,CAAC;iBACnE;gBAAC,MAAM;oBACP,OAAO,SAAS,CAAC;iBACjB;YACF,CAAC;SACD,CAAC,CAAC;KACH;IACD,OAAO,kBAAkB,CAAC;AAC3B,CAAC,CAAC;AAbW,QAAA,sBAAsB,0BAajC;AAaF,SAAS,eAAe,CAAC,IAAY;IACpC,QAAQ,IAAI,EAAE;QACb,KAAK,SAAS,CAAC;QACf,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ,CAAC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AAM,WAAW,GAAG,GAA+C,CAAC;IACpE,OAAO,OAAO,WAAW,EAAE,YAAY,KAAK,UAAU,CAAC;AACxD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,4BAA4B,CAC3C,KAA8C;IAE9C,OAAO,yBAAyB,CAAC,IAAA,0BAAiB,EAAC,KAAK,CAAC,CAAC,CAAC;AAC5D,CAAC;AAJD,oEAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport {\n\tITelemetryBaseLogger,\n\tIConfigProviderBase,\n\tConfigTypes,\n} from \"@fluidframework/core-interfaces\";\nimport { Lazy } from \"@fluidframework/core-utils\";\nimport { createChildLogger, tagCodeArtifacts } from \"./logger\";\nimport { ITelemetryLoggerExt } from \"./telemetryTypes\";\n\n/**\n * Explicitly typed interface for reading configurations.\n *\n * @internal\n */\nexport interface IConfigProvider extends IConfigProviderBase {\n\tgetBoolean(name: string): boolean | undefined;\n\tgetNumber(name: string): number | undefined;\n\tgetString(name: string): string | undefined;\n\tgetBooleanArray(name: string): boolean[] | undefined;\n\tgetNumberArray(name: string): number[] | undefined;\n\tgetStringArray(name: string): string[] | undefined;\n}\n/**\n * Creates a base configuration provider based on `sessionStorage`\n *\n * @returns A lazy initialized base configuration provider with `sessionStorage` as the underlying config store\n *\n * @internal\n */\nexport const sessionStorageConfigProvider = new Lazy<IConfigProviderBase>(() =>\n\tinMemoryConfigProvider(safeSessionStorage()),\n);\n\nconst NullConfigProvider: IConfigProviderBase = {\n\tgetRawConfig: () => undefined,\n};\n\n/**\n * Creates a base configuration provider based on the supplied `Storage` instance\n *\n * @param storage - instance of `Storage` to be used as storage media for the config\n * @returns A base configuration provider with\n * the supplied `Storage` instance as the underlying config store\n */\nexport const inMemoryConfigProvider = (storage: Storage | undefined): IConfigProviderBase => {\n\tif (storage !== undefined && storage !== null) {\n\t\treturn new CachedConfigProvider(undefined, {\n\t\t\tgetRawConfig: (name: string): ConfigTypes | undefined => {\n\t\t\t\ttry {\n\t\t\t\t\treturn stronglyTypedParse(storage.getItem(name) ?? undefined)?.raw;\n\t\t\t\t} catch {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t}\n\treturn NullConfigProvider;\n};\n\ninterface ConfigTypeStringToType {\n\tnumber: number;\n\tstring: string;\n\tboolean: boolean;\n\t[\"number[]\"]: number[];\n\t[\"string[]\"]: string[];\n\t[\"boolean[]\"]: boolean[];\n}\n\ntype PrimitiveTypeStrings = \"number\" | \"string\" | \"boolean\";\n\nfunction isPrimitiveType(type: string): type is PrimitiveTypeStrings {\n\tswitch (type) {\n\t\tcase \"boolean\":\n\t\tcase \"number\":\n\t\tcase \"string\": {\n\t\t\treturn true;\n\t\t}\n\t\tdefault: {\n\t\t\treturn false;\n\t\t}\n\t}\n}\n\ninterface StronglyTypedValue extends Partial<ConfigTypeStringToType> {\n\traw: ConfigTypes;\n}\n/**\n * Takes any supported config type, and returns the value with a strong type. If the type of\n * the config is not a supported type undefined will be returned.\n * The user of this function should cache the result to avoid duplicated work.\n *\n * Strings will be attempted to be parsed and coerced into a strong config type.\n * if it is not possible to parsed and coerce a string to a strong config type the original string\n * will be return with a string type for the consumer to handle further if necessary.\n */\nfunction stronglyTypedParse(input: ConfigTypes): StronglyTypedValue | undefined {\n\tlet output: ConfigTypes = input;\n\tlet defaultReturn: Pick<StronglyTypedValue, \"raw\" | \"string\"> | undefined;\n\t// we do special handling for strings to try and coerce\n\t// them into a config type if we can. This makes it easy\n\t// for config sources like sessionStorage which only\n\t// holds strings\n\tif (typeof input === \"string\") {\n\t\ttry {\n\t\t\toutput = JSON.parse(input) as ConfigTypes;\n\t\t\t// we succeeded in parsing, but we don't support parsing\n\t\t\t// for any object as we can't do it type safely\n\t\t\t// so in this case, the default return will be string\n\t\t\t// rather than undefined, and the consumer\n\t\t\t// can parse, as we don't want to provide\n\t\t\t// a false sense of security by just\n\t\t\t// casting.\n\t\t\tdefaultReturn = { raw: input, string: input };\n\t\t} catch {\n\t\t\t// No-op\n\t\t}\n\t}\n\n\tif (output === undefined) {\n\t\treturn defaultReturn;\n\t}\n\n\tconst outputType = typeof output;\n\tif (isPrimitiveType(outputType)) {\n\t\treturn { ...defaultReturn, raw: input, [outputType]: output };\n\t}\n\n\tif (Array.isArray(output)) {\n\t\tconst firstType = typeof output[0];\n\t\t// ensure the first elements is a primitive type\n\t\tif (!isPrimitiveType(firstType)) {\n\t\t\treturn defaultReturn;\n\t\t}\n\t\t// ensue all the elements types are homogeneous\n\t\t// aka they all have the same type as the first\n\t\tfor (const v of output) {\n\t\t\tif (typeof v !== firstType) {\n\t\t\t\treturn defaultReturn;\n\t\t\t}\n\t\t}\n\t\treturn { ...defaultReturn, raw: input, [`${firstType}[]`]: output };\n\t}\n\n\treturn defaultReturn;\n}\n\n/**\n * `sessionStorage` is undefined in some environments such as Node and web pages with session storage disabled.\n */\nconst safeSessionStorage = (): Storage | undefined => {\n\t// For some configurations accessing \"globalThis.sessionStorage\" throws\n\t// \"'sessionStorage' property from 'Window': Access is denied for this document\" rather than returning undefined.\n\t// Therefor check for it before accessing.\n\ttry {\n\t\t// Using globalThis and checking for undefined is preferred over just accessing global sessionStorage\n\t\t// since it avoids an exception when running in node.\n\t\t// In some cases this has returned null when disabled in the browser, so ensure its undefined in that case:\n\t\treturn globalThis.sessionStorage ?? undefined;\n\t} catch {\n\t\t// For browsers which error on the above when session storage is disabled:\n\t\treturn undefined;\n\t}\n};\n\n/**\n * Implementation of {@link IConfigProvider} which contains nested {@link IConfigProviderBase} instances\n */\nexport class CachedConfigProvider implements IConfigProvider {\n\tprivate readonly configCache = new Map<string, StronglyTypedValue>();\n\tprivate readonly orderedBaseProviders: (IConfigProviderBase | undefined)[];\n\n\tconstructor(\n\t\tprivate readonly logger?: ITelemetryBaseLogger,\n\t\t...orderedBaseProviders: (IConfigProviderBase | undefined)[]\n\t) {\n\t\tthis.orderedBaseProviders = [];\n\t\tconst knownProviders = new Set<IConfigProviderBase>();\n\t\tconst candidateProviders = [...orderedBaseProviders];\n\t\twhile (candidateProviders.length > 0) {\n\t\t\tconst baseProvider = candidateProviders.shift()!;\n\t\t\tif (\n\t\t\t\tbaseProvider !== undefined &&\n\t\t\t\tisConfigProviderBase(baseProvider) &&\n\t\t\t\t!knownProviders.has(baseProvider)\n\t\t\t) {\n\t\t\t\tknownProviders.add(baseProvider);\n\t\t\t\tif (baseProvider instanceof CachedConfigProvider) {\n\t\t\t\t\tcandidateProviders.push(...baseProvider.orderedBaseProviders);\n\t\t\t\t} else {\n\t\t\t\t\tthis.orderedBaseProviders.push(baseProvider);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tgetBoolean(name: string): boolean | undefined {\n\t\treturn this.getCacheEntry(name)?.boolean;\n\t}\n\tgetNumber(name: string): number | undefined {\n\t\treturn this.getCacheEntry(name)?.number;\n\t}\n\tgetString(name: string): string | undefined {\n\t\treturn this.getCacheEntry(name)?.string;\n\t}\n\tgetBooleanArray(name: string): boolean[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"boolean[]\"];\n\t}\n\tgetNumberArray(name: string): number[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"number[]\"];\n\t}\n\tgetStringArray(name: string): string[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"string[]\"];\n\t}\n\n\tgetRawConfig(name: string): ConfigTypes {\n\t\treturn this.getCacheEntry(name)?.raw;\n\t}\n\n\tprivate getCacheEntry(name: string): StronglyTypedValue | undefined {\n\t\tif (!this.configCache.has(name)) {\n\t\t\tfor (const provider of this.orderedBaseProviders) {\n\t\t\t\tconst parsed = stronglyTypedParse(provider?.getRawConfig(name));\n\t\t\t\tif (parsed !== undefined) {\n\t\t\t\t\tthis.configCache.set(name, parsed);\n\t\t\t\t\tthis.logger?.send({\n\t\t\t\t\t\tcategory: \"generic\",\n\t\t\t\t\t\teventName: \"ConfigRead\",\n\t\t\t\t\t\t...tagCodeArtifacts({\n\t\t\t\t\t\t\tconfigName: name,\n\t\t\t\t\t\t\tconfigValue: JSON.stringify(parsed),\n\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\t\t\t\t\treturn parsed;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// configs are immutable, if the first lookup returned no results, all lookups should\n\t\t\tthis.configCache.set(name, { raw: undefined });\n\t\t}\n\t\treturn this.configCache.get(name);\n\t}\n}\n\n/**\n * A type containing both a telemetry logger and a configuration provider.\n *\n * @internal\n */\nexport interface MonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt> {\n\tconfig: IConfigProvider;\n\tlogger: L;\n}\n\n/**\n * Determines whether or not the provided object is a {@link MonitoringContext}.\n * @remarks Can be used for type-narrowing.\n *\n * @internal\n */\nexport function loggerIsMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tobj: L,\n): obj is L & MonitoringContext<L> {\n\tconst maybeConfig = obj as Partial<MonitoringContext<L>> | undefined;\n\treturn isConfigProviderBase(maybeConfig?.config) && maybeConfig?.logger !== undefined;\n}\n\n/**\n * Creates a {@link MonitoringContext} from the provided logger, if it isn't already one.\n *\n * @internal\n */\nexport function loggerToMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tlogger: L,\n): MonitoringContext<L> {\n\tif (loggerIsMonitoringContext<L>(logger)) {\n\t\treturn logger;\n\t}\n\treturn mixinMonitoringContext<L>(logger, sessionStorageConfigProvider.value);\n}\n\n/**\n * Creates a {@link MonitoringContext} from the provided logger.\n *\n * @remarks\n * Assumes that the provided logger is not itself already a {@link MonitoringContext}, and will throw an error if it is.\n * If you are unsure, use {@link loggerToMonitoringContext} instead.\n *\n * @throws If the provided logger is already a {@link MonitoringContext}.\n *\n * @internal\n */\nexport function mixinMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tlogger: L,\n\t...configs: (IConfigProviderBase | undefined)[]\n): MonitoringContext<L> {\n\tif (loggerIsMonitoringContext<L>(logger)) {\n\t\tthrow new Error(\"Logger is already a monitoring context\");\n\t}\n\t/**\n\t * this is the tricky bit we use for now to smuggle monitoring context around.\n\t * To the logger we mixin both config and itself, so mc.logger === logger as it is self-referential.\n\t * We then expose it as a Monitoring context, so via types we hide the outer logger methods.\n\t * To layers that expect just a logger we can pass mc.logger, but this is still a MonitoringContext\n\t * so if a deeper layer then converts that logger to a monitoring context it can find the smuggled properties\n\t * of the MonitoringContext and get the config provider.\n\t */\n\tconst mc: L & Partial<MonitoringContext<L>> = logger;\n\tmc.config = new CachedConfigProvider(logger, ...configs);\n\tmc.logger = logger;\n\treturn mc as MonitoringContext<L>;\n}\n\nfunction isConfigProviderBase(obj: unknown): obj is IConfigProviderBase {\n\tconst maybeConfig = obj as Partial<IConfigProviderBase> | undefined;\n\treturn typeof maybeConfig?.getRawConfig === \"function\";\n}\n\n/**\n * Creates a child logger with a {@link MonitoringContext}.\n *\n * @see {@link loggerToMonitoringContext}\n * @internal\n */\nexport function createChildMonitoringContext(\n\tprops: Parameters<typeof createChildLogger>[0],\n): MonitoringContext {\n\treturn loggerToMonitoringContext(createChildLogger(props));\n}\n"]}
|