Update test framework: fix run_tests.py to support all test files, add auto-import-check for test files

This commit is contained in:
qiaoxinjiu
2026-05-09 15:11:30 +08:00
parent eb053a347f
commit eaba8328da
21739 changed files with 2236758 additions and 719 deletions

View File

@@ -0,0 +1,4 @@
import type { HttpRequestParameters } from './http-transport-types';
import { IExporterTransport } from '../exporter-transport';
export declare function createHttpExporterTransport(parameters: HttpRequestParameters): IExporterTransport;
//# sourceMappingURL=http-exporter-transport.d.ts.map

View File

@@ -0,0 +1,51 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class HttpExporterTransport {
_parameters;
_utils = null;
constructor(_parameters) {
this._parameters = _parameters;
}
async send(data, timeoutMillis) {
const { agent, send } = this._loadUtils();
return new Promise(resolve => {
send(this._parameters, agent, data, result => {
resolve(result);
}, timeoutMillis);
});
}
shutdown() {
// intentionally left empty, nothing to do.
}
_loadUtils() {
let utils = this._utils;
if (utils === null) {
// Lazy require to ensure that http/https is not required before instrumentations can wrap it.
const { sendWithHttp, createHttpAgent,
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require('./http-transport-utils');
utils = this._utils = {
agent: createHttpAgent(this._parameters.url, this._parameters.agentOptions),
send: sendWithHttp,
};
}
return utils;
}
}
export function createHttpExporterTransport(parameters) {
return new HttpExporterTransport(parameters);
}
//# sourceMappingURL=http-exporter-transport.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"http-exporter-transport.js","sourceRoot":"","sources":["../../../src/transport/http-exporter-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAmBH,MAAM,qBAAqB;IAGL;IAFZ,MAAM,GAAiB,IAAI,CAAC;IAEpC,YAAoB,WAAkC;QAAlC,gBAAW,GAAX,WAAW,CAAuB;IAAG,CAAC;IAE1D,KAAK,CAAC,IAAI,CAAC,IAAgB,EAAE,aAAqB;QAChD,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAE1C,OAAO,IAAI,OAAO,CAAiB,OAAO,CAAC,EAAE;YAC3C,IAAI,CACF,IAAI,CAAC,WAAW,EAChB,KAAK,EACL,IAAI,EACJ,MAAM,CAAC,EAAE;gBACP,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,EACD,aAAa,CACd,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,QAAQ;QACN,2CAA2C;IAC7C,CAAC;IAEO,UAAU;QAChB,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QAExB,IAAI,KAAK,KAAK,IAAI,EAAE;YAClB,8FAA8F;YAC9F,MAAM,EACJ,YAAY,EACZ,eAAe;YACf,8DAA8D;cAC/D,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;YAEtC,KAAK,GAAG,IAAI,CAAC,MAAM,GAAG;gBACpB,KAAK,EAAE,eAAe,CACpB,IAAI,CAAC,WAAW,CAAC,GAAG,EACpB,IAAI,CAAC,WAAW,CAAC,YAAY,CAC9B;gBACD,IAAI,EAAE,YAAY;aACnB,CAAC;SACH;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,MAAM,UAAU,2BAA2B,CACzC,UAAiC;IAEjC,OAAO,IAAI,qBAAqB,CAAC,UAAU,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n HttpRequestParameters,\n sendWithHttp,\n} from './http-transport-types';\n\n// NOTE: do not change these type imports to actual imports. Doing so WILL break `@opentelemetry/instrumentation-http`,\n// as they'd be imported before the http/https modules can be wrapped.\nimport type * as https from 'https';\nimport type * as http from 'http';\nimport { ExportResponse } from '../export-response';\nimport { IExporterTransport } from '../exporter-transport';\n\ninterface Utils {\n agent: http.Agent | https.Agent;\n send: sendWithHttp;\n}\n\nclass HttpExporterTransport implements IExporterTransport {\n private _utils: Utils | null = null;\n\n constructor(private _parameters: HttpRequestParameters) {}\n\n async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n const { agent, send } = this._loadUtils();\n\n return new Promise<ExportResponse>(resolve => {\n send(\n this._parameters,\n agent,\n data,\n result => {\n resolve(result);\n },\n timeoutMillis\n );\n });\n }\n\n shutdown() {\n // intentionally left empty, nothing to do.\n }\n\n private _loadUtils(): Utils {\n let utils = this._utils;\n\n if (utils === null) {\n // Lazy require to ensure that http/https is not required before instrumentations can wrap it.\n const {\n sendWithHttp,\n createHttpAgent,\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n } = require('./http-transport-utils');\n\n utils = this._utils = {\n agent: createHttpAgent(\n this._parameters.url,\n this._parameters.agentOptions\n ),\n send: sendWithHttp,\n };\n }\n\n return utils;\n }\n}\n\nexport function createHttpExporterTransport(\n parameters: HttpRequestParameters\n): IExporterTransport {\n return new HttpExporterTransport(parameters);\n}\n"]}

View File

@@ -0,0 +1,13 @@
/// <reference types="node" />
/// <reference types="node" />
import type * as http from 'http';
import type * as https from 'https';
import { ExportResponse } from '../export-response';
export type sendWithHttp = (params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number) => void;
export interface HttpRequestParameters {
url: string;
headers: () => Record<string, string>;
compression: 'gzip' | 'none';
agentOptions: http.AgentOptions | https.AgentOptions;
}
//# sourceMappingURL=http-transport-types.d.ts.map

View File

@@ -0,0 +1,17 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export {};
//# sourceMappingURL=http-transport-types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"http-transport-types.js","sourceRoot":"","sources":["../../../src/transport/http-transport-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport { ExportResponse } from '../export-response';\n\nexport type sendWithHttp = (\n params: HttpRequestParameters,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n onDone: (response: ExportResponse) => void,\n timeoutMillis: number\n) => void;\n\nexport interface HttpRequestParameters {\n url: string;\n headers: () => Record<string, string>;\n compression: 'gzip' | 'none';\n agentOptions: http.AgentOptions | https.AgentOptions;\n}\n"]}

View File

@@ -0,0 +1,18 @@
/// <reference types="node" />
/// <reference types="node" />
import * as http from 'http';
import * as https from 'https';
import { HttpRequestParameters } from './http-transport-types';
import { ExportResponse } from '../export-response';
/**
* Sends data using http
* @param params
* @param agent
* @param data
* @param onDone
* @param timeoutMillis
*/
export declare function sendWithHttp(params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number): void;
export declare function compressAndSend(req: http.ClientRequest, compression: 'gzip' | 'none', data: Uint8Array, onError: (error: Error) => void): void;
export declare function createHttpAgent(rawUrl: string, agentOptions: http.AgentOptions | https.AgentOptions): http.Agent;
//# sourceMappingURL=http-transport-utils.d.ts.map

View File

@@ -0,0 +1,118 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as http from 'http';
import * as https from 'https';
import * as zlib from 'zlib';
import { Readable } from 'stream';
import { isExportRetryable, parseRetryAfterToMills, } from '../is-export-retryable';
import { OTLPExporterError } from '../types';
/**
* Sends data using http
* @param params
* @param agent
* @param data
* @param onDone
* @param timeoutMillis
*/
export function sendWithHttp(params, agent, data, onDone, timeoutMillis) {
const parsedUrl = new URL(params.url);
const nodeVersion = Number(process.versions.node.split('.')[0]);
const options = {
hostname: parsedUrl.hostname,
port: parsedUrl.port,
path: parsedUrl.pathname,
method: 'POST',
headers: {
...params.headers(),
},
agent: agent,
};
const request = parsedUrl.protocol === 'http:' ? http.request : https.request;
const req = request(options, (res) => {
const responseData = [];
res.on('data', chunk => responseData.push(chunk));
res.on('end', () => {
if (res.statusCode && res.statusCode < 299) {
onDone({
status: 'success',
data: Buffer.concat(responseData),
});
}
else if (res.statusCode && isExportRetryable(res.statusCode)) {
onDone({
status: 'retryable',
retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),
});
}
else {
const error = new OTLPExporterError(res.statusMessage, res.statusCode, Buffer.concat(responseData).toString());
onDone({
status: 'failure',
error,
});
}
});
});
req.setTimeout(timeoutMillis, () => {
req.destroy();
onDone({
status: 'failure',
error: new Error('Request Timeout'),
});
});
req.on('error', (error) => {
onDone({
status: 'failure',
error,
});
});
const reportTimeoutErrorEvent = nodeVersion >= 14 ? 'close' : 'abort';
req.on(reportTimeoutErrorEvent, () => {
onDone({
status: 'failure',
error: new Error('Request timed out'),
});
});
compressAndSend(req, params.compression, data, (error) => {
onDone({
status: 'failure',
error,
});
});
}
export function compressAndSend(req, compression, data, onError) {
let dataStream = readableFromUint8Array(data);
if (compression === 'gzip') {
req.setHeader('Content-Encoding', 'gzip');
dataStream = dataStream
.on('error', onError)
.pipe(zlib.createGzip())
.on('error', onError);
}
dataStream.pipe(req).on('error', onError);
}
function readableFromUint8Array(buff) {
const readable = new Readable();
readable.push(buff);
readable.push(null);
return readable;
}
export function createHttpAgent(rawUrl, agentOptions) {
const parsedUrl = new URL(rawUrl);
const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
return new Agent(agentOptions);
}
//# sourceMappingURL=http-transport-utils.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,10 @@
import { IExporterTransport } from '../exporter-transport';
export interface SendBeaconParameters {
url: string;
/**
* for instance 'application/x-protobuf'
*/
blobType: string;
}
export declare function createSendBeaconTransport(parameters: SendBeaconParameters): IExporterTransport;
//# sourceMappingURL=send-beacon-transport.d.ts.map

View File

@@ -0,0 +1,46 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { diag } from '@opentelemetry/api';
class SendBeaconTransport {
_params;
constructor(_params) {
this._params = _params;
}
send(data) {
return new Promise(resolve => {
if (navigator.sendBeacon(this._params.url, new Blob([data], { type: this._params.blobType }))) {
// no way to signal retry, treat everything as success
diag.debug('SendBeacon success');
resolve({
status: 'success',
});
}
else {
resolve({
status: 'failure',
error: new Error('SendBeacon failed'),
});
}
});
}
shutdown() {
// Intentionally left empty, nothing to do.
}
}
export function createSendBeaconTransport(parameters) {
return new SendBeaconTransport(parameters);
}
//# sourceMappingURL=send-beacon-transport.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"send-beacon-transport.js","sourceRoot":"","sources":["../../../src/transport/send-beacon-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAU1C,MAAM,mBAAmB;IACH;IAApB,YAAoB,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IACrD,IAAI,CAAC,IAAgB;QACnB,OAAO,IAAI,OAAO,CAAiB,OAAO,CAAC,EAAE;YAC3C,IACE,SAAS,CAAC,UAAU,CAClB,IAAI,CAAC,OAAO,CAAC,GAAG,EAChB,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAClD,EACD;gBACA,sDAAsD;gBACtD,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;gBACjC,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;iBAClB,CAAC,CAAC;aACJ;iBAAM;gBACL,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,mBAAmB,CAAC;iBACtC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,QAAQ;QACN,2CAA2C;IAC7C,CAAC;CACF;AAED,MAAM,UAAU,yBAAyB,CACvC,UAAgC;IAEhC,OAAO,IAAI,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { IExporterTransport } from '../exporter-transport';\nimport { ExportResponse } from '../export-response';\nimport { diag } from '@opentelemetry/api';\n\nexport interface SendBeaconParameters {\n url: string;\n /**\n * for instance 'application/x-protobuf'\n */\n blobType: string;\n}\n\nclass SendBeaconTransport implements IExporterTransport {\n constructor(private _params: SendBeaconParameters) {}\n send(data: Uint8Array): Promise<ExportResponse> {\n return new Promise<ExportResponse>(resolve => {\n if (\n navigator.sendBeacon(\n this._params.url,\n new Blob([data], { type: this._params.blobType })\n )\n ) {\n // no way to signal retry, treat everything as success\n diag.debug('SendBeacon success');\n resolve({\n status: 'success',\n });\n } else {\n resolve({\n status: 'failure',\n error: new Error('SendBeacon failed'),\n });\n }\n });\n }\n\n shutdown(): void {\n // Intentionally left empty, nothing to do.\n }\n}\n\nexport function createSendBeaconTransport(\n parameters: SendBeaconParameters\n): IExporterTransport {\n return new SendBeaconTransport(parameters);\n}\n"]}

View File

@@ -0,0 +1,11 @@
import { IExporterTransport } from '../exporter-transport';
export interface XhrRequestParameters {
url: string;
headers: () => Record<string, string>;
}
/**
* Creates an exporter transport that uses XHR to send the data
* @param parameters applied to each request made by transport
*/
export declare function createXhrTransport(parameters: XhrRequestParameters): IExporterTransport;
//# sourceMappingURL=xhr-transport.d.ts.map

View File

@@ -0,0 +1,84 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { diag } from '@opentelemetry/api';
import { isExportRetryable, parseRetryAfterToMills, } from '../is-export-retryable';
class XhrTransport {
_parameters;
constructor(_parameters) {
this._parameters = _parameters;
}
send(data, timeoutMillis) {
return new Promise(resolve => {
const xhr = new XMLHttpRequest();
xhr.timeout = timeoutMillis;
xhr.open('POST', this._parameters.url);
const headers = this._parameters.headers();
Object.entries(headers).forEach(([k, v]) => {
xhr.setRequestHeader(k, v);
});
xhr.ontimeout = _ => {
resolve({
status: 'failure',
error: new Error('XHR request timed out'),
});
};
xhr.onreadystatechange = () => {
if (xhr.status >= 200 && xhr.status <= 299) {
diag.debug('XHR success');
resolve({
status: 'success',
});
}
else if (xhr.status && isExportRetryable(xhr.status)) {
resolve({
status: 'retryable',
retryInMillis: parseRetryAfterToMills(xhr.getResponseHeader('Retry-After')),
});
}
else if (xhr.status !== 0) {
resolve({
status: 'failure',
error: new Error('XHR request failed with non-retryable status'),
});
}
};
xhr.onabort = () => {
resolve({
status: 'failure',
error: new Error('XHR request aborted'),
});
};
xhr.onerror = () => {
resolve({
status: 'failure',
error: new Error('XHR request errored'),
});
};
xhr.send(data);
});
}
shutdown() {
// Intentionally left empty, nothing to do.
}
}
/**
* Creates an exporter transport that uses XHR to send the data
* @param parameters applied to each request made by transport
*/
export function createXhrTransport(parameters) {
return new XhrTransport(parameters);
}
//# sourceMappingURL=xhr-transport.js.map

File diff suppressed because one or more lines are too long