@azure/monitor-opentelemetry
Version:
Azure Monitor OpenTelemetry (Node.js)
78 lines • 2.69 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import url from "url";
import { redirectPolicyName } from "@azure/core-rest-pipeline";
import { diag } from "@opentelemetry/api";
import { QuickpulseClient } from "../../../generated/index.js";
const applicationInsightsResource = "https://monitor.azure.com//.default";
/**
* Quickpulse sender class
* @internal
*/
export class QuickpulseSender {
quickpulseClient;
quickpulseClientOptions;
instrumentationKey;
endpointUrl;
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 QuickpulseClient(this.quickpulseClientOptions);
// Handle redirects in HTTP Sender
this.quickpulseClient.pipeline.removePolicy({ name: 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;
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;
diag.warn("Failed to post Quickpulse service", restError.message);
}
return;
}
handlePermanentRedirect(location) {
if (location) {
const locUrl = new url.URL(location);
if (locUrl && locUrl.host) {
this.endpointUrl = "https://" + locUrl.host;
}
}
}
}
//# sourceMappingURL=sender.js.map