@fluidframework/fluid-telemetry 2.0.0-dev-rc.3.0.0.253463
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/.eslintrc.cjs +11 -0
- package/.mocharc.cjs +12 -0
- package/LICENSE +21 -0
- package/README.md +118 -0
- package/api-extractor-cjs.json +30 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +26 -0
- package/api-report/external-telemetry.api.md +68 -0
- package/api-report/fluid-telemetry.api.md +68 -0
- package/dist/app-insights/appInsightsTelemetryConsumer.d.ts +16 -0
- package/dist/app-insights/appInsightsTelemetryConsumer.d.ts.map +1 -0
- package/dist/app-insights/appInsightsTelemetryConsumer.js +24 -0
- package/dist/app-insights/appInsightsTelemetryConsumer.js.map +1 -0
- package/dist/app-insights/index.d.ts +6 -0
- package/dist/app-insights/index.d.ts.map +1 -0
- package/dist/app-insights/index.js +10 -0
- package/dist/app-insights/index.js.map +1 -0
- package/dist/common/consumers/index.d.ts +35 -0
- package/dist/common/consumers/index.d.ts.map +1 -0
- package/dist/common/consumers/index.js +7 -0
- package/dist/common/consumers/index.js.map +1 -0
- package/dist/common/index.d.ts +7 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +7 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/telemetry/index.d.ts +31 -0
- package/dist/common/telemetry/index.d.ts.map +1 -0
- package/dist/common/telemetry/index.js +7 -0
- package/dist/common/telemetry/index.js.map +1 -0
- package/dist/container/containerSystemEvents.d.ts +21 -0
- package/dist/container/containerSystemEvents.d.ts.map +1 -0
- package/dist/container/containerSystemEvents.js +20 -0
- package/dist/container/containerSystemEvents.js.map +1 -0
- package/dist/container/containerTelemetry.d.ts +118 -0
- package/dist/container/containerTelemetry.d.ts.map +1 -0
- package/dist/container/containerTelemetry.js +36 -0
- package/dist/container/containerTelemetry.js.map +1 -0
- package/dist/container/index.d.ts +9 -0
- package/dist/container/index.d.ts.map +1 -0
- package/dist/container/index.js +16 -0
- package/dist/container/index.js.map +1 -0
- package/dist/container/telemetryManager.d.ts +34 -0
- package/dist/container/telemetryManager.d.ts.map +1 -0
- package/dist/container/telemetryManager.js +62 -0
- package/dist/container/telemetryManager.js.map +1 -0
- package/dist/container/telemetryProducer.d.ts +25 -0
- package/dist/container/telemetryProducer.d.ts.map +1 -0
- package/dist/container/telemetryProducer.js +68 -0
- package/dist/container/telemetryProducer.js.map +1 -0
- package/dist/factory/index.d.ts +36 -0
- package/dist/factory/index.d.ts.map +1 -0
- package/dist/factory/index.js +20 -0
- package/dist/factory/index.js.map +1 -0
- package/dist/fluid-telemetry-alpha.d.ts +213 -0
- package/dist/fluid-telemetry-beta.d.ts +213 -0
- package/dist/fluid-telemetry-public.d.ts +32 -0
- package/dist/fluid-telemetry-untrimmed.d.ts +213 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/package.json +3 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/app-insights/appInsightsTelemetryConsumer.d.ts +16 -0
- package/lib/app-insights/appInsightsTelemetryConsumer.d.ts.map +1 -0
- package/lib/app-insights/appInsightsTelemetryConsumer.js +20 -0
- package/lib/app-insights/appInsightsTelemetryConsumer.js.map +1 -0
- package/lib/app-insights/index.d.ts +6 -0
- package/lib/app-insights/index.d.ts.map +1 -0
- package/lib/app-insights/index.js +6 -0
- package/lib/app-insights/index.js.map +1 -0
- package/lib/common/consumers/index.d.ts +35 -0
- package/lib/common/consumers/index.d.ts.map +1 -0
- package/lib/common/consumers/index.js +6 -0
- package/lib/common/consumers/index.js.map +1 -0
- package/lib/common/index.d.ts +7 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +6 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/telemetry/index.d.ts +31 -0
- package/lib/common/telemetry/index.d.ts.map +1 -0
- package/lib/common/telemetry/index.js +6 -0
- package/lib/common/telemetry/index.js.map +1 -0
- package/lib/container/containerSystemEvents.d.ts +21 -0
- package/lib/container/containerSystemEvents.d.ts.map +1 -0
- package/lib/container/containerSystemEvents.js +17 -0
- package/lib/container/containerSystemEvents.js.map +1 -0
- package/lib/container/containerTelemetry.d.ts +118 -0
- package/lib/container/containerTelemetry.d.ts.map +1 -0
- package/lib/container/containerTelemetry.js +33 -0
- package/lib/container/containerTelemetry.js.map +1 -0
- package/lib/container/index.d.ts +9 -0
- package/lib/container/index.d.ts.map +1 -0
- package/lib/container/index.js +9 -0
- package/lib/container/index.js.map +1 -0
- package/lib/container/telemetryManager.d.ts +34 -0
- package/lib/container/telemetryManager.d.ts.map +1 -0
- package/lib/container/telemetryManager.js +58 -0
- package/lib/container/telemetryManager.js.map +1 -0
- package/lib/container/telemetryProducer.d.ts +25 -0
- package/lib/container/telemetryProducer.d.ts.map +1 -0
- package/lib/container/telemetryProducer.js +64 -0
- package/lib/container/telemetryProducer.js.map +1 -0
- package/lib/factory/index.d.ts +36 -0
- package/lib/factory/index.d.ts.map +1 -0
- package/lib/factory/index.js +16 -0
- package/lib/factory/index.js.map +1 -0
- package/lib/fluid-telemetry-alpha.d.ts +213 -0
- package/lib/fluid-telemetry-beta.d.ts +213 -0
- package/lib/fluid-telemetry-public.d.ts +32 -0
- package/lib/fluid-telemetry-untrimmed.d.ts +213 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -0
- package/lib/test/containerTelemetry.spec.d.ts +2 -0
- package/lib/test/containerTelemetry.spec.d.ts.map +1 -0
- package/lib/test/containerTelemetry.spec.js +138 -0
- package/lib/test/containerTelemetry.spec.js.map +1 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/package.json +145 -0
- package/src/app-insights/appInsightsTelemetryConsumer.ts +22 -0
- package/src/app-insights/index.ts +6 -0
- package/src/common/consumers/index.ts +36 -0
- package/src/common/index.ts +7 -0
- package/src/common/telemetry/index.ts +33 -0
- package/src/container/containerSystemEvents.ts +23 -0
- package/src/container/containerTelemetry.ts +126 -0
- package/src/container/index.ts +22 -0
- package/src/container/telemetryManager.ts +85 -0
- package/src/container/telemetryProducer.ts +87 -0
- package/src/factory/index.ts +42 -0
- package/src/index.ts +24 -0
- package/tsconfig.cjs.json +8 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This package provides an implementation and types for producing and consuming telemetry for Fluid Framework applications
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ICriticalContainerError } from '@fluidframework/container-definitions';
|
|
7
|
+
import type { IFluidContainer } from '@fluidframework/fluid-static';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The container "connected" telemetry event.
|
|
11
|
+
* It is produced from an internal Fluid container system event {@link @fluidframework/container-definitions#IContainerEvents} which is emitted when the {@link @fluidframework/container-definitions#IContainer} completes connecting to the Fluid service.
|
|
12
|
+
*
|
|
13
|
+
* @see More details about {@link @fluidframework/container-definitions#IContainer.connectionState | the containers connection state}
|
|
14
|
+
* @see More details about {@link @fluidframework/container-definitions#IContainer.connect | the function to connect a container }
|
|
15
|
+
* @see More details about {@link @fluidframework/container-definitions#IContainer.connectionState | the containers connection state}
|
|
16
|
+
*
|
|
17
|
+
* @beta
|
|
18
|
+
*/
|
|
19
|
+
export declare interface ContainerConnectedTelemetry extends IContainerTelemetry {
|
|
20
|
+
/**
|
|
21
|
+
* {@inheritDoc IFluidTelemetry.eventName}
|
|
22
|
+
*/
|
|
23
|
+
eventName: "fluidframework.container.connected";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The container "disconnected" telemetry event. This telemetry is produced from an internal Fluid container system event
|
|
28
|
+
* {@link @fluidframework/container-definitions#IContainerEvents} which is emitted when the {@link @fluidframework/container-definitions#IContainer}
|
|
29
|
+
* becomes disconnected from the Fluid service.
|
|
30
|
+
*
|
|
31
|
+
* @see More details about{@link @fluidframework/container-definitions#IContainer.connectionState | the containers connection state}
|
|
32
|
+
*
|
|
33
|
+
* @see More details about{@link @fluidframework/container-definitions#IContainer.disconnect | the function to disconnect a container}
|
|
34
|
+
*
|
|
35
|
+
* @beta
|
|
36
|
+
*/
|
|
37
|
+
export declare interface ContainerDisconnectedTelemetry extends IContainerTelemetry {
|
|
38
|
+
/**
|
|
39
|
+
* {@inheritDoc IFluidTelemetry.eventName}
|
|
40
|
+
*/
|
|
41
|
+
eventName: "fluidframework.container.disconnected";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* The Fluid container "disposed" telemetry event. This telemetry is produced from the "disposed" Fluid container system event
|
|
47
|
+
* which is emitted when the {@link @fluidframework/fluid-static#IFluidContainer} is closed, which permanently disables it.
|
|
48
|
+
*
|
|
49
|
+
* @see More details about{@link @fluidframework/container-definitions#IContainer.close | the container close event}
|
|
50
|
+
*
|
|
51
|
+
* @beta
|
|
52
|
+
*/
|
|
53
|
+
export declare interface ContainerDisposedTelemetry extends IContainerTelemetry {
|
|
54
|
+
/**
|
|
55
|
+
* {@inheritDoc IFluidTelemetry.eventName}
|
|
56
|
+
*/
|
|
57
|
+
eventName: "fluidframework.container.disposed";
|
|
58
|
+
/**
|
|
59
|
+
* If the container was closed due to error (as opposed to an explicit call to
|
|
60
|
+
* {@link @fluidframework/fluid-static#IFluidContainer."dispose"}), this will contain details about the error that caused it.
|
|
61
|
+
*/
|
|
62
|
+
error?: ICriticalContainerError;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The aggregate type for all values within {@link ContainerTelemetryEventNames}
|
|
67
|
+
* @beta
|
|
68
|
+
*/
|
|
69
|
+
export declare type ContainerTelemetryEventName = (typeof ContainerTelemetryEventNames)[keyof typeof ContainerTelemetryEventNames];
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* This object contains names for Container Telemetry. Unlike the raw {@link @fluidframework/fluid-static#IFluidContainerEvents | IFluidContainer system event names} they contain more information such as the scope
|
|
73
|
+
*
|
|
74
|
+
* @beta
|
|
75
|
+
*/
|
|
76
|
+
export declare const ContainerTelemetryEventNames: {
|
|
77
|
+
/**
|
|
78
|
+
* Name for the container telemetry event that is intended to be produced from the IFluidContainer "connected" {@link @fluidframework/fluid-static#IFluidContainerEvents | system event}
|
|
79
|
+
*
|
|
80
|
+
* @see {@link ContainerConnectedTelemetry}
|
|
81
|
+
*/
|
|
82
|
+
readonly CONNECTED: "fluidframework.container.connected";
|
|
83
|
+
/**
|
|
84
|
+
* Name for the container telemetry event that is intended to be produced from the IFluidContainer "disconnected" {@link @fluidframework/fluid-static#IFluidContainerEvents | system event}
|
|
85
|
+
*
|
|
86
|
+
* @see {@link ContainerDisconnectedTelemetry}
|
|
87
|
+
*/
|
|
88
|
+
readonly DISCONNECTED: "fluidframework.container.disconnected";
|
|
89
|
+
/**
|
|
90
|
+
* Name for the container telemetry event that is intended to be produced from the IFluidContainer "disposed" {@link @fluidframework/fluid-static#IFluidContainerEvents | system event}
|
|
91
|
+
*
|
|
92
|
+
* @see {@link ContainerDisposedTelemetry}
|
|
93
|
+
*/
|
|
94
|
+
readonly DISPOSED: "fluidframework.container.disposed";
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Aggregate type for all the different types of Fluid telemetry event names.
|
|
99
|
+
*
|
|
100
|
+
* @privateremarks This only looks odd right now because {@link ContainerTelemetryEventName} is the only aggregation at the moment.
|
|
101
|
+
*
|
|
102
|
+
* @beta
|
|
103
|
+
*/
|
|
104
|
+
export declare type FluidTelemetryEventName = ContainerTelemetryEventName;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The base interface for all Container telemetry
|
|
108
|
+
* @beta
|
|
109
|
+
*/
|
|
110
|
+
export declare interface IContainerTelemetry extends IFluidTelemetry {
|
|
111
|
+
/**
|
|
112
|
+
* {@inheritdoc IFluidTelemetry.eventName}
|
|
113
|
+
*/
|
|
114
|
+
eventName: ContainerTelemetryEventName;
|
|
115
|
+
/**
|
|
116
|
+
* Unique identifier for a container, stable across creation and load.
|
|
117
|
+
* I.e. different clients loading the same container (or the same client loading the container two separate times)
|
|
118
|
+
* will agree on this value.
|
|
119
|
+
*
|
|
120
|
+
* @remarks This can be undefined for a container that has not been attached.
|
|
121
|
+
*/
|
|
122
|
+
containerId?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Unique identifier for the container instance that generated the telemetry.
|
|
125
|
+
* This is not a stable identifier for the container across clients/time.
|
|
126
|
+
* Every load of the container will result in a different value.
|
|
127
|
+
*
|
|
128
|
+
*/
|
|
129
|
+
containerInstanceId: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export { ICriticalContainerError }
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The base interface extended by all Fluid telemetry
|
|
136
|
+
*
|
|
137
|
+
* @see {@link @fluidframework/fluid-telemetry#IContainerTelemetry} for an extension of this interface for all container related telemetry.
|
|
138
|
+
*
|
|
139
|
+
* @beta
|
|
140
|
+
*/
|
|
141
|
+
export declare interface IFluidTelemetry {
|
|
142
|
+
/**
|
|
143
|
+
* The unique name of the telemetry event. The event name contains scope concatenated together
|
|
144
|
+
* with periods to enable more granular log searching
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* "fluidframework.container.connected"
|
|
148
|
+
*/
|
|
149
|
+
eventName: FluidTelemetryEventName;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Base interface for all telemetry consumers.
|
|
154
|
+
* Conusmers are intended to take incoming produced {@link IFluidTelemetry} and do something of your choice with it.
|
|
155
|
+
* This could be sending the telemetry to a cloud platform or just console logging.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* Here is an example of how we construct a consumer to send telemetry to Azure App Insights, a cloud logging platform:
|
|
159
|
+
* ```ts
|
|
160
|
+
* class AppInsightsTelemetryConsumer implements ITelemetryConsumer {
|
|
161
|
+
* constructor(private readonly appInsightsClient: ApplicationInsights) {}
|
|
162
|
+
*
|
|
163
|
+
* consume(event: IFluidTelemetry) {
|
|
164
|
+
* this.appInsightsClient.trackEvent({
|
|
165
|
+
* name: event.eventName,
|
|
166
|
+
* properties: event,
|
|
167
|
+
* });
|
|
168
|
+
* }
|
|
169
|
+
* }
|
|
170
|
+
*```
|
|
171
|
+
*
|
|
172
|
+
* @beta
|
|
173
|
+
*/
|
|
174
|
+
export declare interface ITelemetryConsumer {
|
|
175
|
+
/**
|
|
176
|
+
* This method is intended to take created {@link IFluidTelemetry} and do something with it.
|
|
177
|
+
* This could be sending the telemetry to a cloud platform, just console logging or something else of your choice.
|
|
178
|
+
*/
|
|
179
|
+
consume(event: IFluidTelemetry): any;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Starts creating {@link @fluidframework/fluid-telemetry#IFluidTelemetry} by transforming raw system events emitted by the specified container
|
|
184
|
+
* into said telemetry and passing it onto to the specified {@link ITelemetryConsumer}
|
|
185
|
+
*
|
|
186
|
+
* @beta
|
|
187
|
+
*/
|
|
188
|
+
export declare const startTelemetry: (config: TelemetryConfig) => void;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Configuration object for subscribing to {@link @fluidframework/fluid-telemetry#IFluidTelemetry} and consuming said telemetry via one or more {@link ITelemetryConsumer}
|
|
192
|
+
*
|
|
193
|
+
* @beta
|
|
194
|
+
*/
|
|
195
|
+
export declare interface TelemetryConfig {
|
|
196
|
+
/**
|
|
197
|
+
* The container whose events should be monitored, transformed into Fluid telemetry, and sent to a {@link ITelemetryConsumer}.
|
|
198
|
+
*/
|
|
199
|
+
container: IFluidContainer;
|
|
200
|
+
/**
|
|
201
|
+
* Unique identifier for the passed in container, i.e. the return value of a call
|
|
202
|
+
* to {@link @fluidframework/fluid-static#IFluidContainer.attach | `IFluidContainer.attach()`} when creating a new
|
|
203
|
+
* Fluid container, or the id used to load a pre-existing one.
|
|
204
|
+
*/
|
|
205
|
+
containerId: string;
|
|
206
|
+
/**
|
|
207
|
+
* Conusmers take incoming produced {@link @fluidframework/fluid-telemetry#IFluidTelemetry} and do something of your choice with it.
|
|
208
|
+
* This could be sending the telemetry to a cloud platform or just console logging.
|
|
209
|
+
*/
|
|
210
|
+
consumers: ITelemetryConsumer[];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { }
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* This package provides an implementation and types for producing and consuming telemetry for Fluid Framework applications
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export { type ICriticalContainerError } from "@fluidframework/container-definitions";
|
|
10
|
+
export { type IFluidTelemetry, type FluidTelemetryEventName, type ITelemetryConsumer, } from "./common/index.js";
|
|
11
|
+
export { type IContainerTelemetry, type ContainerTelemetryEventName, ContainerTelemetryEventNames, type ContainerConnectedTelemetry, type ContainerDisconnectedTelemetry, type ContainerDisposedTelemetry, } from "./container/index.js";
|
|
12
|
+
export { startTelemetry, type TelemetryConfig } from "./factory/index.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AACrF,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAChC,4BAA4B,EAC5B,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
export { ContainerTelemetryEventNames, } from "./container/index.js";
|
|
6
|
+
export { startTelemetry } from "./factory/index.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,EAGN,4BAA4B,GAI5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAwB,MAAM,oBAAoB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * This package provides an implementation and types for producing and consuming telemetry for Fluid Framework applications\n * @packageDocumentation\n */\nexport { type ICriticalContainerError } from \"@fluidframework/container-definitions\";\nexport {\n\ttype IFluidTelemetry,\n\ttype FluidTelemetryEventName,\n\ttype ITelemetryConsumer,\n} from \"./common/index.js\";\nexport {\n\ttype IContainerTelemetry,\n\ttype ContainerTelemetryEventName,\n\tContainerTelemetryEventNames,\n\ttype ContainerConnectedTelemetry,\n\ttype ContainerDisconnectedTelemetry,\n\ttype ContainerDisposedTelemetry,\n} from \"./container/index.js\";\nexport { startTelemetry, type TelemetryConfig } from \"./factory/index.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"containerTelemetry.spec.d.ts","sourceRoot":"","sources":["../../src/test/containerTelemetry.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { spy } from "sinon";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
import { TypedEventEmitter } from "@fluid-internal/client-utils";
|
|
4
|
+
import { ApplicationInsights } from "@microsoft/applicationinsights-web";
|
|
5
|
+
import { startTelemetry } from "../factory/index.js";
|
|
6
|
+
import { IFluidContainerSystemEventNames } from "../container/index.js";
|
|
7
|
+
import { ContainerTelemetryEventNames, } from "../index.js";
|
|
8
|
+
/**
|
|
9
|
+
* For these unit tests, we are just interested in the event emitter part of the Fluid container.
|
|
10
|
+
* The rest of the functionality of IFluidContainer is irrelevant.
|
|
11
|
+
*/
|
|
12
|
+
class MockFluidContainer extends TypedEventEmitter {
|
|
13
|
+
connect() {
|
|
14
|
+
this.emit(IFluidContainerSystemEventNames.CONNECTED);
|
|
15
|
+
}
|
|
16
|
+
disconnect() {
|
|
17
|
+
this.emit(IFluidContainerSystemEventNames.DISCONNECTED);
|
|
18
|
+
}
|
|
19
|
+
dispose(error) {
|
|
20
|
+
this.emit(IFluidContainerSystemEventNames.DISPOSED, error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
describe("container telemetry via", () => {
|
|
24
|
+
let mockFluidContainer;
|
|
25
|
+
const mockContainerId = "mockContainerId";
|
|
26
|
+
let appInsightsClient;
|
|
27
|
+
let trackEventSpy;
|
|
28
|
+
let telemetryConfig;
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
appInsightsClient = new ApplicationInsights({
|
|
31
|
+
config: {
|
|
32
|
+
connectionString:
|
|
33
|
+
// (this is an example string)
|
|
34
|
+
"InstrumentationKey=abcdefgh-ijkl-mnop-qrst-uvwxyz6ffd9c;IngestionEndpoint=https://westus2-2.in.applicationinsights.azure.com/;LiveEndpoint=https://westus2.livediagnostics.monitor.azure.com/",
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
trackEventSpy = spy(appInsightsClient, "trackEvent");
|
|
38
|
+
mockFluidContainer = new MockFluidContainer();
|
|
39
|
+
class AppInsightsTelemetryConsumer {
|
|
40
|
+
constructor(client) {
|
|
41
|
+
this.client = client;
|
|
42
|
+
}
|
|
43
|
+
consume(event) {
|
|
44
|
+
this.client.trackEvent({
|
|
45
|
+
name: event.eventName,
|
|
46
|
+
properties: event,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
telemetryConfig = {
|
|
51
|
+
container: mockFluidContainer,
|
|
52
|
+
containerId: mockContainerId,
|
|
53
|
+
consumers: [new AppInsightsTelemetryConsumer(appInsightsClient)],
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
it("Emitting 'connected' container system event produces expected ContainerConnectedTelemetry using Azure App Insights", () => {
|
|
57
|
+
startTelemetry(telemetryConfig);
|
|
58
|
+
mockFluidContainer.connect();
|
|
59
|
+
expect(trackEventSpy.callCount).to.equal(1);
|
|
60
|
+
// Obtain the events from the method that the spy was called with
|
|
61
|
+
const actualAppInsightsTelemetry = trackEventSpy.getCall(0).args[0];
|
|
62
|
+
const actualContainerTelemetry = actualAppInsightsTelemetry.properties;
|
|
63
|
+
const expectedAppInsightsTelemetry = {
|
|
64
|
+
name: ContainerTelemetryEventNames.CONNECTED,
|
|
65
|
+
properties: {
|
|
66
|
+
eventName: ContainerTelemetryEventNames.CONNECTED,
|
|
67
|
+
containerId: mockContainerId,
|
|
68
|
+
containerInstanceId: actualContainerTelemetry.containerInstanceId,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
expect(expectedAppInsightsTelemetry).to.deep.equal(actualAppInsightsTelemetry);
|
|
72
|
+
// We won't know what the container containerInstanceId will be but we can still check that it is defined.
|
|
73
|
+
expect(actualContainerTelemetry.containerInstanceId).to.be.a("string").with.length.above(0);
|
|
74
|
+
});
|
|
75
|
+
it("Emitting 'disconnected' container system event produces expected ContainerDisconnectedTelemetry using Azure App Insights", () => {
|
|
76
|
+
startTelemetry(telemetryConfig);
|
|
77
|
+
mockFluidContainer.disconnect();
|
|
78
|
+
expect(trackEventSpy.callCount).to.equal(1);
|
|
79
|
+
// Obtain the events from the method that the spy was called with
|
|
80
|
+
const actualAppInsightsTelemetry = trackEventSpy.getCall(0).args[0];
|
|
81
|
+
const actualContainerTelemetry = actualAppInsightsTelemetry.properties;
|
|
82
|
+
const expectedAppInsightsTelemetry = {
|
|
83
|
+
name: ContainerTelemetryEventNames.DISCONNECTED,
|
|
84
|
+
properties: {
|
|
85
|
+
eventName: ContainerTelemetryEventNames.DISCONNECTED,
|
|
86
|
+
containerId: mockContainerId,
|
|
87
|
+
containerInstanceId: actualContainerTelemetry.containerInstanceId,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
expect(expectedAppInsightsTelemetry).to.deep.equal(actualAppInsightsTelemetry);
|
|
91
|
+
// We won't know what the container containerInstanceId will be but we can still check that it is defined.
|
|
92
|
+
expect(actualContainerTelemetry.containerInstanceId).to.be.a("string").with.length.above(0);
|
|
93
|
+
});
|
|
94
|
+
it("Emitting 'disposed' system event produces expected ContainerDisposedTelemetry using Azure App Insights", () => {
|
|
95
|
+
startTelemetry(telemetryConfig);
|
|
96
|
+
mockFluidContainer.dispose();
|
|
97
|
+
expect(trackEventSpy.callCount).to.equal(1);
|
|
98
|
+
// Obtain the events from the method that the spy was called with
|
|
99
|
+
const actualAppInsightsTelemetry = trackEventSpy.getCall(0).args[0];
|
|
100
|
+
const actualContainerTelemetry = actualAppInsightsTelemetry.properties;
|
|
101
|
+
const expectedAppInsightsTelemetry = {
|
|
102
|
+
name: ContainerTelemetryEventNames.DISPOSED,
|
|
103
|
+
properties: {
|
|
104
|
+
eventName: ContainerTelemetryEventNames.DISPOSED,
|
|
105
|
+
containerId: mockContainerId,
|
|
106
|
+
containerInstanceId: actualContainerTelemetry.containerInstanceId,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
expect(expectedAppInsightsTelemetry).to.deep.equal(actualAppInsightsTelemetry);
|
|
110
|
+
// We won't know what the container containerInstanceId will be but we can still check that it is defined.
|
|
111
|
+
expect(actualContainerTelemetry.containerInstanceId).to.be.a("string").with.length.above(0);
|
|
112
|
+
});
|
|
113
|
+
it("Emitting 'disposed' system event with an error produces expected ContainerDisposedTelemetry using Azure App Insights", () => {
|
|
114
|
+
startTelemetry(telemetryConfig);
|
|
115
|
+
const containerError = {
|
|
116
|
+
errorType: "unknown error",
|
|
117
|
+
message: "An unknown error occured",
|
|
118
|
+
stack: "example stack error at line 52 of Container.ts",
|
|
119
|
+
};
|
|
120
|
+
mockFluidContainer.dispose(containerError);
|
|
121
|
+
// Obtain the events from the method that the spy was called with
|
|
122
|
+
const actualAppInsightsTelemetry = trackEventSpy.getCall(0).args[0];
|
|
123
|
+
const actualContainerTelemetry = actualAppInsightsTelemetry.properties;
|
|
124
|
+
const expectedAppInsightsTelemetry = {
|
|
125
|
+
name: ContainerTelemetryEventNames.DISPOSED,
|
|
126
|
+
properties: {
|
|
127
|
+
eventName: ContainerTelemetryEventNames.DISPOSED,
|
|
128
|
+
containerId: mockContainerId,
|
|
129
|
+
containerInstanceId: actualContainerTelemetry.containerInstanceId,
|
|
130
|
+
error: containerError,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
expect(expectedAppInsightsTelemetry).to.deep.equal(actualAppInsightsTelemetry);
|
|
134
|
+
// We won't know what the container containerInstanceId will be but we can still check that it is defined.
|
|
135
|
+
expect(actualContainerTelemetry.containerInstanceId).to.be.a("string").with.length.above(0);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
//# sourceMappingURL=containerTelemetry.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"containerTelemetry.spec.js","sourceRoot":"","sources":["../../src/test/containerTelemetry.spec.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OA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AC,CAAC;QAC/E,0GAA0G;QAC1G,MAAM,CAAC,wBAAwB,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC7F,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport type Sinon from \"sinon\";\nimport { spy } from \"sinon\";\nimport { expect } from \"chai\";\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport type { ICriticalContainerError } from \"@fluidframework/container-definitions\";\nimport { ApplicationInsights, type IEventTelemetry } from \"@microsoft/applicationinsights-web\";\nimport type { IFluidContainer, IFluidContainerEvents } from \"@fluidframework/fluid-static\";\nimport { startTelemetry, type TelemetryConfig } from \"../factory/index.js\";\nimport { IFluidContainerSystemEventNames, type IContainerTelemetry } from \"../container/index.js\";\nimport {\n\tContainerTelemetryEventNames,\n\ttype ContainerConnectedTelemetry,\n\ttype ContainerDisconnectedTelemetry,\n\ttype ContainerDisposedTelemetry,\n\ttype IFluidTelemetry,\n\ttype ITelemetryConsumer,\n} from \"../index.js\";\n\n/**\n * For these unit tests, we are just interested in the event emitter part of the Fluid container.\n * The rest of the functionality of IFluidContainer is irrelevant.\n */\nclass MockFluidContainer extends TypedEventEmitter<IFluidContainerEvents> {\n\tpublic connect(): void {\n\t\tthis.emit(IFluidContainerSystemEventNames.CONNECTED);\n\t}\n\n\tpublic disconnect(): void {\n\t\tthis.emit(IFluidContainerSystemEventNames.DISCONNECTED);\n\t}\n\n\tpublic dispose(error?: ICriticalContainerError): void {\n\t\tthis.emit(IFluidContainerSystemEventNames.DISPOSED, error);\n\t}\n}\n\ndescribe(\"container telemetry via\", () => {\n\tlet mockFluidContainer: MockFluidContainer;\n\tconst mockContainerId = \"mockContainerId\";\n\tlet appInsightsClient: ApplicationInsights;\n\tlet trackEventSpy: Sinon.SinonSpy;\n\tlet telemetryConfig: TelemetryConfig;\n\n\tbeforeEach(() => {\n\t\tappInsightsClient = new ApplicationInsights({\n\t\t\tconfig: {\n\t\t\t\tconnectionString:\n\t\t\t\t\t// (this is an example string)\n\t\t\t\t\t\"InstrumentationKey=abcdefgh-ijkl-mnop-qrst-uvwxyz6ffd9c;IngestionEndpoint=https://westus2-2.in.applicationinsights.azure.com/;LiveEndpoint=https://westus2.livediagnostics.monitor.azure.com/\",\n\t\t\t},\n\t\t});\n\n\t\ttrackEventSpy = spy(appInsightsClient, \"trackEvent\");\n\t\tmockFluidContainer = new MockFluidContainer();\n\n\t\tclass AppInsightsTelemetryConsumer implements ITelemetryConsumer {\n\t\t\tpublic constructor(private readonly client: ApplicationInsights) {}\n\n\t\t\tpublic consume(event: IFluidTelemetry): void {\n\t\t\t\tthis.client.trackEvent({\n\t\t\t\t\tname: event.eventName,\n\t\t\t\t\tproperties: event,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\ttelemetryConfig = {\n\t\t\tcontainer: mockFluidContainer as unknown as IFluidContainer,\n\t\t\tcontainerId: mockContainerId,\n\t\t\tconsumers: [new AppInsightsTelemetryConsumer(appInsightsClient)],\n\t\t};\n\t});\n\n\tit(\"Emitting 'connected' container system event produces expected ContainerConnectedTelemetry using Azure App Insights\", () => {\n\t\tstartTelemetry(telemetryConfig);\n\n\t\tmockFluidContainer.connect();\n\n\t\texpect(trackEventSpy.callCount).to.equal(1);\n\n\t\t// Obtain the events from the method that the spy was called with\n\t\tconst actualAppInsightsTelemetry = trackEventSpy.getCall(0).args[0] as IEventTelemetry;\n\t\tconst actualContainerTelemetry =\n\t\t\tactualAppInsightsTelemetry.properties as IContainerTelemetry;\n\n\t\tconst expectedAppInsightsTelemetry: IEventTelemetry = {\n\t\t\tname: ContainerTelemetryEventNames.CONNECTED,\n\t\t\tproperties: {\n\t\t\t\teventName: ContainerTelemetryEventNames.CONNECTED,\n\t\t\t\tcontainerId: mockContainerId,\n\t\t\t\tcontainerInstanceId: actualContainerTelemetry.containerInstanceId,\n\t\t\t} satisfies ContainerConnectedTelemetry,\n\t\t};\n\n\t\texpect(expectedAppInsightsTelemetry).to.deep.equal(actualAppInsightsTelemetry);\n\t\t// We won't know what the container containerInstanceId will be but we can still check that it is defined.\n\t\texpect(actualContainerTelemetry.containerInstanceId).to.be.a(\"string\").with.length.above(0);\n\t});\n\n\tit(\"Emitting 'disconnected' container system event produces expected ContainerDisconnectedTelemetry using Azure App Insights\", () => {\n\t\tstartTelemetry(telemetryConfig);\n\n\t\tmockFluidContainer.disconnect();\n\n\t\texpect(trackEventSpy.callCount).to.equal(1);\n\n\t\t// Obtain the events from the method that the spy was called with\n\t\tconst actualAppInsightsTelemetry = trackEventSpy.getCall(0).args[0] as IEventTelemetry;\n\t\tconst actualContainerTelemetry =\n\t\t\tactualAppInsightsTelemetry.properties as IContainerTelemetry;\n\n\t\tconst expectedAppInsightsTelemetry: IEventTelemetry = {\n\t\t\tname: ContainerTelemetryEventNames.DISCONNECTED,\n\t\t\tproperties: {\n\t\t\t\teventName: ContainerTelemetryEventNames.DISCONNECTED,\n\t\t\t\tcontainerId: mockContainerId,\n\t\t\t\tcontainerInstanceId: actualContainerTelemetry.containerInstanceId,\n\t\t\t} satisfies ContainerDisconnectedTelemetry,\n\t\t};\n\n\t\texpect(expectedAppInsightsTelemetry).to.deep.equal(actualAppInsightsTelemetry);\n\t\t// We won't know what the container containerInstanceId will be but we can still check that it is defined.\n\t\texpect(actualContainerTelemetry.containerInstanceId).to.be.a(\"string\").with.length.above(0);\n\t});\n\n\tit(\"Emitting 'disposed' system event produces expected ContainerDisposedTelemetry using Azure App Insights\", () => {\n\t\tstartTelemetry(telemetryConfig);\n\n\t\tmockFluidContainer.dispose();\n\n\t\texpect(trackEventSpy.callCount).to.equal(1);\n\n\t\t// Obtain the events from the method that the spy was called with\n\t\tconst actualAppInsightsTelemetry = trackEventSpy.getCall(0).args[0] as IEventTelemetry;\n\t\tconst actualContainerTelemetry =\n\t\t\tactualAppInsightsTelemetry.properties as IContainerTelemetry;\n\n\t\tconst expectedAppInsightsTelemetry: IEventTelemetry = {\n\t\t\tname: ContainerTelemetryEventNames.DISPOSED,\n\t\t\tproperties: {\n\t\t\t\teventName: ContainerTelemetryEventNames.DISPOSED,\n\t\t\t\tcontainerId: mockContainerId,\n\t\t\t\tcontainerInstanceId: actualContainerTelemetry.containerInstanceId,\n\t\t\t} satisfies ContainerDisposedTelemetry,\n\t\t};\n\n\t\texpect(expectedAppInsightsTelemetry).to.deep.equal(actualAppInsightsTelemetry);\n\t\t// We won't know what the container containerInstanceId will be but we can still check that it is defined.\n\t\texpect(actualContainerTelemetry.containerInstanceId).to.be.a(\"string\").with.length.above(0);\n\t});\n\n\tit(\"Emitting 'disposed' system event with an error produces expected ContainerDisposedTelemetry using Azure App Insights\", () => {\n\t\tstartTelemetry(telemetryConfig);\n\n\t\tconst containerError: ICriticalContainerError = {\n\t\t\terrorType: \"unknown error\",\n\t\t\tmessage: \"An unknown error occured\",\n\t\t\tstack: \"example stack error at line 52 of Container.ts\",\n\t\t};\n\n\t\tmockFluidContainer.dispose(containerError);\n\n\t\t// Obtain the events from the method that the spy was called with\n\t\tconst actualAppInsightsTelemetry = trackEventSpy.getCall(0).args[0] as IEventTelemetry;\n\t\tconst actualContainerTelemetry =\n\t\t\tactualAppInsightsTelemetry.properties as IContainerTelemetry;\n\n\t\tconst expectedAppInsightsTelemetry: IEventTelemetry = {\n\t\t\tname: ContainerTelemetryEventNames.DISPOSED,\n\t\t\tproperties: {\n\t\t\t\teventName: ContainerTelemetryEventNames.DISPOSED,\n\t\t\t\tcontainerId: mockContainerId,\n\t\t\t\tcontainerInstanceId: actualContainerTelemetry.containerInstanceId,\n\t\t\t\terror: containerError,\n\t\t\t} satisfies ContainerDisposedTelemetry,\n\t\t};\n\n\t\texpect(expectedAppInsightsTelemetry).to.deep.equal(actualAppInsightsTelemetry);\n\t\t// We won't know what the container containerInstanceId will be but we can still check that it is defined.\n\t\texpect(actualContainerTelemetry.containerInstanceId).to.be.a(\"string\").with.length.above(0);\n\t});\n});\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.42.3"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fluidframework/fluid-telemetry",
|
|
3
|
+
"version": "2.0.0-dev-rc.3.0.0.253463",
|
|
4
|
+
"description": "Customer facing Fluid telemetry types and classes for both producing and consuming said telemetry",
|
|
5
|
+
"homepage": "https://fluidframework.com",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/microsoft/FluidFramework.git",
|
|
9
|
+
"directory": "packages/framework/client-logger/fluid-telemetry"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "Microsoft and contributors",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./lib/index.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"require": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"./public": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./lib/fluid-telemetry-public.d.ts",
|
|
29
|
+
"default": "./lib/index.js"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/fluid-telemetry-public.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./beta": {
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./lib/fluid-telemetry-beta.d.ts",
|
|
39
|
+
"default": "./lib/index.js"
|
|
40
|
+
},
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./dist/fluid-telemetry-beta.d.ts",
|
|
43
|
+
"default": "./dist/index.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"./internal": {
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./lib/index.d.ts",
|
|
49
|
+
"default": "./lib/index.js"
|
|
50
|
+
},
|
|
51
|
+
"require": {
|
|
52
|
+
"types": "./dist/index.d.ts",
|
|
53
|
+
"default": "./dist/index.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"./app-insights": {
|
|
57
|
+
"import": {
|
|
58
|
+
"types": "./lib/app-insights/index.d.ts",
|
|
59
|
+
"default": "./lib/app-insights/index.js"
|
|
60
|
+
},
|
|
61
|
+
"require": {
|
|
62
|
+
"types": "./dist/app-insights/index.d.ts",
|
|
63
|
+
"default": "./dist/app-insights/index.js"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"main": "dist/index.js",
|
|
68
|
+
"types": "dist/index.d.ts",
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@fluidframework/container-definitions": "2.0.0-dev-rc.3.0.0.253463",
|
|
71
|
+
"@fluidframework/container-loader": "2.0.0-dev-rc.3.0.0.253463",
|
|
72
|
+
"@fluidframework/fluid-static": "2.0.0-dev-rc.3.0.0.253463",
|
|
73
|
+
"@microsoft/applicationinsights-web": "^2.8.11",
|
|
74
|
+
"uuid": "^9.0.0"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@arethetypeswrong/cli": "^0.15.2",
|
|
78
|
+
"@fluid-internal/client-utils": "2.0.0-dev-rc.3.0.0.253463",
|
|
79
|
+
"@fluid-internal/mocha-test-setup": "2.0.0-dev-rc.3.0.0.253463",
|
|
80
|
+
"@fluid-tools/build-cli": "^0.34.0",
|
|
81
|
+
"@fluidframework/build-tools": "^0.34.0",
|
|
82
|
+
"@microsoft/api-extractor": "^7.42.3",
|
|
83
|
+
"@types/chai": "^4.0.0",
|
|
84
|
+
"@types/mocha": "^9.1.1",
|
|
85
|
+
"@types/sinon": "^17.0.3",
|
|
86
|
+
"@types/uuid": "^9.0.2",
|
|
87
|
+
"chai": "^4.2.0",
|
|
88
|
+
"eslint": "~8.55.0",
|
|
89
|
+
"mocha": "^10.2.0",
|
|
90
|
+
"prettier": "~3.0.3",
|
|
91
|
+
"rimraf": "^4.4.0",
|
|
92
|
+
"sinon": "^17.0.1",
|
|
93
|
+
"tslib": "^1.10.0",
|
|
94
|
+
"typescript": "~5.1.6"
|
|
95
|
+
},
|
|
96
|
+
"fluidBuild": {
|
|
97
|
+
"tasks": {
|
|
98
|
+
"build:docs": {
|
|
99
|
+
"dependsOn": [
|
|
100
|
+
"...",
|
|
101
|
+
"api-extractor:commonjs",
|
|
102
|
+
"api-extractor:esnext"
|
|
103
|
+
],
|
|
104
|
+
"script": false
|
|
105
|
+
},
|
|
106
|
+
"tsc": [
|
|
107
|
+
"...",
|
|
108
|
+
"typetests:gen"
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
"typeValidation": {
|
|
113
|
+
"broken": {},
|
|
114
|
+
"disabled": true
|
|
115
|
+
},
|
|
116
|
+
"scripts": {
|
|
117
|
+
"api": "fluid-build . --task api",
|
|
118
|
+
"api-extractor:commonjs": "api-extractor run --config ./api-extractor-cjs.json",
|
|
119
|
+
"api-extractor:esnext": "api-extractor run --local",
|
|
120
|
+
"build": "fluid-build . --task build",
|
|
121
|
+
"build:commonjs": "fluid-build . --task commonjs",
|
|
122
|
+
"build:compile": "fluid-build . --task compile",
|
|
123
|
+
"build:docs": "fluid-build . --task api",
|
|
124
|
+
"build:esnext": "tsc --project ./tsconfig.json",
|
|
125
|
+
"check:are-the-types-wrong": "attw --pack . --entrypoints .",
|
|
126
|
+
"check:release-tags": "api-extractor run --local --config ./api-extractor-lint.json",
|
|
127
|
+
"ci:build:docs": "api-extractor run",
|
|
128
|
+
"clean": "rimraf --glob _api-extractor-temp coverage dist lib nyc \"**/*.tsbuildinfo\" \"**/*.build.log\"",
|
|
129
|
+
"eslint": "eslint --format stylish src",
|
|
130
|
+
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
131
|
+
"format": "fluid-build --task format .",
|
|
132
|
+
"format-and-build": "npm run format && npm run build",
|
|
133
|
+
"format-and-compile": "npm run format && npm run build:compile",
|
|
134
|
+
"format:prettier": "prettier --write . --cache --ignore-path ../../../../.prettierignore",
|
|
135
|
+
"lint": "fluid-build . --task lint",
|
|
136
|
+
"lint:fix": "fluid-build . --task eslint:fix --task format",
|
|
137
|
+
"test": "npm run test:mocha",
|
|
138
|
+
"test:mocha": "npm run test:mocha:esm && echo skipping cjs to avoid overhead - npm run test:mocha:cjs",
|
|
139
|
+
"test:mocha:cjs": "mocha --recursive \"dist/test/**/*.spec.*js\" --exit",
|
|
140
|
+
"test:mocha:esm": "mocha --recursive \"lib/test/**/*.spec.*js\" --exit",
|
|
141
|
+
"tsc": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../../common/build/build-common/src/cjs/package.json ./dist",
|
|
142
|
+
"typetests:gen": "fluid-type-test-generator",
|
|
143
|
+
"typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { type ApplicationInsights } from "@microsoft/applicationinsights-web";
|
|
7
|
+
import type { IFluidTelemetry, ITelemetryConsumer } from "../common/index.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An implementation of {@link ITelemetryConsumer} that routes {@link IFluidTelemetry} to Azure App Insights
|
|
11
|
+
* in a format that is supported by Fluid Framework service offerings such as Cloud dashboards and alarms.
|
|
12
|
+
*/
|
|
13
|
+
export class AppInsightsTelemetryConsumer implements ITelemetryConsumer {
|
|
14
|
+
public constructor(private readonly appInsightsClient: ApplicationInsights) {}
|
|
15
|
+
|
|
16
|
+
public consume(event: IFluidTelemetry): void {
|
|
17
|
+
this.appInsightsClient.trackEvent({
|
|
18
|
+
name: event.eventName,
|
|
19
|
+
properties: event,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { IFluidTelemetry } from "../index.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Base interface for all telemetry consumers.
|
|
10
|
+
* Conusmers are intended to take incoming produced {@link IFluidTelemetry} and do something of your choice with it.
|
|
11
|
+
* This could be sending the telemetry to a cloud platform or just console logging.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* Here is an example of how we construct a consumer to send telemetry to Azure App Insights, a cloud logging platform:
|
|
15
|
+
* ```ts
|
|
16
|
+
* class AppInsightsTelemetryConsumer implements ITelemetryConsumer {
|
|
17
|
+
* constructor(private readonly appInsightsClient: ApplicationInsights) {}
|
|
18
|
+
*
|
|
19
|
+
* consume(event: IFluidTelemetry) {
|
|
20
|
+
* this.appInsightsClient.trackEvent({
|
|
21
|
+
* name: event.eventName,
|
|
22
|
+
* properties: event,
|
|
23
|
+
* });
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
*```
|
|
27
|
+
*
|
|
28
|
+
* @beta
|
|
29
|
+
*/
|
|
30
|
+
export interface ITelemetryConsumer {
|
|
31
|
+
/**
|
|
32
|
+
* This method is intended to take created {@link IFluidTelemetry} and do something with it.
|
|
33
|
+
* This could be sending the telemetry to a cloud platform, just console logging or something else of your choice.
|
|
34
|
+
*/
|
|
35
|
+
consume(event: IFluidTelemetry);
|
|
36
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { type ITelemetryConsumer } from "./consumers/index.js";
|
|
7
|
+
export { type IFluidTelemetry, type FluidTelemetryEventName } from "./telemetry/index.js";
|