From 224581319370af3e14f42f39c1a43bf3352655c7 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Tue, 12 Jan 2021 18:12:19 -0800 Subject: [PATCH 1/4] Updating Open Telemetry to latest version --- common/config/rush/common-versions.json | 21 +++- common/config/rush/pnpm-lock.yaml | 105 ++++++------------ .../package.json | 10 +- ...pentelemetry-exporter-azure-monitor.api.md | 2 +- .../src/export/trace.ts | 35 ++++-- .../src/utils/spanUtils.ts | 14 +-- .../test/common/flushSpanProcessor.ts | 19 ++-- .../test/common/scenario/basic.ts | 16 ++- .../test/functional/trace.test.ts | 2 +- .../test/unit/export/trace.test.ts | 14 +-- .../test/unit/utils/eventhub.test.ts | 5 +- .../test/unit/utils/spanUtils.test.ts | 24 ++-- 12 files changed, 135 insertions(+), 132 deletions(-) diff --git a/common/config/rush/common-versions.json b/common/config/rush/common-versions.json index 7863c2776b88..4f51e8bfb6d8 100644 --- a/common/config/rush/common-versions.json +++ b/common/config/rush/common-versions.json @@ -44,9 +44,12 @@ // The following is required for eventhubs-checkpointstore-blob, // 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"], + "@azure/storage-blob": [ + "^12.3.0" + ], + "@azure/ms-rest-js": [ + "^2.0.0" + ], /** * For example, allow some projects to use an older TypeScript compiler * (in addition to whatever "usual" version is being used by other projects in the repo): @@ -55,10 +58,16 @@ // "~2.4.0" // ] // Following is required to allow for backward compatibility with Event Processor Host Track 1 - "@azure/event-hubs": ["^2.1.4"], - + "@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"] + "@types/node": [ + "^10.0.0" + ] } } diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index a4623da43dfe..8ed59bfdaa2a 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -602,6 +602,14 @@ packages: node: '>=8.0.0' resolution: integrity: sha512-GtpMGd6vkzDMYcpu2t9LlhEgMy/SzBwRnz48EejlRArYqZzqSzAsKmegUK7zHgl+EOIaK9mKHhnRaQu3qw20cA== + /@opentelemetry/api/0.14.0: + dependencies: + '@opentelemetry/context-base': 0.14.0 + dev: false + engines: + node: '>=8.0.0' + resolution: + integrity: sha512-L7RMuZr5LzMmZiQSQDy9O1jo0q+DaLy6XpYJfIGfYSfoJA5qzYwUP3sP1uMIQ549DvxAgM3ng85EaPTM/hUHwQ== /@opentelemetry/api/0.6.1: dependencies: '@opentelemetry/context-base': 0.6.1 @@ -616,49 +624,55 @@ packages: node: '>=8.0.0' resolution: integrity: sha512-hZNKjKOYsckoOEgBziGMnBcX0M7EtstnCmwz5jZUOUYwlZ+/xxX6z3jPu1XVO2Jivk0eLfuP9GP+vFD49CMetw== + /@opentelemetry/context-base/0.14.0: + dev: false + engines: + node: '>=8.0.0' + resolution: + integrity: sha512-sDOAZcYwynHFTbLo6n8kIbLiVF3a3BLkrmehJUyEbT9F+Smbi47kLGS2gG2g0fjBLR/Lr1InPD7kXL7FaTqEkw== /@opentelemetry/context-base/0.6.1: dev: false engines: node: '>=8.0.0' resolution: integrity: sha512-5bHhlTBBq82ti3qPT15TRxkYTFPPQWbnkkQkmHPtqiS1XcTB69cEKd3Jm7Cfi/vkPoyxapmePE9tyA7EzLt8SQ== - /@opentelemetry/core/0.10.2: + /@opentelemetry/core/0.14.0: dependencies: - '@opentelemetry/api': 0.10.2 - '@opentelemetry/context-base': 0.10.2 + '@opentelemetry/api': 0.14.0 + '@opentelemetry/context-base': 0.14.0 semver: 7.3.4 dev: false engines: node: '>=8.5.0' resolution: - integrity: sha512-DhkiTp5eje2zTGd+HAIKWpGE6IR6lq7tUpYt4nnkhOi6Hq9WQAANVDCWEZEbYOw57LkdXbE50FZ/kMvHDm450Q== - /@opentelemetry/resources/0.10.2: + integrity: sha512-HJ4VM0cV6c5qjdW7C7koB2IT4ADunCOehxnKFRslQkbDqAEA1w42AZ9679siYALpWYxNqcJyqF2jxCNtfNHa6Q== + /@opentelemetry/resources/0.14.0: dependencies: - '@opentelemetry/api': 0.10.2 - '@opentelemetry/core': 0.10.2 - gcp-metadata: 3.5.0 + '@opentelemetry/api': 0.14.0 + '@opentelemetry/core': 0.14.0 dev: false engines: node: '>=8.0.0' resolution: - integrity: sha512-5JGC2TPSAIHth615IURt+sSsTljY43zTfJD0JE9PHC6ipZPiQ0dpQDZOrLn8NAMfOHY1jeWwpIuLASjqbXUfuw== - /@opentelemetry/semantic-conventions/0.10.2: + integrity: sha512-7XVML4HxvoH6kWY+x0mhMc5m0a2YBvPCTSX7yAqyp9XIGvFpdjzAE2ggJ40DZrL1sPv9f0QYAbnIKFDVLBTfGA== + /@opentelemetry/semantic-conventions/0.14.0: dev: false engines: node: '>=8.0.0' resolution: - integrity: sha512-AaXFy0uR6JlQkDzkCKYiGeJDxEhdqnadAyqiiD0T9p77yjRkCGwydz6/HTp0G80ZdeBZp4w9jZ961yuD5E7lyw== - /@opentelemetry/tracing/0.10.2: + integrity: sha512-iDGRLQwo+ka1ljlLo4KyuUmzsJwtPw+PyCjetQwn3m/pTXjdyWLGOTARBrpQGpkQp7k87RaCCg5AqZaKFU2G6g== + /@opentelemetry/tracing/0.14.0: dependencies: - '@opentelemetry/api': 0.10.2 - '@opentelemetry/context-base': 0.10.2 - '@opentelemetry/core': 0.10.2 - '@opentelemetry/resources': 0.10.2 + '@opentelemetry/api': 0.14.0 + '@opentelemetry/context-base': 0.14.0 + '@opentelemetry/core': 0.14.0 + '@opentelemetry/resources': 0.14.0 + '@opentelemetry/semantic-conventions': 0.14.0 dev: false engines: node: '>=8.0.0' resolution: - integrity: sha512-mNAhARn4dEdOjTa9OdysjI4fRHMbvr4YSbPuH7jhkyPzgoa+DnvnbY3GGpEay6kpuYJsrW8Ef9OIKAV/GndhbQ== + integrity: sha512-sw9lXJQUQO0xaCvHWFUzIhgh2jGFgXubRQ6g1O84Q/ILU93ZMMVt+d97mihcrtBrV89Sy39HF8tAwekjpzv+cA== /@rollup/plugin-commonjs/11.0.2_rollup@1.32.1: dependencies: '@rollup/pluginutils': 3.1.0_rollup@1.32.1 @@ -1240,14 +1254,6 @@ packages: dev: false resolution: integrity: sha1-kbR5JYinc4wl813W9jdSovh3YTU= - /abort-controller/3.0.0: - dependencies: - event-target-shim: 5.0.1 - dev: false - engines: - node: '>=6.5' - resolution: - integrity: sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg== /accepts/1.3.7: dependencies: mime-types: 2.1.27 @@ -1692,10 +1698,6 @@ packages: dev: false resolution: integrity: sha1-QIZrnhueC1W0gYlDEeaPr/rrxSI= - /bignumber.js/9.0.1: - dev: false - resolution: - integrity: sha512-IdZR9mh6ahOBv/hYGiXyVuyCetmGJhtYkqLBpTStdhEGjegpPlUawydyaF3pbIOFynJTpllEs+NP+CS9jKFLjA== /binary-extensions/2.1.0: dev: false engines: @@ -2938,12 +2940,6 @@ packages: node: '>= 0.6' resolution: integrity: sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc= - /event-target-shim/5.0.1: - dev: false - engines: - node: '>=6' - resolution: - integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ== /eventemitter3/4.0.7: dev: false resolution: @@ -3363,27 +3359,6 @@ packages: optional: true resolution: integrity: sha1-LANAXHU4w51+s3sxcCLjJfsBi/c= - /gaxios/2.3.4: - dependencies: - abort-controller: 3.0.0 - extend: 3.0.2 - https-proxy-agent: 5.0.0 - is-stream: 2.0.0 - node-fetch: 2.6.1 - dev: false - engines: - node: '>=8.10.0' - resolution: - integrity: sha512-US8UMj8C5pRnao3Zykc4AAVr+cffoNKRTg9Rsf2GiuZCW69vgJj38VK2PzlPuQU73FZ/nTk9/Av6/JGcE1N9vA== - /gcp-metadata/3.5.0: - dependencies: - gaxios: 2.3.4 - json-bigint: 0.3.1 - dev: false - engines: - node: '>=8.10.0' - resolution: - integrity: sha512-ZQf+DLZ5aKcRpLzYUyBS3yo3N0JSa82lNDO8rj3nMSlovLcz2riKFBsYgDzeXcv75oo5eqB2lx+B14UvPoCRnA== /gensync/1.0.0-beta.2: dev: false engines: @@ -4362,12 +4337,6 @@ packages: hasBin: true resolution: integrity: sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA== - /json-bigint/0.3.1: - dependencies: - bignumber.js: 9.0.1 - dev: false - resolution: - integrity: sha512-DGWnSzmusIreWlEupsUelHrhwmPPE+FiQvg+drKfk2p+bdEYa5mp4PJ8JsCWqae0M2jQNb0HPvnwvf1qOTThzQ== /json-edm-parser/0.1.2: dependencies: jsonparse: 1.2.0 @@ -9857,11 +9826,11 @@ packages: 'file:projects/opentelemetry-exporter-azure-monitor.tgz': dependencies: '@microsoft/api-extractor': 7.7.11 - '@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 '@types/mocha': 7.0.2 '@types/node': 10.17.49 eslint: 7.15.0 @@ -9879,7 +9848,7 @@ packages: dev: false name: '@rush-temp/opentelemetry-exporter-azure-monitor' resolution: - integrity: sha512-2D1De0nKkSxPnE6MpmIIxJlQgBzVhZG0+WV7bH/A+SAEkbPnCaZc4x06S55r1HqHEkaed5jAKAD/w34dcK+lFA== + integrity: sha512-1YDWRJ3nfnzkb4A/gPy7qComvRV3S+pLTD6MqjqKLxZt3P9b2uwF9K4j4zixj+M3LrZ48S4y1G770wSyxMsF6g== tarball: 'file:projects/opentelemetry-exporter-azure-monitor.tgz' version: 0.0.0 'file:projects/schema-registry-avro.tgz': diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/package.json b/sdk/monitor/opentelemetry-exporter-azure-monitor/package.json index 62931380e6e6..41b39e7324f2 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/package.json +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/package.json @@ -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": [ diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/review/opentelemetry-exporter-azure-monitor.api.md b/sdk/monitor/opentelemetry-exporter-azure-monitor/review/opentelemetry-exporter-azure-monitor.api.md index 7490c791e7cf..b17fa3024f6e 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/review/opentelemetry-exporter-azure-monitor.api.md +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/review/opentelemetry-exporter-azure-monitor.api.md @@ -20,7 +20,7 @@ export class AzureMonitorTraceExporter implements SpanExporter { // (undocumented) export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): Promise; // (undocumented) - shutdown(): void; + shutdown(): Promise; } diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts index 64c64e049e3f..e624c1dcf2b6 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts @@ -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"; @@ -65,9 +65,11 @@ export class AzureMonitorTraceExporter implements SpanExporter { private async _persist(envelopes: unknown[]): Promise { 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 }; } } @@ -85,7 +87,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) { @@ -103,7 +105,9 @@ export class AzureMonitorTraceExporter implements SpanExporter { } } else { // Failed -- not retriable - return ExportResult.FAILED_NOT_RETRYABLE; + return { + code: ExportResultCode.FAILED + }; } } catch (senderErr) { if (this._isNetworkError(senderErr)) { @@ -111,14 +115,14 @@ export class AzureMonitorTraceExporter implements SpanExporter { "Retrying due to transient client side error. Error message:", senderErr.message ); - return ExportResult.FAILED_RETRYABLE; + 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 }; } } } @@ -134,9 +138,20 @@ export class AzureMonitorTraceExporter implements SpanExporter { resultCallback(await this.exportEnvelopes(envelopes)); } - shutdown(): void { + shutdown(): Promise { 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); + }); + }); } private async _sendFirstPersistedFile(): Promise { diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/utils/spanUtils.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/utils/spanUtils.ts index 73f244232c43..d5981081e977 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/utils/spanUtils.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/utils/spanUtils.ts @@ -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 { @@ -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}`; @@ -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", @@ -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, diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts index 1972523adbe7..96523c53b610 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts @@ -8,13 +8,16 @@ import { ReadableSpan, SpanExporter, SpanProcessor } from "@opentelemetry/tracin */ export class FlushSpanProcessor implements SpanProcessor { private _spans: ReadableSpan[] = []; - constructor(public exporter: SpanExporter) {} + constructor(public exporter: SpanExporter) { } + + forceFlush(): Promise { + return Promise.resolve() + .then(() => { + this.exporter.export(this._spans, () => { + this._spans = []; + }); + }); - forceFlush(callback: () => void): void { - this.exporter.export(this._spans, () => { - this._spans = []; - callback(); - }); } onStart(): void { @@ -23,7 +26,7 @@ export class FlushSpanProcessor implements SpanProcessor { onEnd(span: ReadableSpan): void { this._spans.push(span); } - shutdown(): void { - // no op + shutdown(): Promise { + return Promise.resolve(); } } diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/scenario/basic.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/scenario/basic.ts index 7e10539d9f09..0f352af60f80 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/scenario/basic.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/scenario/basic.ts @@ -6,7 +6,7 @@ import { BasicTracerProvider } from "@opentelemetry/tracing"; import { AzureMonitorTraceExporter } from "../../../src"; import { Expectation, Scenario } from "./types"; import { msToTimeSpan } from "../../../src/utils/breezeUtils"; -import { CanonicalCode } from "@opentelemetry/api"; +import { StatusCode } from "@opentelemetry/api"; import { FlushSpanProcessor } from "../flushSpanProcessor"; import { delay } from "@azure/core-http"; import { TelemetryItem as Envelope } from "../../../src/generated"; @@ -40,7 +40,6 @@ export class BasicScenario implements Scenario { await tracer.withSpan(root, async () => { const child1 = tracer.startSpan(`${this.constructor.name}.Child.1`, { startTime: 0, - parent: root, kind: opentelemetry.SpanKind.CLIENT, attributes: { numbers: "123" @@ -49,23 +48,22 @@ export class BasicScenario implements Scenario { const child2 = tracer.startSpan(`${this.constructor.name}.Child.2`, { startTime: 0, - parent: root, kind: opentelemetry.SpanKind.CLIENT, attributes: { numbers: "1234" - } + }, }); tracer.withSpan(child1, () => { - child1.setStatus({ code: CanonicalCode.OK }); + child1.setStatus({ code: StatusCode.OK }); child1.end(100); }); await delay(0); - child2.setStatus({ code: CanonicalCode.OK }); + child2.setStatus({ code: StatusCode.OK }); child2.end(100); - root.setStatus({ code: CanonicalCode.OK }); + root.setStatus({ code: StatusCode.OK }); root.end(600); }); } @@ -74,8 +72,8 @@ export class BasicScenario implements Scenario { opentelemetry.trace.disable(); } - flush(callback: () => void): void { - processor.forceFlush(callback); + flush(): Promise { + return processor.forceFlush(); } expectation: Expectation[] = [ diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/functional/trace.test.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/functional/trace.test.ts index b189bb7514d1..641e5b98ddca 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/functional/trace.test.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/functional/trace.test.ts @@ -39,7 +39,7 @@ describe("Trace Exporter Scenarios", () => { .run() .then(() => { // promisify doesn't work on this, so use callbacks/done for now - return scenario.flush(() => { + return scenario.flush().then(() => { assertExpectation(ingest, scenario.expectation); assertCount(ingest, scenario.expectation); done(); diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/unit/export/trace.test.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/unit/export/trace.test.ts index c312db8b9667..5e3f3dd1598a 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/unit/export/trace.test.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/unit/export/trace.test.ts @@ -2,7 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; -import { ExportResult } from "@opentelemetry/core"; +import { ExportResult, ExportResultCode } from "@opentelemetry/core"; import { AzureMonitorTraceExporter } from "../../../src/export/trace"; import { DEFAULT_BREEZE_ENDPOINT } from "../../../src/Declarations/Constants"; import { @@ -72,7 +72,7 @@ describe("#AzureMonitorBaseExporter", () => { scope.reply(429, JSON.stringify(response)); const result = await exporter.exportEnvelopesPrivate([envelope]); - assert.strictEqual(result, ExportResult.FAILED_RETRYABLE); + assert.strictEqual(result.code, ExportResultCode.SUCCESS); const persistedEnvelopes = (await exporter["_persister"].shift()) as Envelope[]; assert.strictEqual(persistedEnvelopes?.length, 1); @@ -85,7 +85,7 @@ describe("#AzureMonitorBaseExporter", () => { scope.reply(206, JSON.stringify(response)); const result = await exporter.exportEnvelopesPrivate([envelope, envelope, envelope]); - assert.strictEqual(result, ExportResult.FAILED_RETRYABLE); + assert.strictEqual(result.code, ExportResultCode.SUCCESS); const persistedEnvelopes = (await exporter["_persister"].shift()) as Envelope[]; assert.strictEqual(persistedEnvelopes?.length, 2); @@ -97,7 +97,7 @@ describe("#AzureMonitorBaseExporter", () => { scope.reply(400, JSON.stringify(response)); const result = await exporter.exportEnvelopesPrivate([envelope]); - assert.strictEqual(result, ExportResult.FAILED_NOT_RETRYABLE); + assert.strictEqual(result.code, ExportResultCode.FAILED); const persistedEnvelopes = await exporter["_persister"].shift(); assert.strictEqual(persistedEnvelopes, null); @@ -108,7 +108,7 @@ describe("#AzureMonitorBaseExporter", () => { scope.reply(1, ""); // httpSender will throw const result = await exporter.exportEnvelopesPrivate([envelope]); - assert.strictEqual(result, ExportResult.FAILED_NOT_RETRYABLE); + assert.strictEqual(result.code, ExportResultCode.FAILED); const persistedEnvelopes = await exporter["_persister"].shift(); assert.strictEqual(persistedEnvelopes, null); @@ -120,7 +120,7 @@ describe("#AzureMonitorBaseExporter", () => { scope.reply(200, JSON.stringify(response)); const result = await exporter.exportEnvelopesPrivate([envelope]); - assert.strictEqual(result, ExportResult.SUCCESS); + assert.strictEqual(result.code, ExportResultCode.SUCCESS); assert.notStrictEqual(exporter["_retryTimer"], null); clearTimeout(exporter["_retryTimer"]!); @@ -134,7 +134,7 @@ describe("#AzureMonitorBaseExporter", () => { scope.reply(200, JSON.stringify(response)); const result = await exporter.exportEnvelopesPrivate([envelope]); - assert.strictEqual(result, ExportResult.SUCCESS); + assert.strictEqual(result.code, ExportResultCode.SUCCESS); assert.strictEqual(exporter["_retryTimer"], "foo"); }); }); diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/unit/utils/eventhub.test.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/unit/utils/eventhub.test.ts index d3a8fb4cc213..8dd321a389c7 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/unit/utils/eventhub.test.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/unit/utils/eventhub.test.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { Attributes, HrTime, SpanContext, SpanKind } from "@opentelemetry/api"; +import { Attributes, HrTime, SpanContext, SpanKind, ROOT_CONTEXT } from "@opentelemetry/api"; import { NoopLogger, timeInputToHrTime } from "@opentelemetry/core"; import { BasicTracerProvider, Span } from "@opentelemetry/tracing"; import * as assert from "assert"; @@ -34,6 +34,7 @@ describe("#parseEventHubSpan(...)", () => { const envelope = { data: { baseData: {} } } as Envelope; const span = new Span( tracer, + ROOT_CONTEXT, "test span", { traceId: "traceid", spanId: "spanId", traceFlags: 0 }, SpanKind.CLIENT @@ -54,6 +55,7 @@ describe("#parseEventHubSpan(...)", () => { const envelope = { data: { baseData: {} } } as Envelope; const span = new Span( tracer, + ROOT_CONTEXT, "test span", { traceId: "traceid", spanId: "spanId", traceFlags: 0 }, SpanKind.PRODUCER @@ -75,6 +77,7 @@ describe("#parseEventHubSpan(...)", () => { const envelope = { data: { baseData: {} } } as Envelope; const span = new Span( tracer, + ROOT_CONTEXT, "test span", { traceId: "traceid", spanId: "spanId", traceFlags: 0 }, SpanKind.CONSUMER, diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/unit/utils/spanUtils.test.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/unit/utils/spanUtils.test.ts index b57545b35faf..0e09b852aba8 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/unit/utils/spanUtils.test.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/unit/utils/spanUtils.test.ts @@ -2,7 +2,7 @@ // Licensed under the MIT license. import { Span, BasicTracerProvider, TracerConfig } from "@opentelemetry/tracing"; -import { SpanKind, CanonicalCode } from "@opentelemetry/api"; +import { SpanKind, StatusCode, ROOT_CONTEXT } from "@opentelemetry/api"; import * as assert from "assert"; import { NoopLogger, hrTimeToMilliseconds } from "@opentelemetry/core"; import { Resource, SERVICE_RESOURCE } from "@opentelemetry/resources"; @@ -86,6 +86,7 @@ describe("spanUtils.ts", () => { it("should create a Request Envelope for Server Spans", () => { const span = new Span( tracer, + ROOT_CONTEXT, "parent span", { traceId: "traceid", spanId: "spanId", traceFlags: 0 }, SpanKind.SERVER, @@ -93,14 +94,14 @@ describe("spanUtils.ts", () => { ); span.setAttributes({ "extra.attribute": "foo", - [grpc.GRPC_STATUS_CODE]: CanonicalCode.OK, + [grpc.GRPC_STATUS_CODE]: StatusCode.OK, [grpc.GRPC_KIND]: SpanKind.SERVER, [grpc.GRPC_METHOD]: "/foo.Example/Foo", [grpc.GRPC_ERROR_MESSAGE]: "some error message", [grpc.GRPC_ERROR_NAME]: "some error name" }); span.setStatus({ - code: CanonicalCode.OK + code: StatusCode.OK }); span.end(); const expectedTags: Tags = { @@ -141,6 +142,7 @@ describe("spanUtils.ts", () => { it("should create a Dependency Envelope for Client Spans", () => { const span = new Span( tracer, + ROOT_CONTEXT, "parent span", { traceId: "traceid", spanId: "spanId", traceFlags: 0 }, SpanKind.CLIENT, @@ -148,14 +150,14 @@ describe("spanUtils.ts", () => { ); span.setAttributes({ "extra.attribute": "foo", - [grpc.GRPC_STATUS_CODE]: CanonicalCode.OK, + [grpc.GRPC_STATUS_CODE]: StatusCode.OK, [grpc.GRPC_KIND]: SpanKind.CLIENT, [grpc.GRPC_METHOD]: "/foo.Example/Foo", [grpc.GRPC_ERROR_MESSAGE]: "some error message", [grpc.GRPC_ERROR_NAME]: "some error name" }); span.setStatus({ - code: CanonicalCode.OK + code: StatusCode.OK }); span.end(); const expectedTags: Tags = { @@ -198,6 +200,7 @@ describe("spanUtils.ts", () => { it("should create a Request Envelope for Server Spans", () => { const span = new Span( tracer, + ROOT_CONTEXT, "parent span", { traceId: "traceid", spanId: "spanId", traceFlags: 0 }, SpanKind.SERVER, @@ -207,7 +210,7 @@ describe("spanUtils.ts", () => { "extra.attribute": "foo" }); span.setStatus({ - code: CanonicalCode.OK + code: StatusCode.OK }); span.end(); const expectedTime = new Date(hrTimeToMilliseconds(span.startTime)); @@ -247,6 +250,7 @@ describe("spanUtils.ts", () => { it("should create a Dependency Envelope for Client Spans", () => { const span = new Span( tracer, + ROOT_CONTEXT, "parent span", { traceId: "traceid", spanId: "spanId", traceFlags: 0 }, SpanKind.CLIENT, @@ -256,7 +260,7 @@ describe("spanUtils.ts", () => { "extra.attribute": "foo" }); span.setStatus({ - code: CanonicalCode.OK + code: StatusCode.OK }); span.end(); const expectedTags: Tags = { @@ -297,6 +301,7 @@ describe("spanUtils.ts", () => { it("(HTTP) should create a Request Envelope for Server Spans", () => { const span = new Span( tracer, + ROOT_CONTEXT, "parent span", { traceId: "traceid", spanId: "spanId", traceFlags: 0 }, SpanKind.SERVER, @@ -310,7 +315,7 @@ describe("spanUtils.ts", () => { "extra.attribute": "foo" }); span.setStatus({ - code: CanonicalCode.OK + code: StatusCode.OK }); span.end(); const expectedTags: Tags = { @@ -351,6 +356,7 @@ describe("spanUtils.ts", () => { it("should create a Dependency Envelope for Client Spans", () => { const span = new Span( tracer, + ROOT_CONTEXT, "parent span", { traceId: "traceid", spanId: "spanId", traceFlags: 0 }, SpanKind.CLIENT, @@ -363,7 +369,7 @@ describe("spanUtils.ts", () => { "extra.attribute": "foo" }); span.setStatus({ - code: CanonicalCode.OK + code: StatusCode.OK }); span.end(); const expectedTags: Tags = { From b999e9a2b7b9c73c0b220ca79ba2607bf44a7af0 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Tue, 12 Jan 2021 18:12:43 -0800 Subject: [PATCH 2/4] Updating to latest OR --- common/config/rush/common-versions.json | 20 +++++-------------- .../src/export/trace.ts | 14 +++++++------ .../test/common/flushSpanProcessor.ts | 12 +++++------ .../test/common/scenario/basic.ts | 2 +- 4 files changed, 19 insertions(+), 29 deletions(-) diff --git a/common/config/rush/common-versions.json b/common/config/rush/common-versions.json index 4f51e8bfb6d8..0858387ce872 100644 --- a/common/config/rush/common-versions.json +++ b/common/config/rush/common-versions.json @@ -44,12 +44,8 @@ // The following is required for eventhubs-checkpointstore-blob, // 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" - ], + "@azure/storage-blob": ["^12.3.0"], + "@azure/ms-rest-js": ["^2.0.0"], /** * For example, allow some projects to use an older TypeScript compiler * (in addition to whatever "usual" version is being used by other projects in the repo): @@ -58,16 +54,10 @@ // "~2.4.0" // ] // 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" - ], + "@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" - ] + "@types/node": ["^10.0.0"] } } diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts index e624c1dcf2b6..c4824cac13c4 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts @@ -65,9 +65,12 @@ export class AzureMonitorTraceExporter implements SpanExporter { private async _persist(envelopes: unknown[]): Promise { try { const success = await this._persister.push(envelopes); - return success ? { code: ExportResultCode.SUCCESS } : { - code: ExportResultCode.FAILED, error: new Error("Failed to persist envelope in disk.") - } + 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 }; } @@ -116,8 +119,7 @@ export class AzureMonitorTraceExporter implements SpanExporter { senderErr.message ); return await this._persist(envelopes); - } - else { + } else { this._logger.error( "Envelopes could not be exported and are not retriable. Error message:", senderErr.message @@ -148,7 +150,7 @@ export class AzureMonitorTraceExporter implements SpanExporter { .then(() => { resolve(); }) - .catch(e => { + .catch((e) => { reject(e); }); }); diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts index 96523c53b610..6aeac3970454 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts @@ -8,16 +8,14 @@ import { ReadableSpan, SpanExporter, SpanProcessor } from "@opentelemetry/tracin */ export class FlushSpanProcessor implements SpanProcessor { private _spans: ReadableSpan[] = []; - constructor(public exporter: SpanExporter) { } + constructor(public exporter: SpanExporter) {} forceFlush(): Promise { - return Promise.resolve() - .then(() => { - this.exporter.export(this._spans, () => { - this._spans = []; - }); + return Promise.resolve().then(() => { + this.exporter.export(this._spans, () => { + this._spans = []; }); - + }); } onStart(): void { diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/scenario/basic.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/scenario/basic.ts index 0f352af60f80..a3d68db74b77 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/scenario/basic.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/scenario/basic.ts @@ -51,7 +51,7 @@ export class BasicScenario implements Scenario { kind: opentelemetry.SpanKind.CLIENT, attributes: { numbers: "1234" - }, + } }); tracer.withSpan(child1, () => { From f4f1f91ed1d19a91f5a769d5f6a437df35689513 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Wed, 13 Jan 2021 11:13:40 -0800 Subject: [PATCH 3/4] Addressing comments --- .../src/export/trace.ts | 21 +++++-------------- .../src/platform/nodejs/httpSender.ts | 2 +- .../src/types.ts | 2 +- .../test/common/flushSpanProcessor.ts | 5 +++-- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts index c4824cac13c4..25c3f24be65d 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts @@ -68,9 +68,9 @@ export class AzureMonitorTraceExporter implements SpanExporter { return success ? { code: ExportResultCode.SUCCESS } : { - code: ExportResultCode.FAILED, - error: new Error("Failed to persist envelope in disk.") - }; + code: ExportResultCode.FAILED, + error: new Error("Failed to persist envelope in disk.") + }; } catch (ex) { return { code: ExportResultCode.FAILED, error: ex }; } @@ -140,20 +140,9 @@ export class AzureMonitorTraceExporter implements SpanExporter { resultCallback(await this.exportEnvelopes(envelopes)); } - shutdown(): Promise { + async shutdown(): Promise { this._logger.info("Azure Monitor Trace Exporter shutting down"); - return new Promise((resolve, reject) => { - Promise.resolve() - .then(() => { - return this._sender.shutdown(); - }) - .then(() => { - resolve(); - }) - .catch((e) => { - reject(e); - }); - }); + return this._sender.shutdown(); } private async _sendFirstPersistedFile(): Promise { diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/platform/nodejs/httpSender.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/platform/nodejs/httpSender.ts index 9c51247d5e5f..2a6c0e911218 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/platform/nodejs/httpSender.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/platform/nodejs/httpSender.ts @@ -35,7 +35,7 @@ export class HttpSender implements Sender { } } - shutdown(): void { + async shutdown(): Promise { this._logger.info("HttpSender shutting down"); } } diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/types.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/types.ts index 17fd2bfb6913..5b395ffabb3f 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/types.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/types.ts @@ -15,7 +15,7 @@ export type SenderResult = { statusCode: number; result: string }; export interface Sender { send(payload: unknown[]): Promise; - shutdown(): void; + shutdown(): Promise; } export interface PersistentStorage { diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts index 6aeac3970454..ad7f543e9a75 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts @@ -8,12 +8,13 @@ import { ReadableSpan, SpanExporter, SpanProcessor } from "@opentelemetry/tracin */ export class FlushSpanProcessor implements SpanProcessor { private _spans: ReadableSpan[] = []; - constructor(public exporter: SpanExporter) {} + constructor(public exporter: SpanExporter) { } forceFlush(): Promise { - return Promise.resolve().then(() => { + return new Promise((resolve) => { this.exporter.export(this._spans, () => { this._spans = []; + resolve(); }); }); } From 101c9c778f4d29755d286a36ad1dd69ac06335a5 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Wed, 13 Jan 2021 11:14:18 -0800 Subject: [PATCH 4/4] Addressing comments --- .../src/export/trace.ts | 6 +++--- .../test/common/flushSpanProcessor.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts index 25c3f24be65d..ef6dbe6b9937 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts @@ -68,9 +68,9 @@ export class AzureMonitorTraceExporter implements SpanExporter { return success ? { code: ExportResultCode.SUCCESS } : { - code: ExportResultCode.FAILED, - error: new Error("Failed to persist envelope in disk.") - }; + code: ExportResultCode.FAILED, + error: new Error("Failed to persist envelope in disk.") + }; } catch (ex) { return { code: ExportResultCode.FAILED, error: ex }; } diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts index ad7f543e9a75..c04b822cd20f 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts @@ -8,7 +8,7 @@ import { ReadableSpan, SpanExporter, SpanProcessor } from "@opentelemetry/tracin */ export class FlushSpanProcessor implements SpanProcessor { private _spans: ReadableSpan[] = []; - constructor(public exporter: SpanExporter) { } + constructor(public exporter: SpanExporter) {} forceFlush(): Promise { return new Promise((resolve) => {