Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Azure Monitor Exporter] Separate tests into internal and public folders #15932

Merged
merged 12 commits into from
Jun 28, 2021
Prev Previous commit
Next Next commit
try flush processor
xiao-lix committed Jun 25, 2021
commit 72c31272caa4397515376b8b93d53ff981192532
Original file line number Diff line number Diff line change
@@ -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<Envelope> = {
instrumentationKey: process.env.APPINSIGHTS_INSTRUMENTATIONKEY || "ikey",
@@ -18,7 +19,7 @@ const COMMON_ENVELOPE_PARAMS: Partial<Envelope> = {
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 {
Original file line number Diff line number Diff line change
@@ -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<void> {
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<void> {
return Promise.resolve();
}
}