Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Monitor Exporter] Move the Monitor package to use core-rest-pipeline #16513

Merged
merged 10 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
540 changes: 267 additions & 273 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion sdk/monitor/monitor-opentelemetry-exporter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
"typescript": "~4.2.0"
},
"dependencies": {
"@azure/core-http": "^2.0.0",
"@azure/core-client": "^1.0.0",
"@azure/core-rest-pipeline": "^1.1.0",
"@opentelemetry/api": "^1.0.1",
"@opentelemetry/core": "^0.22.0",
"@opentelemetry/resources": "^0.22.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { diag } from "@opentelemetry/api";
import { ExportResult, ExportResultCode } from "@opentelemetry/core";
import { ReadableSpan, SpanExporter } from "@opentelemetry/tracing";
import { RestError } from "@azure/core-http";
import { RestError } from "@azure/core-rest-pipeline";
import { ConnectionStringParser } from "../utils/connectionStringParser";
import { HttpSender, FileSystemPersist } from "../platform";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/

import * as coreHttp from "@azure/core-http";
import * as coreClient from "@azure/core-client";
import * as Parameters from "./models/parameters";
import * as Mappers from "./models/mappers";
import { ApplicationInsightsClientContext } from "./applicationInsightsClientContext";
import {
ApplicationInsightsClientOptionalParams,
TelemetryItem,
ApplicationInsightsClientTrackOptionalParams,
ApplicationInsightsClientTrackResponse
} from "./models";

Expand All @@ -32,22 +33,15 @@ export class ApplicationInsightsClient extends ApplicationInsightsClientContext
*/
track(
body: TelemetryItem[],
options?: coreHttp.OperationOptions
options?: ApplicationInsightsClientTrackOptionalParams
): Promise<ApplicationInsightsClientTrackResponse> {
const operationOptions: coreHttp.RequestOptionsBase = coreHttp.operationOptionsToRequestOptionsBase(
options || {}
);
return this.sendOperationRequest(
{ body, options: operationOptions },
trackOperationSpec
) as Promise<ApplicationInsightsClientTrackResponse>;
return this.sendOperationRequest({ body, options }, trackOperationSpec);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);

const serializer = new coreHttp.Serializer(Mappers, /* isXml */ false);

const trackOperationSpec: coreHttp.OperationSpec = {
const trackOperationSpec: coreClient.OperationSpec = {
path: "/track",
httpMethod: "POST",
responses: {
Expand All @@ -58,19 +52,24 @@ const trackOperationSpec: coreHttp.OperationSpec = {
bodyMapper: Mappers.TrackResponse
},
400: {
bodyMapper: Mappers.TrackResponse
bodyMapper: Mappers.TrackResponse,
isError: true
},
402: {
bodyMapper: Mappers.TrackResponse
bodyMapper: Mappers.TrackResponse,
isError: true
},
429: {
bodyMapper: Mappers.TrackResponse
bodyMapper: Mappers.TrackResponse,
isError: true
},
500: {
bodyMapper: Mappers.TrackResponse
bodyMapper: Mappers.TrackResponse,
isError: true
},
503: {
bodyMapper: Mappers.TrackResponse
bodyMapper: Mappers.TrackResponse,
isError: true
}
},
requestBody: Parameters.body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/

import * as coreHttp from "@azure/core-http";
import * as coreClient from "@azure/core-client";
import { ApplicationInsightsClientOptionalParams } from "./models";

const packageName = "@azure/monitor-opentelemetry-exporter";
const packageVersion = "1.0.0-beta.2";

export class ApplicationInsightsClientContext extends coreHttp.ServiceClient {
export class ApplicationInsightsClientContext extends coreClient.ServiceClient {
host: string;

/**
Expand All @@ -24,17 +21,25 @@ export class ApplicationInsightsClientContext extends coreHttp.ServiceClient {
if (!options) {
options = {};
}

if (!options.userAgent) {
const defaultUserAgent = coreHttp.getDefaultUserAgentValue();
options.userAgent = `${packageName}/${packageVersion} ${defaultUserAgent}`;
}

super(undefined, options);

this.requestContentType = "application/json; charset=utf-8";

this.baseUri = options.endpoint || "{Host}/v2";
const defaults: ApplicationInsightsClientOptionalParams = {
requestContentType: "application/json; charset=utf-8"
};

const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.4`;
const userAgentPrefix =
options.userAgentOptions && options.userAgentOptions.userAgentPrefix
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
: `${packageDetails}`;

const optionsWithDefaults = {
...defaults,
...options,
userAgentOptions: {
userAgentPrefix
},
baseUri: options.endpoint || "{Host}/v2"
};
super(optionsWithDefaults);

// Assigning values to Constant parameters
this.host = options.host || "https://dc.services.visualstudio.com";
Expand Down
Loading