Add error when ikey/connection string not present in TelemetryClient (#1008)
This commit is contained in:
Родитель
ab798447cd
Коммит
c507448f1f
|
@ -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 }>{};
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче