Skip to content

Commit

Permalink
2.1.0 release (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorhdzg committed Jun 2, 2021
1 parent 3064bea commit 9ff235d
Show file tree
Hide file tree
Showing 14 changed files with 9 additions and 314 deletions.
2 changes: 1 addition & 1 deletion Bootstrap/DiagnosticLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class DiagnosticLogger {
siteName: process.env.WEBSITE_SITE_NAME,
ikey: process.env.APPINSIGHTS_INSTRUMENTATIONKEY,
extensionVersion: process.env.ApplicationInsightsAgent_EXTENSION_VERSION,
sdkVersion: "2.0.0",
sdkVersion: "2.1.0",
subscriptionId: process.env.WEBSITE_OWNER_NAME ? process.env.WEBSITE_OWNER_NAME.split("+")[0] : null,
}
}
Expand Down
34 changes: 0 additions & 34 deletions Library/AuthorizationHandler.ts

This file was deleted.

3 changes: 0 additions & 3 deletions Library/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ class Config {
/** Disable including legacy headers in outgoing requests, x-ms-request-id */
public ignoreLegacyHeaders?: boolean;

/** AAD TokenCredential to use to authenticate the app */
public aadTokenCredential?: azureCore.TokenCredential;

private endpointBase: string = Constants.DEFAULT_BREEZE_ENDPOINT;
private setCorrelationId: (v: string) => void;
private _profileQueryEndpoint: string;
Expand Down
21 changes: 1 addition & 20 deletions Library/QuickPulseSender.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import https = require("https");

import AuthorizationHandler = require("./AuthorizationHandler");
import Config = require("./Config");
import AutoCollectHttpDependencies = require("../AutoCollection/HttpDependencies");
import Logging = require("./Logging");
Expand Down Expand Up @@ -31,12 +30,10 @@ class QuickPulseSender {

private _config: Config;
private _consecutiveErrors: number;
private _getAuthorizationHandler: (config: Config) => AuthorizationHandler;

constructor(config: Config, getAuthorizationHandler?: (config: Config) => AuthorizationHandler) {
constructor(config: Config) {
this._config = config;
this._consecutiveErrors = 0;
this._getAuthorizationHandler = getAuthorizationHandler;
}

public ping(envelope: Contracts.EnvelopeQuickPulse,
Expand Down Expand Up @@ -88,22 +85,6 @@ class QuickPulseSender {
additionalHeaders.forEach(header => options.headers[header.name] = header.value);
}

if (postOrPing === "post") {
let authHandler = this._getAuthorizationHandler ? this._getAuthorizationHandler(this._config) : null;
if (authHandler) {
try {
// Add bearer token
await authHandler.addAuthorizationHeader(options);
}
catch (authError) {
let notice = `Failed to get AAD bearer token for the Application. Error:`;
Logging.info(QuickPulseSender.TAG, notice, authError);
// Do not send request to Quickpulse if auth fails, data will be dropped
return;
}
}
}

// HTTPS only
if (this._config.httpsAgent) {
(<any>options).agent = this._config.httpsAgent;
Expand Down
6 changes: 2 additions & 4 deletions Library/QuickPulseStateManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AuthorizationHandler = require("./AuthorizationHandler");
import Logging = require("./Logging");
import Config = require("./Config");
import QuickPulseEnvelopeFactory = require("./QuickPulseEnvelopeFactory");
Expand All @@ -14,7 +13,6 @@ import * as Contracts from "../Declarations/Contracts";
class QuickPulseStateManager {
public config: Config;
public context: Context;
public authorizationHandler: AuthorizationHandler;

private static MAX_POST_WAIT_TIME = 20000;
private static MAX_PING_WAIT_TIME = 60000;
Expand All @@ -34,10 +32,10 @@ class QuickPulseStateManager {
private _redirectedHost: string = null;
private _pollingIntervalHint: number = -1;

constructor(config: Config, context?: Context, getAuthorizationHandler?: (config: Config) => AuthorizationHandler) {
constructor(config: Config, context?: Context) {
this.config = config;
this.context = context || new Context();
this._sender = new QuickPulseSender(this.config, getAuthorizationHandler);
this._sender = new QuickPulseSender(this.config);
this._isEnabled = false;
}

Expand Down
26 changes: 1 addition & 25 deletions Library/Sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import path = require("path");
import zlib = require("zlib");
import child_process = require("child_process");

import AuthorizationHandler = require("./AuthorizationHandler");
import Logging = require("./Logging");
import Config = require("./Config")
import Contracts = require("../Declarations/Contracts");
Expand All @@ -32,7 +31,6 @@ class Sender {
private _config: Config;
private _onSuccess: (response: string) => void;
private _onError: (error: Error) => void;
private _getAuthorizationHandler: (config: Config) => AuthorizationHandler;
private _enableDiskRetryMode: boolean;
private _numConsecutiveFailures: number;
private _numConsecutiveRedirects: number;
Expand All @@ -43,7 +41,7 @@ class Sender {
protected _resendInterval: number;
protected _maxBytesOnDisk: number;

constructor(config: Config, getAuthorizationHandler?: (config: Config) => AuthorizationHandler, onSuccess?: (response: string) => void, onError?: (error: Error) => void) {
constructor(config: Config, onSuccess?: (response: string) => void, onError?: (error: Error) => void) {
this._config = config;
this._onSuccess = onSuccess;
this._onError = onError;
Expand All @@ -53,7 +51,6 @@ class Sender {
this._numConsecutiveFailures = 0;
this._numConsecutiveRedirects = 0;
this._resendTimer = null;
this._getAuthorizationHandler = getAuthorizationHandler;
this._fileCleanupTimer = null;
// tmpdir is /tmp for *nix and USERDIR/AppData/Local/Temp for Windows
this._tempDir = path.join(os.tmpdir(), Sender.TEMPDIR_PREFIX + this._config.instrumentationKey);
Expand Down Expand Up @@ -121,26 +118,7 @@ class Sender {
}
};

let authHandler = this._getAuthorizationHandler ? this._getAuthorizationHandler(this._config) : null;
if (authHandler) {
try {
// Add bearer token
await authHandler.addAuthorizationHeader(options);
}
catch (authError) {
let errorMsg = "Failed to get AAD bearer token for the Application. Error:" + authError.toString();
// If AAD auth fails do not send to Breeze
if (typeof callback === "function") {
callback(errorMsg);
}
this._storeToDisk(envelopes);
Logging.warn(Sender.TAG, errorMsg);
return;
}
}

let batch: string = "";

envelopes.forEach(envelope => {
var payload: string = this._stringify(envelope);
if (typeof payload !== "string") {
Expand Down Expand Up @@ -283,8 +261,6 @@ class Sender {
return (
statusCode === 206 || // Retriable
statusCode === 308 || // Permanent Redirect
statusCode === 401 || // Unauthorized
statusCode === 403 || // Forbidden
statusCode === 408 || // Timeout
statusCode === 429 || // Throttle
statusCode === 439 || // Quota
Expand Down
16 changes: 1 addition & 15 deletions Library/TelemetryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import os = require("os");
import azureCore = require("@azure/core-http");

import Config = require("./Config");
import AuthorizationHandler = require("./AuthorizationHandler");
import Context = require("./Context");
import Contracts = require("../Declarations/Contracts");
import Channel = require("./Channel");
Expand All @@ -30,8 +29,6 @@ class TelemetryClient {
public commonProperties: { [key: string]: string; };
public channel: Channel;
public quickPulseClient: QuickPulseStateManager;
public authorizationHandler: AuthorizationHandler;


/**
* Constructs a new client of the client
Expand All @@ -42,8 +39,7 @@ class TelemetryClient {
this.config = config;
this.context = new Context();
this.commonProperties = {};
this.authorizationHandler = null;
var sender = new Sender(this.config, this.getAuthorizationHandler);
var sender = new Sender(this.config);
this.channel = new Channel(() => config.disableAppInsights, () => config.maxBatchSize, () => config.maxBatchIntervalMs, sender);
}

Expand Down Expand Up @@ -178,16 +174,6 @@ class TelemetryClient {
this._enableAzureProperties = value;
}

/**
* Get Authorization handler
*/
public getAuthorizationHandler(config: Config): AuthorizationHandler {
if (config && config.aadTokenCredential) {
return this.authorizationHandler || new AuthorizationHandler(config.aadTokenCredential);
}
return null;
}

/**
* Adds telemetry processor to the collection. Telemetry processors will be called one by one
* before telemetry item is pushed for sending and in the order they were added.
Expand Down
73 changes: 0 additions & 73 deletions Tests/Library/AuthorizationHandler.tests.ts

This file was deleted.

10 changes: 0 additions & 10 deletions Tests/Library/Client.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,6 @@ describe("Library/TelemetryClient", () => {
var client = new Client("1aa11111-bbbb-1ccc-8ddd-eeeeffff3333");
assert.ok(client.channel);
});

it("should initialize authorization handler", () => {
var client = new Client("InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;");
client.config.aadTokenCredential = {
async getToken(scopes: string | string[], options?: any): Promise<any> {
return { token: "testToken", };
}
};
assert.ok(client.getAuthorizationHandler(client.config));
});
});

describe("#trackEvent()", () => {
Expand Down
2 changes: 1 addition & 1 deletion Tests/Library/Context.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("Library/Context", () => {
it("should set internalSdkVersion to 'node:<version>'", () => {
var context = new Context();
// todo: make this less fragile (will need updating on each minor version change)
assert.equal(context.tags[context.keys.internalSdkVersion].substring(0, 9), "node:2.0.");
assert.equal(context.tags[context.keys.internalSdkVersion].substring(0, 9), "node:2.1.");
});

it("should correctly set device context", () => {
Expand Down
Loading

0 comments on commit 9ff235d

Please sign in to comment.