Skip to content

Commit

Permalink
[Monitor Exporter] Move the Monitor package to use core-rest-pipeline (
Browse files Browse the repository at this point in the history
…#16513)

* fix pipeline

* init commit : update to use core-rest-pipeline

* remove 307 handling

* address comments

* format

* use custom redirect policy

* format

* udpate
  • Loading branch information
xiao-lix authored Jul 29, 2021
1 parent 95487e0 commit e402e50
Show file tree
Hide file tree
Showing 13 changed files with 616 additions and 745 deletions.
533 changes: 263 additions & 270 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

0 comments on commit e402e50

Please sign in to comment.