3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import type { AppInsightsCore , IExtendedConfiguration } from '@microsoft/1ds-core-js' ;
6
+ import type { IExtendedConfiguration , IExtendedTelemetryItem , ITelemetryItem , ITelemetryUnloadState } from '@microsoft/1ds-core-js' ;
7
7
import type { IChannelConfiguration , IXHROverride , PostChannel } from '@microsoft/1ds-post-js' ;
8
8
import { onUnexpectedError } from 'vs/base/common/errors' ;
9
9
import { mixin } from 'vs/base/common/objects' ;
10
10
import { ITelemetryAppender , validateTelemetryData } from 'vs/platform/telemetry/common/telemetryUtils' ;
11
11
12
+ // Interface type which is a subset of @microsoft /1ds-core-js AppInsightsCore.
13
+ // Allows us to more easily build mock objects for testing as the interface is quite large and we only need a few properties.
14
+ export interface IAppInsightsCore {
15
+ pluginVersionString : string ;
16
+ track ( item : ITelemetryItem | IExtendedTelemetryItem ) : void ;
17
+ unload ( isAsync : boolean , unloadComplete : ( unloadState : ITelemetryUnloadState ) => void ) : void ;
18
+ }
19
+
12
20
const endpointUrl = 'https://mobile.events.data.microsoft.com/OneCollector/1.0' ;
13
21
14
- async function getClient ( instrumentationKey : string , addInternalFlag ?: boolean , xhrOverride ?: IXHROverride ) : Promise < AppInsightsCore > {
22
+ async function getClient ( instrumentationKey : string , addInternalFlag ?: boolean , xhrOverride ?: IXHROverride ) : Promise < IAppInsightsCore > {
15
23
const oneDs = await import ( '@microsoft/1ds-core-js' ) ;
16
24
const postPlugin = await import ( '@microsoft/1ds-post-js' ) ;
17
25
const appInsightsCore = new oneDs . AppInsightsCore ( ) ;
@@ -57,15 +65,15 @@ async function getClient(instrumentationKey: string, addInternalFlag?: boolean,
57
65
// TODO @lramos 15 maybe make more in line with src/vs/platform/telemetry/browser/appInsightsAppender.ts with caching support
58
66
export abstract class AbstractOneDataSystemAppender implements ITelemetryAppender {
59
67
60
- protected _aiCoreOrKey : AppInsightsCore | string | undefined ;
61
- private _asyncAiCore : Promise < AppInsightsCore > | null ;
68
+ protected _aiCoreOrKey : IAppInsightsCore | string | undefined ;
69
+ private _asyncAiCore : Promise < IAppInsightsCore > | null ;
62
70
protected readonly endPointUrl = endpointUrl ;
63
71
64
72
constructor (
65
73
private readonly _isInternalTelemetry : boolean ,
66
74
private _eventPrefix : string ,
67
75
private _defaultData : { [ key : string ] : any } | null ,
68
- iKeyOrClientFactory : string | ( ( ) => AppInsightsCore ) , // allow factory function for testing
76
+ iKeyOrClientFactory : string | ( ( ) => IAppInsightsCore ) , // allow factory function for testing
69
77
private _xhrOverride ?: IXHROverride
70
78
) {
71
79
if ( ! this . _defaultData ) {
@@ -80,7 +88,7 @@ export abstract class AbstractOneDataSystemAppender implements ITelemetryAppende
80
88
this . _asyncAiCore = null ;
81
89
}
82
90
83
- private _withAIClient ( callback : ( aiCore : AppInsightsCore ) => void ) : void {
91
+ private _withAIClient ( callback : ( aiCore : IAppInsightsCore ) => void ) : void {
84
92
if ( ! this . _aiCoreOrKey ) {
85
93
return ;
86
94
}
0 commit comments