///
import { IncomingMessage, ServerResponse } from 'http';
import { NodeSDK } from '@opentelemetry/sdk-node';
import type { Instrumentation } from '@opentelemetry/instrumentation';
import { IInstrumentationScope, IResource, ISpan } from './otlp-types';
/**
* A utility for scripts that will be run with `runTestFixture()` to create an
* appropriately configured NodeSDK.
*
* Typically, when run via `runTestFixture`, OTEL_EXPORTER_OTLP_ENDPOINT will be
* set to export to a test collector. When that envvar is not set, this falls
* back to exporting to the console for dev convenience.
*/
export declare function createTestNodeSdk(opts: {
serviceName?: string;
instrumentations: (Instrumentation | Instrumentation[])[];
}): NodeSDK;
export type TestSpan = ISpan & {
resource: IResource;
instrumentationScope: IInstrumentationScope;
};
/**
* A minimal HTTP server that can act as an OTLP HTTP/JSON protocol collector.
* It stores the received data for later test assertions.
*
* Limitations: This only supports traces so far, no metrics or logs.
* There is little error checking here; we are assuming valid OTLP.
*/
export declare class TestCollector {
endpointUrl?: string;
spans: Array;
private _http;
constructor();
clear(): void;
start(): Promise;
close(): import("http").Server;
/**
* Return the spans sorted by which started first, for testing convenience.
*
* Note: This sorting is a *best effort*. `span.startTimeUnixNano` has
* millisecond accuracy, so if multiple spans start in the same millisecond
* then this cannot know the start ordering. If `startTimeUnixNano` are the
* same, this attempts to get the correct ordering using `parentSpanId` -- a
* parent span starts before any of its direct children. This isn't perfect.
*/
get sortedSpans(): Array;
private _onRequest;
private _ingestTraces;
}
export type RunTestFixtureOptions = {
/** Arguments to `node` executable. */
argv: Array;
cwd?: string;
env?: Record;
/** Timeout for the executed process in milliseconds. Defaults to 10s. */
timeoutMs?: number;
/** Check the process result. */
checkResult?: (err: Error | null, stdout: string, stderr: string) => void;
/** Check the collected results, e.g. via `collector.sortedSpans`. */
checkCollector?: (collector: TestCollector) => void;
};
/**
* Run a script that uses otel tracing and check the results.
*
* This starts a test collector that is capable of receiving HTTP/JSON OTLP,
* and sets OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OTLP_PROTOCOL
* appropriately so that scripts using `NodeSDK` will by default send traces
* to this collector. (See `createTestNodeSdk()` as a convenience for these
* scripts.)
*
* Then the script (given in `argv`) is executed and the optional `opts.check*`
* callbacks are called so the caller can assert expected process output and
* collected spans.
*
* For example:
* await runTestFixture({
* argv: ['fixtures/some-esm-script.mjs'],
* cwd: __dirname,
* env: {
* NODE_OPTIONS: '--experimental-loader=@opentelemetry/instrumentation/hook.mjs',
* NODE_NO_WARNINGS: '1',
* },
* checkResult: (err, stdout, stderr) => {
* assert.ifError(err);
* },
* checkCollector: (collector: TestCollector) => {
* const spans = collector.sortedSpans;
* assert.strictEqual(spans[0].name, 'manual');
* // ...
* },
* });
*/
export declare function runTestFixture(opts: RunTestFixtureOptions): Promise;
//# sourceMappingURL=test-fixtures.d.ts.map