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

Updating OpenTelemetry version for Azure Exporter #13193

Merged
merged 5 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 1 addition & 2 deletions common/config/rush/common-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
// since there is a new 12.4-beta version which is being maintained in the repo
// To be reverted when the storage-blob releases a stable version.
"@azure/storage-blob": ["^12.3.0"],

"@azure/ms-rest-js": ["^2.0.0"],
/**
* For example, allow some projects to use an older TypeScript compiler
Expand All @@ -56,7 +55,7 @@
// ]
// Following is required to allow for backward compatibility with Event Processor Host Track 1
"@azure/event-hubs": ["^2.1.4"],

"@opentelemetry/api": ["^0.14.0"],
// Monitor: Allow node 10 types until Timeout / Timer conflict is resolved in OpenTelemetry repo
// TODO: remove when released https://github.com/open-telemetry/opentelemetry-js/pull/1352
"@types/node": ["^10.0.0"]
Expand Down
105 changes: 37 additions & 68 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions sdk/monitor/opentelemetry-exporter-azure-monitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@
},
"dependencies": {
"@azure/core-http": "^1.2.0",
"@opentelemetry/api": "^0.10.2",
"@opentelemetry/core": "^0.10.2",
"@opentelemetry/resources": "^0.10.2",
"@opentelemetry/semantic-conventions": "^0.10.2",
"@opentelemetry/tracing": "^0.10.2"
"@opentelemetry/api": "^0.14.0",
"@opentelemetry/core": "^0.14.0",
"@opentelemetry/resources": "^0.14.0",
"@opentelemetry/semantic-conventions": "^0.14.0",
"@opentelemetry/tracing": "^0.14.0"
},
"sideEffects": false,
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class AzureMonitorTraceExporter implements SpanExporter {
// (undocumented)
export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): Promise<void>;
// (undocumented)
shutdown(): void;
shutdown(): Promise<void>;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT license.

import { Logger } from "@opentelemetry/api";
import { ConsoleLogger, LogLevel, ExportResult } from "@opentelemetry/core";
import { ConsoleLogger, LogLevel, ExportResult, ExportResultCode } from "@opentelemetry/core";
import { ReadableSpan, SpanExporter } from "@opentelemetry/tracing";
import { RestError } from "@azure/core-http";
import { ConnectionStringParser } from "../utils/connectionStringParser";
Expand Down Expand Up @@ -65,9 +65,14 @@ export class AzureMonitorTraceExporter implements SpanExporter {
private async _persist(envelopes: unknown[]): Promise<ExportResult> {
try {
const success = await this._persister.push(envelopes);
return success ? ExportResult.FAILED_RETRYABLE : ExportResult.FAILED_NOT_RETRYABLE;
} catch (e) {
return ExportResult.FAILED_NOT_RETRYABLE;
return success
? { code: ExportResultCode.SUCCESS }
: {
code: ExportResultCode.FAILED,
error: new Error("Failed to persist envelope in disk.")
};
} catch (ex) {
return { code: ExportResultCode.FAILED, error: ex };
}
}

Expand All @@ -85,7 +90,7 @@ export class AzureMonitorTraceExporter implements SpanExporter {
}, this._options.batchSendRetryIntervalMs);
this._retryTimer.unref();
}
return ExportResult.SUCCESS;
return { code: ExportResultCode.SUCCESS };
} else if (statusCode && isRetriable(statusCode)) {
// Failed -- persist failed data
if (result) {
Expand All @@ -103,22 +108,23 @@ export class AzureMonitorTraceExporter implements SpanExporter {
}
} else {
// Failed -- not retriable
return ExportResult.FAILED_NOT_RETRYABLE;
return {
code: ExportResultCode.FAILED
};
}
} catch (senderErr) {
if (this._isNetworkError(senderErr)) {
this._logger.error(
"Retrying due to transient client side error. Error message:",
senderErr.message
);
return ExportResult.FAILED_RETRYABLE;
}
else {
return await this._persist(envelopes);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't technically need the await here

} else {
this._logger.error(
"Envelopes could not be exported and are not retriable. Error message:",
senderErr.message
);
return ExportResult.FAILED_NOT_RETRYABLE;
return { code: ExportResultCode.FAILED, error: senderErr };
}
}
}
Expand All @@ -134,9 +140,20 @@ export class AzureMonitorTraceExporter implements SpanExporter {
resultCallback(await this.exportEnvelopes(envelopes));
}

shutdown(): void {
shutdown(): Promise<void> {
this._logger.info("Azure Monitor Trace Exporter shutting down");
this._sender.shutdown();
return new Promise((resolve, reject) => {
Promise.resolve()
.then(() => {
return this._sender.shutdown();
})
.then(() => {
resolve();
})
.catch((e) => {
reject(e);
});
});
hectorhdzg marked this conversation as resolved.
Show resolved Hide resolved
}

private async _sendFirstPersistedFile(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { URL } from "url";
import { ReadableSpan } from "@opentelemetry/tracing";
import { hrTimeToMilliseconds } from "@opentelemetry/core";
import { SpanKind, Logger, CanonicalCode, Link } from "@opentelemetry/api";
import { SpanKind, Logger, StatusCode, Link } from "@opentelemetry/api";
import { SERVICE_RESOURCE } from "@opentelemetry/resources";
import { Tags, Properties, MSLink, Measurements } from "../types";
import {
Expand Down Expand Up @@ -43,10 +43,10 @@ function createTagsFromSpan(span: ReadableSpan): Tags {
if (span.parentSpanId) {
tags[AI_OPERATION_PARENT_ID] = span.parentSpanId;
}
if (span.resource && span.resource.labels) {
const serviceName = span.resource.labels[SERVICE_RESOURCE.NAME];
const serviceNamespace = span.resource.labels[SERVICE_RESOURCE.NAMESPACE];
const serviceInstanceId = span.resource.labels[SERVICE_RESOURCE.INSTANCE_ID];
if (span.resource && span.resource.attributes) {
const serviceName = span.resource.attributes[SERVICE_RESOURCE.NAME];
const serviceNamespace = span.resource.attributes[SERVICE_RESOURCE.NAMESPACE];
const serviceInstanceId = span.resource.attributes[SERVICE_RESOURCE.INSTANCE_ID];
if (serviceName) {
if (serviceNamespace) {
tags[AI_CLOUD_ROLE] = `${serviceNamespace}.${serviceName}`;
Expand Down Expand Up @@ -108,7 +108,7 @@ function createDependencyData(span: ReadableSpan): RemoteDependencyData {
const data: RemoteDependencyData = {
name: span.name,
id: `|${span.spanContext.traceId}.${span.spanContext.spanId}.`,
success: span.status.code === CanonicalCode.OK,
success: span.status.code === StatusCode.OK,
resultCode: String(span.status.code),
target: span.attributes[HTTP_URL] as string | undefined,
type: "Dependency",
Expand Down Expand Up @@ -162,7 +162,7 @@ function createRequestData(span: ReadableSpan): RequestData {
const data: RequestData = {
name: span.name,
id: `|${span.spanContext.traceId}.${span.spanContext.spanId}.`,
success: span.status.code === CanonicalCode.OK,
success: span.status.code === StatusCode.OK,
responseCode: String(span.status.code),
duration: msToTimeSpan(hrTimeToMilliseconds(span.duration)),
version: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ export class FlushSpanProcessor implements SpanProcessor {
private _spans: ReadableSpan[] = [];
constructor(public exporter: SpanExporter) {}

forceFlush(callback: () => void): void {
this.exporter.export(this._spans, () => {
this._spans = [];
callback();
forceFlush(): Promise<void> {
return Promise.resolve().then(() => {
this.exporter.export(this._spans, () => {
this._spans = [];
});
hectorhdzg marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand All @@ -23,7 +24,7 @@ export class FlushSpanProcessor implements SpanProcessor {
onEnd(span: ReadableSpan): void {
this._spans.push(span);
}
shutdown(): void {
// no op
shutdown(): Promise<void> {
return Promise.resolve();
}
}
Loading