Skip to content

Commit

Permalink
Updating OpenTelemetry version for Azure Exporter (Azure#13193)
Browse files Browse the repository at this point in the history
* Updating Open Telemetry to latest version

* Updating to latest OR

* Addressing comments

* Addressing comments
  • Loading branch information
hectorhdzg authored and ljian3377 committed Jan 22, 2021
1 parent 37fe016 commit c8f9173
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 129 deletions.
2 changes: 1 addition & 1 deletion common/config/rush/common-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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
107 changes: 38 additions & 69 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 @@ -83,11 +83,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",
"tslib": "^2.0.0"
},
"sideEffects": false,
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);
} 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,9 @@ export class AzureMonitorTraceExporter implements SpanExporter {
resultCallback(await this.exportEnvelopes(envelopes));
}

shutdown(): void {
async shutdown(): Promise<void> {
this._logger.info("Azure Monitor Trace Exporter shutting down");
this._sender.shutdown();
return this._sender.shutdown();
}

private async _sendFirstPersistedFile(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class HttpSender implements Sender {
}
}

shutdown(): void {
async shutdown(): Promise<void> {
this._logger.info("HttpSender shutting down");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type SenderResult = { statusCode: number; result: string };

export interface Sender {
send(payload: unknown[]): Promise<SenderResult>;
shutdown(): void;
shutdown(): Promise<void>;
}

export interface PersistentStorage {
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,12 @@ 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 new Promise((resolve) => {
this.exporter.export(this._spans, () => {
this._spans = [];
resolve();
});
});
}

Expand All @@ -23,7 +25,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

0 comments on commit c8f9173

Please sign in to comment.