UNPKG

@azure/monitor-opentelemetry

Version:
144 lines 5.74 kB
"use strict"; /* * Copyright (c) Microsoft Corporation. * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.QuickpulseClient = void 0; const tslib_1 = require("tslib"); const coreClient = tslib_1.__importStar(require("@azure/core-client")); const Parameters = tslib_1.__importStar(require("./models/parameters.js")); const Mappers = tslib_1.__importStar(require("./models/mappers.js")); class QuickpulseClient extends coreClient.ServiceClient { /** * Initializes a new instance of the QuickpulseClient class. * @param options The parameter options */ constructor(options) { var _a, _b; // Initializing default values for options if (!options) { options = {}; } const defaults = { requestContentType: "application/json; charset=utf-8", }; const packageDetails = `azsdk-js-monitor-opentelemetry/1.0.0-beta.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}` : `${packageDetails}`; const optionsWithDefaults = Object.assign(Object.assign(Object.assign({}, defaults), options), { userAgentOptions: { userAgentPrefix, }, endpoint: (_b = (_a = options.endpoint) !== null && _a !== void 0 ? _a : options.baseUri) !== null && _b !== void 0 ? _b : "{endpoint}" }); super(optionsWithDefaults); // Assigning values to Constant parameters this.apiVersion = options.apiVersion || "2024-04-01-preview"; this.addCustomApiVersionPolicy(options.apiVersion); } /** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */ addCustomApiVersionPolicy(apiVersion) { if (!apiVersion) { return; } const apiVersionPolicy = { name: "CustomApiVersionPolicy", async sendRequest(request, next) { const param = request.url.split("?"); if (param.length > 1) { const newParams = param[1].split("&").map((item) => { if (item.indexOf("api-version") > -1) { return "api-version=" + apiVersion; } else { return item; } }); request.url = param[0] + "?" + newParams.join("&"); } return next(request); }, }; this.pipeline.addPolicy(apiVersionPolicy); } /** * Determine whether there is any subscription to the metrics and documents. * @param endpoint The endpoint of the Live Metrics service. * @param ikey The instrumentation key of the target Application Insights component for which the * client checks whether there's any subscription to it. * @param options The options parameters. */ isSubscribed(endpoint, ikey, options) { return this.sendOperationRequest({ endpoint, ikey, options }, isSubscribedOperationSpec); } /** * Publish live metrics to the Live Metrics service when there is an active subscription to the * metrics. * @param endpoint The endpoint of the Live Metrics service. * @param ikey The instrumentation key of the target Application Insights component for which the * client checks whether there's any subscription to it. * @param options The options parameters. */ publish(endpoint, ikey, options) { return this.sendOperationRequest({ endpoint, ikey, options }, publishOperationSpec); } } exports.QuickpulseClient = QuickpulseClient; // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const isSubscribedOperationSpec = { path: "/QuickPulseService.svc/ping", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.CollectionConfigurationInfo, headersMapper: Mappers.QuickpulseClientIsSubscribedHeaders, }, default: { bodyMapper: Mappers.ServiceError, }, }, requestBody: Parameters.monitoringDataPoint, queryParameters: [Parameters.apiVersion, Parameters.ikey], urlParameters: [Parameters.endpoint], headerParameters: [ Parameters.contentType, Parameters.accept, Parameters.transmissionTime, Parameters.machineName, Parameters.instanceName, Parameters.streamId, Parameters.roleName, Parameters.invariantVersion, Parameters.configurationEtag, ], mediaType: "json", serializer, }; const publishOperationSpec = { path: "/QuickPulseService.svc/post", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.CollectionConfigurationInfo, headersMapper: Mappers.QuickpulseClientPublishHeaders, }, default: { bodyMapper: Mappers.ServiceError, }, }, requestBody: Parameters.monitoringDataPoints, queryParameters: [Parameters.apiVersion, Parameters.ikey], urlParameters: [Parameters.endpoint], headerParameters: [ Parameters.contentType, Parameters.accept, Parameters.transmissionTime, Parameters.configurationEtag, ], mediaType: "json", serializer, }; //# sourceMappingURL=quickpulseClient.js.map