Skip to content

Commit

Permalink
modified file structure to match jupyter repo
Browse files Browse the repository at this point in the history
  • Loading branch information
amunger committed Apr 19, 2022
1 parent d4dbf27 commit 1f3bc90
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 123 deletions.
9 changes: 4 additions & 5 deletions src/test/testHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { Context } from 'mocha';
import { AppinsightsKey, JVSC_EXTENSION_ID, Telemetry } from '../platform/common/constants';
import { IS_CI_SERVER } from './ciConstants.node';
import { extensions } from 'vscode';
import TelemetryReporter from './utils/ciTelemetry/node/telemetryReporter.node';
import { sleep } from './core';
import { CiTelemetryReporter } from './utils/ciTelemetry/ciTelemetryReporter.node';


let telemetryReporter: TelemetryReporter | undefined;
let telemetryReporter: CiTelemetryReporter | undefined;

export const rootHooks = {
beforeAll() {
Expand All @@ -15,7 +14,7 @@ export const rootHooks = {
}

const extensionVersion = extensions.getExtension(JVSC_EXTENSION_ID)?.packageJSON.version;
telemetryReporter = new TelemetryReporter(JVSC_EXTENSION_ID, extensionVersion, AppinsightsKey, true);
telemetryReporter = new CiTelemetryReporter(JVSC_EXTENSION_ID, extensionVersion, AppinsightsKey, true);
},
afterEach(this: Context) {
if (!IS_CI_SERVER) {
Expand All @@ -36,7 +35,7 @@ export const rootHooks = {
if (!IS_CI_SERVER) {
return;
}

await telemetryReporter?.dispose();
await sleep(2000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import { AppenderData, ITelemetryAppender } from './baseTelemetryReporter';
import { AppenderData, ITelemetryAppender } from './baseCiTelemetryReporter';

export interface BaseTelemetryClient {
logEvent(eventName: string, data?: AppenderData): void;
logException(exception: Error, data?: AppenderData): void;
flush(): void | Promise<void>;
}

export class BaseTelemetryAppender implements ITelemetryAppender {
export class TelemetryAppender implements ITelemetryAppender {
private _telemetryClient: BaseTelemetryClient | undefined;
private _clientInitialization: Promise<void> | undefined;

Expand All @@ -36,8 +36,7 @@ export class BaseTelemetryAppender implements ITelemetryAppender {
logEvent(eventName: string, data?: AppenderData): void {
if (this._telemetryClient) {
this._telemetryClient.logEvent(eventName, data);
}
else{
} else {
this._eventQueue.push({ eventName, data });
}
}
Expand All @@ -50,8 +49,7 @@ export class BaseTelemetryAppender implements ITelemetryAppender {
logException(exception: Error, data?: AppenderData): void {
if (this._telemetryClient) {
this._telemetryClient.logException(exception, data);
}
else{
} else {
this._exceptionQueue.push({ exception, data });
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import * as os from "os";
import { TelemetryClient } from 'applicationinsights';
import { BaseTelemetryClient } from './TelemetryAppender';
import { AppenderData } from './baseCiTelemetryReporter';
import * as vscode from "vscode";
import type { TelemetryClient } from "applicationinsights";
import { AppenderData, BaseTelemetryReporter } from "../common/baseTelemetryReporter";
import { BaseTelemetryAppender, BaseTelemetryClient } from "../common/baseTelemetryAppender";

/**
* A factory function which creates a telemetry client to be used by an appender to send telemetry in a node application.
Expand All @@ -17,7 +12,7 @@ import { BaseTelemetryAppender, BaseTelemetryClient } from "../common/baseTeleme
*
* @returns A promise which resolves to the telemetry client or rejects upon error
*/
const appInsightsClientFactory = async (key: string): Promise<BaseTelemetryClient> => {
export async function appInsightsClientFactory (key: string): Promise<BaseTelemetryClient> {
let appInsightsClient: TelemetryClient | undefined;
try {
process.env["APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL"] = "1";
Expand Down Expand Up @@ -88,17 +83,3 @@ const appInsightsClientFactory = async (key: string): Promise<BaseTelemetryClien
};
return telemetryClient;
};

export default class TelemetryReporter extends BaseTelemetryReporter {
constructor(extensionId: string, extensionVersion: string, key: string, firstParty: boolean) {
const appender = new BaseTelemetryAppender(key, (key) => appInsightsClientFactory(key));
if (key && key.indexOf("AIF-") === 0) {
firstParty = true;
}
super(extensionId, extensionVersion, appender, {
release: os.release(),
platform: os.platform(),
architecture: os.arch(),
}, firstParty);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*--------------------------------------------------------*/

import * as vscode from "vscode";
import { RawTelemetryEventProperties, TelemetryEventMeasurements, TelemetryEventProperties } from '../telemetryReporter';


export interface AppenderData {
Expand All @@ -17,6 +16,19 @@ export interface ITelemetryAppender {
instantiateAppender(): void;
}

export interface TelemetryEventProperties {
readonly [key: string]: string;
}

export interface RawTelemetryEventProperties {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
readonly [key: string]: any;
}

export interface TelemetryEventMeasurements {
readonly [key: string]: number;
}


export class BaseTelemetryReporter {
private userOptIn = true;
Expand Down
32 changes: 32 additions & 0 deletions src/test/utils/ciTelemetry/ciTelemetryReporter.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import * as os from 'os';
import { BaseTelemetryReporter } from './baseCiTelemetryReporter';
import { TelemetryAppender } from './TelemetryAppender';
import { appInsightsClientFactory } from './appInsightsClientFactory.node';

/**
* An isolated wrapper for an Application Insights client that is specifically for sending telemetry during CI jobs.
* This won't run on a users machine, so there is no need to check for opt-in status.
*/
export class CiTelemetryReporter extends BaseTelemetryReporter {
constructor(extensionId: string, extensionVersion: string, key: string, firstParty: boolean) {
const appender = new TelemetryAppender(key, (key) => appInsightsClientFactory(key));
if (key && key.indexOf('AIF-') === 0) {
firstParty = true;
}
super(
extensionId,
extensionVersion,
appender,
{
release: os.release(),
platform: os.platform(),
architecture: os.arch()
},
firstParty
);
}
}
88 changes: 0 additions & 88 deletions src/test/utils/ciTelemetry/telemetryReporter.d.ts

This file was deleted.

0 comments on commit 1f3bc90

Please sign in to comment.