From ddd59287b1022b39c4bc26ba1ba3ffacc8ab005d Mon Sep 17 00:00:00 2001 From: xiao-lix Date: Wed, 23 Jun 2021 15:57:24 -0700 Subject: [PATCH 01/11] [Monitor Exporter] Separate tests into internal and public folders --- .../package.json | 6 +++--- .../connectionStringParser.test.ts | 4 ++-- .../{unit/utils => internal}/eventhub.test.ts | 8 ++++---- .../fileSystemPersist.test.ts | 4 ++-- .../{ => internal}/functional/trace.test.ts | 10 +++++----- .../nodejs => internal}/httpSender.test.ts | 10 +++++----- .../utils => internal}/spanUtils.test.ts | 20 +++++++++---------- .../trace.exporter.test.ts} | 10 +++++----- .../test/{common => utils}/assert.ts | 5 ++--- .../test/{common/scenario => utils}/basic.ts | 8 ++++---- .../test/{unit => utils}/breezeTestUtils.ts | 0 .../{common => utils}/flushSpanProcessor.ts | 0 .../test/{common/scenario => utils}/types.ts | 2 +- 13 files changed, 43 insertions(+), 44 deletions(-) rename sdk/monitor/monitor-opentelemetry-exporter/test/{unit/utils => internal}/connectionStringParser.test.ts (97%) rename sdk/monitor/monitor-opentelemetry-exporter/test/{unit/utils => internal}/eventhub.test.ts (94%) rename sdk/monitor/monitor-opentelemetry-exporter/test/{unit/platform/nodejs/persist => internal}/fileSystemPersist.test.ts (96%) rename sdk/monitor/monitor-opentelemetry-exporter/test/{ => internal}/functional/trace.test.ts (79%) rename sdk/monitor/monitor-opentelemetry-exporter/test/{unit/platform/nodejs => internal}/httpSender.test.ts (85%) rename sdk/monitor/monitor-opentelemetry-exporter/test/{unit/utils => internal}/spanUtils.test.ts (94%) rename sdk/monitor/monitor-opentelemetry-exporter/test/{unit/export/trace.test.ts => public/trace.exporter.test.ts} (96%) rename sdk/monitor/monitor-opentelemetry-exporter/test/{common => utils}/assert.ts (97%) rename sdk/monitor/monitor-opentelemetry-exporter/test/{common/scenario => utils}/basic.ts (93%) rename sdk/monitor/monitor-opentelemetry-exporter/test/{unit => utils}/breezeTestUtils.ts (100%) rename sdk/monitor/monitor-opentelemetry-exporter/test/{common => utils}/flushSpanProcessor.ts (100%) rename sdk/monitor/monitor-opentelemetry-exporter/test/{common/scenario => utils}/types.ts (80%) diff --git a/sdk/monitor/monitor-opentelemetry-exporter/package.json b/sdk/monitor/monitor-opentelemetry-exporter/package.json index 401274c6075b..ad86db244dc8 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/package.json +++ b/sdk/monitor/monitor-opentelemetry-exporter/package.json @@ -23,11 +23,11 @@ "test:node": "npm run unit-test:node", "test:browser": "npm run unit-test:browser", "unit-test:browser": "echo skipped", - "unit-test:node": "nyc mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/unit/**/*.test.ts\"", - "unit-test:node:debug": "nyc mocha --inspect-brk -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/unit/**/*.test.ts\"", + "unit-test:node": "nyc mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/internal/**/*.test.ts\" \"test/public/**/*.test.ts\"", + "unit-test:node:debug": "nyc mocha --inspect-brk -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/internal/**/*.test.ts\" \"test/public/**/*.test.ts\"", "unit-test:node:no-timeout": "echo skipped", "unit-test": "npm run unit-test:node && npm run unit-test:browser", - "functional-test": "nyc mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/functional/**/*.test.ts\"", + "functional-test": "nyc mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/internal/functional/*.test.ts\"", "integration-test:browser": "echo skipped", "integration-test:node": "npm run functional-test", "integration-test": "npm run integration-test:node && npm run integration-test:browser", diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/utils/connectionStringParser.test.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/connectionStringParser.test.ts similarity index 97% rename from sdk/monitor/monitor-opentelemetry-exporter/test/unit/utils/connectionStringParser.test.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/internal/connectionStringParser.test.ts index e00aab1bf7e6..54f8a6fb4ebe 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/utils/connectionStringParser.test.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/connectionStringParser.test.ts @@ -2,8 +2,8 @@ // Licensed under the MIT license. import * as assert from "assert"; -import * as Constants from "../../../src/Declarations/Constants"; -import { ConnectionStringParser } from "../../../src/utils/connectionStringParser"; +import * as Constants from "../../src/Declarations/Constants"; +import { ConnectionStringParser } from "../../src/utils/connectionStringParser"; describe("ConnectionStringParser", () => { describe("#parse()", () => { diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/utils/eventhub.test.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/eventhub.test.ts similarity index 94% rename from sdk/monitor/monitor-opentelemetry-exporter/test/unit/utils/eventhub.test.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/internal/eventhub.test.ts index afc80c84f4d1..9e10c02b74cc 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/utils/eventhub.test.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/eventhub.test.ts @@ -8,14 +8,14 @@ import * as assert from "assert"; import { ENQUEUED_TIME, TIME_SINCE_ENQUEUED -} from "../../../src/utils/constants/applicationinsights"; +} from "../../src/utils/constants/applicationinsights"; import { AzNamespace, MessageBusDestination, MicrosoftEventHub -} from "../../../src/utils/constants/span/azAttributes"; -import { parseEventHubSpan } from "../../../src/utils/eventhub"; -import { RemoteDependencyData, TelemetryItem as Envelope } from "../../../src/generated"; +} from "../../src/utils/constants/span/azAttributes"; +import { parseEventHubSpan } from "../../src/utils/eventhub"; +import { RemoteDependencyData, TelemetryItem as Envelope } from "../../src/generated"; const tracer = new BasicTracerProvider().getTracer("default"); diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/platform/nodejs/persist/fileSystemPersist.test.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/fileSystemPersist.test.ts similarity index 96% rename from sdk/monitor/monitor-opentelemetry-exporter/test/unit/platform/nodejs/persist/fileSystemPersist.test.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/internal/fileSystemPersist.test.ts index e3af385fcc01..24809ea87eb3 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/platform/nodejs/persist/fileSystemPersist.test.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/fileSystemPersist.test.ts @@ -5,8 +5,8 @@ import * as assert from "assert"; import * as fs from "fs"; import * as os from "os"; import * as path from "path"; -import { FileSystemPersist } from "../../../../../src/platform/nodejs/persist/fileSystemPersist"; -import { TelemetryItem as Envelope } from "../../../../../src/generated"; +import { FileSystemPersist } from "../../src/platform/nodejs/persist/fileSystemPersist"; +import { TelemetryItem as Envelope } from "../../src/generated"; import { promisify } from "util"; const statAsync = promisify(fs.stat); diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/functional/trace.test.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/functional/trace.test.ts similarity index 79% rename from sdk/monitor/monitor-opentelemetry-exporter/test/functional/trace.test.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/internal/functional/trace.test.ts index 990611c4a18f..f09a7f8f5bf1 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/functional/trace.test.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/functional/trace.test.ts @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { assertCount, assertExpectation } from "../common/assert"; -import { BasicScenario } from "../common/scenario/basic"; -import { DEFAULT_BREEZE_ENDPOINT } from "../../src/Declarations/Constants"; +import { assertCount, assertExpectation } from "../../utils/assert"; +import { BasicScenario } from "../../utils/basic"; +import { DEFAULT_BREEZE_ENDPOINT } from "../../../src/Declarations/Constants"; import nock from "nock"; -import { successfulBreezeResponse } from "../unit/breezeTestUtils"; -import { TelemetryItem as Envelope } from "../../src/generated"; +import { successfulBreezeResponse } from "../../utils/breezeTestUtils"; +import { TelemetryItem as Envelope } from "../../../src/generated"; describe("Trace Exporter Scenarios", () => { describe(BasicScenario.prototype.constructor.name, () => { diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/platform/nodejs/httpSender.test.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/httpSender.test.ts similarity index 85% rename from sdk/monitor/monitor-opentelemetry-exporter/test/unit/platform/nodejs/httpSender.test.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/internal/httpSender.test.ts index 88aa2d746cfc..87e889cffa59 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/platform/nodejs/httpSender.test.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/httpSender.test.ts @@ -2,15 +2,15 @@ // Licensed under the MIT license. import * as assert from "assert"; -import { DEFAULT_EXPORTER_CONFIG } from "../../../../src/config"; -import { HttpSender } from "../../../../src/platform/nodejs/httpSender"; -import { DEFAULT_BREEZE_ENDPOINT } from "../../../../src/Declarations/Constants"; +import { DEFAULT_EXPORTER_CONFIG } from "../../src/config"; +import { HttpSender } from "../../src/platform/nodejs/httpSender"; +import { DEFAULT_BREEZE_ENDPOINT } from "../../src/Declarations/Constants"; import { successfulBreezeResponse, failedBreezeResponse, partialBreezeResponse -} from "../../breezeTestUtils"; -import { TelemetryItem as Envelope } from "../../../../src/generated"; +} from "../utils/breezeTestUtils"; +import { TelemetryItem as Envelope } from "../../src/generated"; import nock from "nock"; describe("HttpSender", () => { diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/utils/spanUtils.test.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/spanUtils.test.ts similarity index 94% rename from sdk/monitor/monitor-opentelemetry-exporter/test/unit/utils/spanUtils.test.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/internal/spanUtils.test.ts index 21d82113840a..23d969124364 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/utils/spanUtils.test.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/spanUtils.test.ts @@ -7,19 +7,19 @@ import * as assert from "assert"; import { hrTimeToMilliseconds } from "@opentelemetry/core"; import { Resource, SERVICE_RESOURCE } from "@opentelemetry/resources"; -import { Tags, Properties, Measurements } from "../../../src/types"; +import { Tags, Properties, Measurements } from "../../src/types"; import { AI_CLOUD_ROLE, AI_CLOUD_ROLE_INSTACE -} from "../../../src/utils/constants/applicationinsights"; -import * as http from "../../../src/utils/constants/span/httpAttributes"; -import * as grpc from "../../../src/utils/constants/span/grpcAttributes"; -import * as ai from "../../../src/utils/constants/applicationinsights"; -import { Context, getInstance } from "../../../src/platform"; -import { msToTimeSpan } from "../../../src/utils/breezeUtils"; -import { readableSpanToEnvelope } from "../../../src/utils/spanUtils"; -import { RemoteDependencyData, RequestData } from "../../../src/generated"; -import { TelemetryItem as Envelope } from "../../../src/generated"; +} from "../../src/utils/constants/applicationinsights"; +import * as http from "../../src/utils/constants/span/httpAttributes"; +import * as grpc from "../../src/utils/constants/span/grpcAttributes"; +import * as ai from "../../src/utils/constants/applicationinsights"; +import { Context, getInstance } from "../../src/platform"; +import { msToTimeSpan } from "../../src/utils/breezeUtils"; +import { readableSpanToEnvelope } from "../../src/utils/spanUtils"; +import { RemoteDependencyData, RequestData } from "../../src/generated"; +import { TelemetryItem as Envelope } from "../../src/generated"; const context = getInstance(undefined, "./"); diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/export/trace.test.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/public/trace.exporter.test.ts similarity index 96% rename from sdk/monitor/monitor-opentelemetry-exporter/test/unit/export/trace.test.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/public/trace.exporter.test.ts index ee9293616d2f..48d5a2203dcf 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/export/trace.test.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/public/trace.exporter.test.ts @@ -3,15 +3,15 @@ import * as assert from "assert"; import { ExportResult, ExportResultCode } from "@opentelemetry/core"; -import { AzureMonitorTraceExporter } from "../../../src/export/trace"; -import { DEFAULT_BREEZE_ENDPOINT } from "../../../src/Declarations/Constants"; +import { AzureMonitorTraceExporter } from "../../src/export/trace"; +import { DEFAULT_BREEZE_ENDPOINT } from "../../src/Declarations/Constants"; import { failedBreezeResponse, partialBreezeResponse, successfulBreezeResponse -} from "../breezeTestUtils"; -import { FileSystemPersist, HttpSender } from "../../../src/platform"; -import { TelemetryItem as Envelope } from "../../../src/generated"; +} from "../utils/breezeTestUtils"; +import { FileSystemPersist, HttpSender } from "../../src/platform"; +import { TelemetryItem as Envelope } from "../../src/generated"; import nock from "nock"; function toObject(obj: T): T { diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/common/assert.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts similarity index 97% rename from sdk/monitor/monitor-opentelemetry-exporter/test/common/assert.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts index 809fd79fecc1..097282e30548 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/common/assert.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts @@ -6,7 +6,7 @@ import { AI_OPERATION_ID, AI_OPERATION_PARENT_ID } from "../../src/utils/constants/applicationinsights"; -import { Expectation } from "./scenario/types"; +import { Expectation } from "./types"; import { MonitorBase, RequestData, TelemetryItem as Envelope } from "../../src/generated"; import { TelemetryItem as EnvelopeMapper } from "../../src/generated/models/mappers"; @@ -81,8 +81,7 @@ export const assertExpectation = (actual: Envelope[], expectations: Expectation[ if (envelope.length !== 1) { assert.ok( false, - `assertExpectation: could not find exported envelope: ${ - (expectation.data?.baseData as RequestData).name + `assertExpectation: could not find exported envelope: ${(expectation.data?.baseData as RequestData).name }` ); } diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/common/scenario/basic.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts similarity index 93% rename from sdk/monitor/monitor-opentelemetry-exporter/test/common/scenario/basic.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts index a817f620469e..346de86564ea 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/common/scenario/basic.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts @@ -3,13 +3,13 @@ import * as opentelemetry from "@opentelemetry/api"; import { BasicTracerProvider } from "@opentelemetry/tracing"; -import { AzureMonitorTraceExporter } from "../../../src"; +import { AzureMonitorTraceExporter } from "../../src"; import { Expectation, Scenario } from "./types"; -import { msToTimeSpan } from "../../../src/utils/breezeUtils"; +import { msToTimeSpan } from "../../src/utils/breezeUtils"; import { SpanStatusCode } from "@opentelemetry/api"; -import { FlushSpanProcessor } from "../flushSpanProcessor"; +import { FlushSpanProcessor } from "./flushSpanProcessor"; import { delay } from "@azure/core-http"; -import { TelemetryItem as Envelope } from "../../../src/generated"; +import { TelemetryItem as Envelope } from "../../src/generated"; const COMMON_ENVELOPE_PARAMS: Partial = { instrumentationKey: process.env.APPINSIGHTS_INSTRUMENTATIONKEY || "ikey", diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/breezeTestUtils.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/breezeTestUtils.ts similarity index 100% rename from sdk/monitor/monitor-opentelemetry-exporter/test/unit/breezeTestUtils.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/utils/breezeTestUtils.ts diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/common/flushSpanProcessor.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/flushSpanProcessor.ts similarity index 100% rename from sdk/monitor/monitor-opentelemetry-exporter/test/common/flushSpanProcessor.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/utils/flushSpanProcessor.ts diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/common/scenario/types.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/types.ts similarity index 80% rename from sdk/monitor/monitor-opentelemetry-exporter/test/common/scenario/types.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/utils/types.ts index 5b5eeb784978..0ec01b69706a 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/common/scenario/types.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/types.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { TelemetryItem as Envelope } from "../../../src/generated"; +import { TelemetryItem as Envelope } from "../../src/generated"; export interface Expectation extends Partial { children: Expectation[]; From 51f540198f4949fc557b2a9f8540cf7498e6c963 Mon Sep 17 00:00:00 2001 From: xiao-lix Date: Wed, 23 Jun 2021 17:31:35 -0700 Subject: [PATCH 02/11] fix build --- .../test/internal/eventhub.test.ts | 5 +---- .../test/public/trace.exporter.test.ts | 3 ++- .../monitor-opentelemetry-exporter/test/utils/assert.ts | 3 ++- sdk/monitor/monitor-opentelemetry-exporter/tests.yml | 2 -- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/internal/eventhub.test.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/eventhub.test.ts index 9e10c02b74cc..7303ed4a393a 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/internal/eventhub.test.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/eventhub.test.ts @@ -5,10 +5,7 @@ import { SpanAttributes, HrTime, SpanContext, SpanKind, ROOT_CONTEXT } from "@op import { timeInputToHrTime } from "@opentelemetry/core"; import { BasicTracerProvider, Span } from "@opentelemetry/tracing"; import * as assert from "assert"; -import { - ENQUEUED_TIME, - TIME_SINCE_ENQUEUED -} from "../../src/utils/constants/applicationinsights"; +import { ENQUEUED_TIME, TIME_SINCE_ENQUEUED } from "../../src/utils/constants/applicationinsights"; import { AzNamespace, MessageBusDestination, diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/public/trace.exporter.test.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/public/trace.exporter.test.ts index 48d5a2203dcf..06729c603f34 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/public/trace.exporter.test.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/public/trace.exporter.test.ts @@ -4,7 +4,6 @@ import * as assert from "assert"; import { ExportResult, ExportResultCode } from "@opentelemetry/core"; import { AzureMonitorTraceExporter } from "../../src/export/trace"; -import { DEFAULT_BREEZE_ENDPOINT } from "../../src/Declarations/Constants"; import { failedBreezeResponse, partialBreezeResponse, @@ -18,6 +17,8 @@ function toObject(obj: T): T { return JSON.parse(JSON.stringify(obj)) as T; } +const DEFAULT_BREEZE_ENDPOINT = "https://dc.services.visualstudio.com"; + describe("#AzureMonitorBaseExporter", () => { class TestExporter extends AzureMonitorTraceExporter { private thisAsAny: any; diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts index 097282e30548..5c6576928b86 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts @@ -81,7 +81,8 @@ export const assertExpectation = (actual: Envelope[], expectations: Expectation[ if (envelope.length !== 1) { assert.ok( false, - `assertExpectation: could not find exported envelope: ${(expectation.data?.baseData as RequestData).name + `assertExpectation: could not find exported envelope: ${ + (expectation.data?.baseData as RequestData).name }` ); } diff --git a/sdk/monitor/monitor-opentelemetry-exporter/tests.yml b/sdk/monitor/monitor-opentelemetry-exporter/tests.yml index a94d18d16d84..e903fad293c7 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/tests.yml +++ b/sdk/monitor/monitor-opentelemetry-exporter/tests.yml @@ -6,7 +6,5 @@ stages: TimeoutInMinutes: 15 PackageName: "@azure/monitor-opentelemetry-exporter" ServiceDirectory: monitor - MatrixFilters: - - DependencyVersion=^$ PostSteps: - template: /eng/pipelines/templates/steps/monitor-additional-steps.yml From e709a6a708a8d295716c991253f68516dd02e670 Mon Sep 17 00:00:00 2001 From: xiao-lix Date: Thu, 24 Jun 2021 16:01:36 -0700 Subject: [PATCH 03/11] put tests in internal --- .../trace.exporter.test.ts | 3 +- .../test/utils/basic.ts | 13 ++++---- .../test/utils/flushSpanProcessor.ts | 31 ------------------- .../monitor-opentelemetry-exporter/tests.yml | 2 ++ 4 files changed, 10 insertions(+), 39 deletions(-) rename sdk/monitor/monitor-opentelemetry-exporter/test/{public => internal}/trace.exporter.test.ts (99%) delete mode 100644 sdk/monitor/monitor-opentelemetry-exporter/test/utils/flushSpanProcessor.ts diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/public/trace.exporter.test.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/trace.exporter.test.ts similarity index 99% rename from sdk/monitor/monitor-opentelemetry-exporter/test/public/trace.exporter.test.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/internal/trace.exporter.test.ts index 910424859ed3..3ff576079e19 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/public/trace.exporter.test.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/trace.exporter.test.ts @@ -4,6 +4,7 @@ import * as assert from "assert"; import { ExportResult, ExportResultCode } from "@opentelemetry/core"; import { AzureMonitorTraceExporter } from "../../src/export/trace"; +import { DEFAULT_BREEZE_ENDPOINT } from "../../src/Declarations/Constants"; import { failedBreezeResponse, partialBreezeResponse, @@ -17,8 +18,6 @@ function toObject(obj: T): T { return JSON.parse(JSON.stringify(obj)) as T; } -const DEFAULT_BREEZE_ENDPOINT = "https://dc.services.visualstudio.com"; - describe("#AzureMonitorBaseExporter", () => { class TestExporter extends AzureMonitorTraceExporter { private thisAsAny: any; diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts index a340233201ee..6ef827228c93 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts @@ -2,12 +2,11 @@ // Licensed under the MIT license. import * as opentelemetry from "@opentelemetry/api"; -import { BasicTracerProvider } from "@opentelemetry/tracing"; +import { BasicTracerProvider, SimpleSpanProcessor } from "@opentelemetry/tracing"; import { AzureMonitorTraceExporter } from "../../src"; import { Expectation, Scenario } from "./types"; import { msToTimeSpan } from "../../src/utils/breezeUtils"; import { SpanStatusCode } from "@opentelemetry/api"; -import { FlushSpanProcessor } from "./flushSpanProcessor"; import { delay } from "@azure/core-http"; import { TelemetryItem as Envelope } from "../../src/generated"; @@ -19,13 +18,13 @@ const COMMON_ENVELOPE_PARAMS: Partial = { const exporter = new AzureMonitorTraceExporter({ connectionString: `instrumentationkey=${COMMON_ENVELOPE_PARAMS.instrumentationKey}` }); -const processor = new FlushSpanProcessor(exporter); +const processor = new SimpleSpanProcessor(exporter); export class BasicScenario implements Scenario { prepare(): void { const provider = new BasicTracerProvider(); provider.addSpanProcessor(processor); - opentelemetry.trace.setGlobalTracerProvider(provider); + provider.register(); } async run(): Promise { @@ -37,20 +36,22 @@ export class BasicScenario implements Scenario { foo: "bar" } }); + + const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), root); const child1 = tracer.startSpan(`${this.constructor.name}.Child.1`, { startTime: 0, kind: opentelemetry.SpanKind.CLIENT, attributes: { numbers: "123" } - }); + }, ctx); const child2 = tracer.startSpan(`${this.constructor.name}.Child.2`, { startTime: 0, kind: opentelemetry.SpanKind.CLIENT, attributes: { numbers: "1234" } - }); + }, ctx); child1.setStatus({ code: SpanStatusCode.OK }); child1.end(100); await delay(0); diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/flushSpanProcessor.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/flushSpanProcessor.ts deleted file mode 100644 index c04b822cd20f..000000000000 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/flushSpanProcessor.ts +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import { ReadableSpan, SpanExporter, SpanProcessor } from "@opentelemetry/tracing"; - -/** - * Span Processor that only exports spans on flush - */ -export class FlushSpanProcessor implements SpanProcessor { - private _spans: ReadableSpan[] = []; - constructor(public exporter: SpanExporter) {} - - forceFlush(): Promise { - return new Promise((resolve) => { - this.exporter.export(this._spans, () => { - this._spans = []; - resolve(); - }); - }); - } - - onStart(): void { - // no op - } - onEnd(span: ReadableSpan): void { - this._spans.push(span); - } - shutdown(): Promise { - return Promise.resolve(); - } -} diff --git a/sdk/monitor/monitor-opentelemetry-exporter/tests.yml b/sdk/monitor/monitor-opentelemetry-exporter/tests.yml index e903fad293c7..a94d18d16d84 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/tests.yml +++ b/sdk/monitor/monitor-opentelemetry-exporter/tests.yml @@ -6,5 +6,7 @@ stages: TimeoutInMinutes: 15 PackageName: "@azure/monitor-opentelemetry-exporter" ServiceDirectory: monitor + MatrixFilters: + - DependencyVersion=^$ PostSteps: - template: /eng/pipelines/templates/steps/monitor-additional-steps.yml From 6fcd4a4fff93930dc92d7a5015e1754a756d5d1c Mon Sep 17 00:00:00 2001 From: xiao-lix Date: Thu, 24 Jun 2021 16:19:25 -0700 Subject: [PATCH 04/11] prettier --- .../test/utils/basic.ts | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts index 6ef827228c93..d72b9ef1783e 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts @@ -38,20 +38,28 @@ export class BasicScenario implements Scenario { }); const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), root); - const child1 = tracer.startSpan(`${this.constructor.name}.Child.1`, { - startTime: 0, - kind: opentelemetry.SpanKind.CLIENT, - attributes: { - numbers: "123" - } - }, ctx); - const child2 = tracer.startSpan(`${this.constructor.name}.Child.2`, { - startTime: 0, - kind: opentelemetry.SpanKind.CLIENT, - attributes: { - numbers: "1234" - } - }, ctx); + const child1 = tracer.startSpan( + `${this.constructor.name}.Child.1`, + { + startTime: 0, + kind: opentelemetry.SpanKind.CLIENT, + attributes: { + numbers: "123" + } + }, + ctx + ); + const child2 = tracer.startSpan( + `${this.constructor.name}.Child.2`, + { + startTime: 0, + kind: opentelemetry.SpanKind.CLIENT, + attributes: { + numbers: "1234" + } + }, + ctx + ); child1.setStatus({ code: SpanStatusCode.OK }); child1.end(100); await delay(0); From d1ca83028dc577220d36d846c84a12a8b29b6378 Mon Sep 17 00:00:00 2001 From: xiao-lix Date: Fri, 25 Jun 2021 14:36:34 -0700 Subject: [PATCH 05/11] console log for testing --- .../package.json | 4 +-- .../test/utils/assert.ts | 26 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/sdk/monitor/monitor-opentelemetry-exporter/package.json b/sdk/monitor/monitor-opentelemetry-exporter/package.json index aec79e0bfb78..80c9b9c47131 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/package.json +++ b/sdk/monitor/monitor-opentelemetry-exporter/package.json @@ -23,8 +23,8 @@ "test:node": "npm run unit-test:node", "test:browser": "npm run unit-test:browser", "unit-test:browser": "echo skipped", - "unit-test:node": "nyc mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/internal/**/*.test.ts\" \"test/public/**/*.test.ts\"", - "unit-test:node:debug": "nyc mocha --inspect-brk -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/internal/**/*.test.ts\" \"test/public/**/*.test.ts\"", + "unit-test:node": "nyc mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/internal/**/*.test.ts\"", + "unit-test:node:debug": "nyc mocha --inspect-brk -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/internal/**/*.test.ts\"", "unit-test:node:no-timeout": "echo skipped", "unit-test": "npm run unit-test:node && npm run unit-test:browser", "functional-test": "nyc mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/internal/functional/*.test.ts\"", diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts index 5c6576928b86..0536551f7ca2 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts @@ -27,10 +27,17 @@ export const assertData = (actual: MonitorBase, expected: MonitorBase): void => }; export const assertTrace = (actual: Envelope[], expectation: Expectation): void => { + console.log('inside assertTrace method: '); + console.log('actual: '); + console.log(actual); + console.log('expectation: '); + console.log(expectation); const envelope = actual.filter( (e) => (e.data!.baseData as RequestData).name === (expectation.data!.baseData as RequestData).name ); + console.log('envelope: '); + console.log(envelope); if (envelope.length !== 1) { assert.ok(false, `assertTrace: could not find exported envelope: ${expectation.name}`); } @@ -73,16 +80,29 @@ export const assertCount = (actual: Envelope[], expectations: Expectation[]): vo }; export const assertExpectation = (actual: Envelope[], expectations: Expectation[]): void => { + console.log('inside assertExpectation method: '); + console.log('actual: '); + console.log(actual); + console.log('expectations: '); + console.log(expectations); for (const expectation of expectations) { + console.log('expectation: '); + console.log(expectation); const envelope = actual.filter( - (e) => + (e) => { + console.log('e.data.baseData'); + console.log(e.data!.baseData); + console.log('expectation.data!.baseData'); + console.log(expectation.data!.baseData); (e.data!.baseData as RequestData).name === (expectation.data!.baseData as RequestData).name + } ); + console.log('envelope: '); + console.log(envelope); if (envelope.length !== 1) { assert.ok( false, - `assertExpectation: could not find exported envelope: ${ - (expectation.data?.baseData as RequestData).name + `assertExpectation: could not find exported envelope: ${(expectation.data?.baseData as RequestData).name }` ); } From dde67280e29e01d65a055de9e05eb5fd4b9592e6 Mon Sep 17 00:00:00 2001 From: xiao-lix Date: Fri, 25 Jun 2021 15:21:53 -0700 Subject: [PATCH 06/11] testing --- .../test/utils/assert.ts | 33 ++++--------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts index 0536551f7ca2..042cd3f8a069 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts @@ -27,17 +27,11 @@ export const assertData = (actual: MonitorBase, expected: MonitorBase): void => }; export const assertTrace = (actual: Envelope[], expectation: Expectation): void => { - console.log('inside assertTrace method: '); - console.log('actual: '); - console.log(actual); - console.log('expectation: '); - console.log(expectation); const envelope = actual.filter( - (e) => - (e.data!.baseData as RequestData).name === (expectation.data!.baseData as RequestData).name + (e) => { + return (e.data!.baseData as RequestData).name === (expectation.data!.baseData as RequestData).name + } ); - console.log('envelope: '); - console.log(envelope); if (envelope.length !== 1) { assert.ok(false, `assertTrace: could not find exported envelope: ${expectation.name}`); } @@ -80,25 +74,12 @@ export const assertCount = (actual: Envelope[], expectations: Expectation[]): vo }; export const assertExpectation = (actual: Envelope[], expectations: Expectation[]): void => { - console.log('inside assertExpectation method: '); - console.log('actual: '); - console.log(actual); - console.log('expectations: '); - console.log(expectations); for (const expectation of expectations) { - console.log('expectation: '); - console.log(expectation); - const envelope = actual.filter( - (e) => { - console.log('e.data.baseData'); - console.log(e.data!.baseData); - console.log('expectation.data!.baseData'); - console.log(expectation.data!.baseData); + const envelope = actual.filter((e) => { + return ( (e.data!.baseData as RequestData).name === (expectation.data!.baseData as RequestData).name - } - ); - console.log('envelope: '); - console.log(envelope); + ); + }); if (envelope.length !== 1) { assert.ok( false, From 1ef02f59a5dc64e7c9be6f4109ec77147226c00a Mon Sep 17 00:00:00 2001 From: xiao-lix Date: Fri, 25 Jun 2021 15:29:34 -0700 Subject: [PATCH 07/11] format --- .../test/utils/assert.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts index 042cd3f8a069..03873ab3bb1e 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts @@ -27,11 +27,11 @@ export const assertData = (actual: MonitorBase, expected: MonitorBase): void => }; export const assertTrace = (actual: Envelope[], expectation: Expectation): void => { - const envelope = actual.filter( - (e) => { - return (e.data!.baseData as RequestData).name === (expectation.data!.baseData as RequestData).name - } - ); + const envelope = actual.filter((e) => { + return ( + (e.data!.baseData as RequestData).name === (expectation.data!.baseData as RequestData).name + ); + }); if (envelope.length !== 1) { assert.ok(false, `assertTrace: could not find exported envelope: ${expectation.name}`); } @@ -83,7 +83,8 @@ export const assertExpectation = (actual: Envelope[], expectations: Expectation[ if (envelope.length !== 1) { assert.ok( false, - `assertExpectation: could not find exported envelope: ${(expectation.data?.baseData as RequestData).name + `assertExpectation: could not find exported envelope: ${ + (expectation.data?.baseData as RequestData).name }` ); } From 4ac95362342ccf02830908fee03b288c5873ce7d Mon Sep 17 00:00:00 2001 From: xiao-lix Date: Fri, 25 Jun 2021 15:47:36 -0700 Subject: [PATCH 08/11] console --- .../test/utils/assert.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts index 03873ab3bb1e..72eb218a4b37 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts @@ -74,8 +74,19 @@ export const assertCount = (actual: Envelope[], expectations: Expectation[]): vo }; export const assertExpectation = (actual: Envelope[], expectations: Expectation[]): void => { + console.log("inside assertExpectation method: "); + console.log("actual: "); + console.log(actual); + console.log("expectasions: "); + console.log(expectations); for (const expectation of expectations) { const envelope = actual.filter((e) => { + console.log("e: "); + console.log(e); + console.log("e.data!.baseData"); + console.log(e.data!.baseData); + console.log("expectation.data!.baseData"); + console.log(expectation.data!.baseData); return ( (e.data!.baseData as RequestData).name === (expectation.data!.baseData as RequestData).name ); From 72c31272caa4397515376b8b93d53ff981192532 Mon Sep 17 00:00:00 2001 From: xiao-lix Date: Fri, 25 Jun 2021 16:42:11 -0700 Subject: [PATCH 09/11] try flush processor --- .../test/utils/basic.ts | 5 +-- .../test/utils/flushSpanProcessor.ts | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 sdk/monitor/monitor-opentelemetry-exporter/test/utils/flushSpanProcessor.ts diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts index d72b9ef1783e..e0f3fe5e730a 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts @@ -2,13 +2,14 @@ // Licensed under the MIT license. import * as opentelemetry from "@opentelemetry/api"; -import { BasicTracerProvider, SimpleSpanProcessor } from "@opentelemetry/tracing"; +import { BasicTracerProvider } from "@opentelemetry/tracing"; import { AzureMonitorTraceExporter } from "../../src"; import { Expectation, Scenario } from "./types"; import { msToTimeSpan } from "../../src/utils/breezeUtils"; import { SpanStatusCode } from "@opentelemetry/api"; import { delay } from "@azure/core-http"; import { TelemetryItem as Envelope } from "../../src/generated"; +import { FlushSpanProcessor } from "./flushSpanProcessor"; const COMMON_ENVELOPE_PARAMS: Partial = { instrumentationKey: process.env.APPINSIGHTS_INSTRUMENTATIONKEY || "ikey", @@ -18,7 +19,7 @@ const COMMON_ENVELOPE_PARAMS: Partial = { const exporter = new AzureMonitorTraceExporter({ connectionString: `instrumentationkey=${COMMON_ENVELOPE_PARAMS.instrumentationKey}` }); -const processor = new SimpleSpanProcessor(exporter); +const processor = new FlushSpanProcessor(exporter); export class BasicScenario implements Scenario { prepare(): void { diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/flushSpanProcessor.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/flushSpanProcessor.ts new file mode 100644 index 000000000000..ad7f543e9a75 --- /dev/null +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/flushSpanProcessor.ts @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { ReadableSpan, SpanExporter, SpanProcessor } from "@opentelemetry/tracing"; + +/** + * Span Processor that only exports spans on flush + */ +export class FlushSpanProcessor implements SpanProcessor { + private _spans: ReadableSpan[] = []; + constructor(public exporter: SpanExporter) { } + + forceFlush(): Promise { + return new Promise((resolve) => { + this.exporter.export(this._spans, () => { + this._spans = []; + resolve(); + }); + }); + } + + onStart(): void { + // no op + } + onEnd(span: ReadableSpan): void { + this._spans.push(span); + } + shutdown(): Promise { + return Promise.resolve(); + } +} From aeee6eba62f9f3eb3794012907d5f4b937fdafbe Mon Sep 17 00:00:00 2001 From: xiao-lix Date: Fri, 25 Jun 2021 16:43:00 -0700 Subject: [PATCH 10/11] format --- .../test/utils/flushSpanProcessor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/flushSpanProcessor.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/flushSpanProcessor.ts index ad7f543e9a75..c04b822cd20f 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/flushSpanProcessor.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/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) => { From d14546fe59465cd2ca81fe55f63c92cc515fbb91 Mon Sep 17 00:00:00 2001 From: xiao-lix Date: Fri, 25 Jun 2021 16:59:06 -0700 Subject: [PATCH 11/11] remove console logs --- .../test/utils/assert.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts index 72eb218a4b37..03873ab3bb1e 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts @@ -74,19 +74,8 @@ export const assertCount = (actual: Envelope[], expectations: Expectation[]): vo }; export const assertExpectation = (actual: Envelope[], expectations: Expectation[]): void => { - console.log("inside assertExpectation method: "); - console.log("actual: "); - console.log(actual); - console.log("expectasions: "); - console.log(expectations); for (const expectation of expectations) { const envelope = actual.filter((e) => { - console.log("e: "); - console.log(e); - console.log("e.data!.baseData"); - console.log(e.data!.baseData); - console.log("expectation.data!.baseData"); - console.log(expectation.data!.baseData); return ( (e.data!.baseData as RequestData).name === (expectation.data!.baseData as RequestData).name );