diff --git a/common/config/rush/common-versions.json b/common/config/rush/common-versions.json index 05d6bb4a6b9d..674cfa2f1d00 100644 --- a/common/config/rush/common-versions.json +++ b/common/config/rush/common-versions.json @@ -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"] diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 1ffee339183b..5bbdacc5255f 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 @@ -1693,10 +1699,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: @@ -2939,12 +2941,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: @@ -3378,27 +3374,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: @@ -4389,12 +4364,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 @@ -9917,11 +9886,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 @@ -9939,8 +9908,8 @@ packages: dev: false name: '@rush-temp/opentelemetry-exporter-azure-monitor' resolution: - integrity: sha512-2D1De0nKkSxPnE6MpmIIxJlQgBzVhZG0+WV7bH/A+SAEkbPnCaZc4x06S55r1HqHEkaed5jAKAD/w34dcK+lFA== - tarball: file:projects/opentelemetry-exporter-azure-monitor.tgz + integrity: sha512-1YDWRJ3nfnzkb4A/gPy7qComvRV3S+pLTD6MqjqKLxZt3P9b2uwF9K4j4zixj+M3LrZ48S4y1G770wSyxMsF6g== + tarball: 'file:projects/opentelemetry-exporter-azure-monitor.tgz' version: 0.0.0 file:projects/schema-registry-avro.tgz: dependencies: diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/package.json b/sdk/monitor/opentelemetry-exporter-azure-monitor/package.json index ada3736cb9c6..0e27213a1d66 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/package.json +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/package.json @@ -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, 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..ef6dbe6b9937 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,14 @@ 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 +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) { @@ -103,7 +108,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 +118,13 @@ export class AzureMonitorTraceExporter implements SpanExporter { "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 }; } } } @@ -134,9 +140,9 @@ export class AzureMonitorTraceExporter implements SpanExporter { resultCallback(await this.exportEnvelopes(envelopes)); } - shutdown(): void { + async shutdown(): Promise { this._logger.info("Azure Monitor Trace Exporter shutting down"); - this._sender.shutdown(); + 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/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..c04b822cd20f 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/test/common/flushSpanProcessor.ts @@ -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 { + return new Promise((resolve) => { + this.exporter.export(this._spans, () => { + this._spans = []; + resolve(); + }); }); } @@ -23,7 +25,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..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 @@ -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,7 +48,6 @@ 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" @@ -57,15 +55,15 @@ export class BasicScenario implements Scenario { }); 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 516b9412ec66..884545d3ddf7 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 = {