@azure/monitor-opentelemetry
Version:
Azure Monitor OpenTelemetry (Node.js)
79 lines • 2.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuickpulseSender = void 0;
const tslib_1 = require("tslib");
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
const url_1 = tslib_1.__importDefault(require("url"));
const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
const api_1 = require("@opentelemetry/api");
const index_js_1 = require("../../../generated/index.js");
const applicationInsightsResource = "https://monitor.azure.com//.default";
/**
* Quickpulse sender class
* @internal
*/
class QuickpulseSender {
constructor(options) {
// Build endpoint using provided configuration or default values
this.endpointUrl = options.endpointUrl;
this.quickpulseClientOptions = {
endpoint: this.endpointUrl,
};
this.instrumentationKey = options.instrumentationKey;
if (options.credential) {
this.quickpulseClientOptions.credential = options.credential;
// Add credentialScopes
if (options.credentialScopes) {
this.quickpulseClientOptions.credentialScopes = options.credentialScopes;
}
else {
// Default
this.quickpulseClientOptions.credentialScopes = [applicationInsightsResource];
}
}
this.quickpulseClient = new index_js_1.QuickpulseClient(this.quickpulseClientOptions);
// Handle redirects in HTTP Sender
this.quickpulseClient.pipeline.removePolicy({ name: core_rest_pipeline_1.redirectPolicyName });
}
/**
* isSubscribed Quickpulse service
* @internal
*/
async isSubscribed(optionalParams) {
try {
const response = await this.quickpulseClient.isSubscribed(this.endpointUrl, this.instrumentationKey, optionalParams);
return response;
}
catch (error) {
const restError = error;
api_1.diag.info("Failed to ping Quickpulse service", restError.message);
}
return;
}
/**
* publish Quickpulse service
* @internal
*/
async publish(optionalParams) {
try {
const response = await this.quickpulseClient.publish(this.endpointUrl, this.instrumentationKey, optionalParams);
return response;
}
catch (error) {
const restError = error;
api_1.diag.warn("Failed to post Quickpulse service", restError.message);
}
return;
}
handlePermanentRedirect(location) {
if (location) {
const locUrl = new url_1.default.URL(location);
if (locUrl && locUrl.host) {
this.endpointUrl = "https://" + locUrl.host;
}
}
}
}
exports.QuickpulseSender = QuickpulseSender;
//# sourceMappingURL=sender.js.map