Add error when ikey/connection string not present in TelemetryClient (#1008)

This commit is contained in:
Hector Hernandez 2022-09-07 13:18:54 -07:00 коммит произвёл GitHub
Родитель ab798447cd
Коммит c507448f1f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 367 добавлений и 500 удалений

Просмотреть файл

@ -78,11 +78,6 @@ class Config implements IConfig {
const instrumentationKeyEnv: string | undefined = this._instrumentationKey;
this.instrumentationKey = csCode.instrumentationkey || iKeyCode /* === instrumentationKey */ || csEnv.instrumentationkey || instrumentationKeyEnv;
if (!this.instrumentationKey || this.instrumentationKey == "") {
throw new Error("Instrumentation key not found, please provide a connection string before starting the server");
}
let endpoint = `${this.endpointUrl || csCode.ingestionendpoint || csEnv.ingestionendpoint || this._endpointBase}`;
if (endpoint.endsWith("/")) {
// Remove extra '/' if present

Просмотреть файл

@ -42,6 +42,9 @@ class TelemetryClient {
constructor(setupString?: string) {
var config = new Config(setupString);
this.config = config;
if (!this.config.instrumentationKey || this.config.instrumentationKey == "") {
throw new Error("Instrumentation key not found, please provide a connection string before starting Application Insights SDK.");
}
this.context = new Context();
this.commonProperties = {};
this.authorizationHandler = null;

Просмотреть файл

@ -99,6 +99,12 @@ describe("#setupAndStart()", () => {
sinon.stub(Helpers, "sdkAlreadyExists", () => false);
// Test
assert.throws(function () { const Default = require("../../Bootstrap/Default") as typeof DefaultTypes; });
const Default = require("../../Bootstrap/Default") as typeof DefaultTypes;
Default.setLogger(new DiagnosticLogger(logger));
let result = Default.setupAndStart();
assert.equal(result, null);
assert.equal(logger.logCount, 0);
assert.equal(logger.errorCount, 1);
});
});

Просмотреть файл

@ -113,6 +113,13 @@ describe("Library/TelemetryClient", () => {
};
assert.ok(client.getAuthorizationHandler(client.config));
});
it("should throw if no iKey is available", () => {
var env = {};
process.env = env;
assert.throws(() => new Client());
});
});
describe("#trackEvent()", () => {

Просмотреть файл

@ -122,11 +122,6 @@ describe("Library/Config", () => {
http.request.restore();
https.request.restore();
});
it("should throw if no iKey is available", () => {
var env = {};
process.env = env;
assert.throws(() => new Config());
});
it("should read iKey from environment", () => {
var env = <{ [id: string]: string }>{};

837
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу