diff --git a/sdk/monitor/monitor-opentelemetry-exporter/package.json b/sdk/monitor/monitor-opentelemetry-exporter/package.json index 5bd37efa024f..80c9b9c47131 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\"", + "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/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 93% 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..7303ed4a393a 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/utils/eventhub.test.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/eventhub.test.ts @@ -5,17 +5,14 @@ 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, 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 cf5309d182f0..ecd32f7bdff7 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 ad82fb80e4d5..f16fe42b9bdf 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/utils/spanUtils.test.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/spanUtils.test.ts @@ -8,19 +8,19 @@ import { hrTimeToMilliseconds } from "@opentelemetry/core"; import { Resource } from "@opentelemetry/resources"; import { ResourceAttributes } from "@opentelemetry/semantic-conventions"; -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/internal/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/internal/trace.exporter.test.ts index 88db775e3d62..3ff576079e19 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/test/unit/export/trace.test.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/test/internal/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 95% rename from sdk/monitor/monitor-opentelemetry-exporter/test/common/assert.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/utils/assert.ts index 809fd79fecc1..03873ab3bb1e 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"; @@ -27,10 +27,11 @@ export const assertData = (actual: MonitorBase, expected: MonitorBase): void => }; export const assertTrace = (actual: Envelope[], expectation: Expectation): void => { - const envelope = actual.filter( - (e) => + 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}`); } @@ -74,10 +75,11 @@ export const assertCount = (actual: Envelope[], expectations: Expectation[]): vo export const assertExpectation = (actual: Envelope[], expectations: Expectation[]): void => { for (const expectation of expectations) { - const envelope = actual.filter( - (e) => + 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, 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 77% rename from sdk/monitor/monitor-opentelemetry-exporter/test/common/scenario/basic.ts rename to sdk/monitor/monitor-opentelemetry-exporter/test/utils/basic.ts index c20e245d5aa1..e0f3fe5e730a 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 { delay } from "@azure/core-http"; -import { TelemetryItem as Envelope } from "../../../src/generated"; +import { TelemetryItem as Envelope } from "../../src/generated"; +import { FlushSpanProcessor } from "./flushSpanProcessor"; const COMMON_ENVELOPE_PARAMS: Partial = { instrumentationKey: process.env.APPINSIGHTS_INSTRUMENTATIONKEY || "ikey", @@ -25,7 +25,7 @@ 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 +37,30 @@ export class BasicScenario implements Scenario { foo: "bar" } }); - const child1 = tracer.startSpan(`${this.constructor.name}.Child.1`, { - startTime: 0, - kind: opentelemetry.SpanKind.CLIENT, - attributes: { - numbers: "123" - } - }); - const child2 = tracer.startSpan(`${this.constructor.name}.Child.2`, { - startTime: 0, - kind: opentelemetry.SpanKind.CLIENT, - attributes: { - numbers: "1234" - } - }); + + 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/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[];