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,29 @@
import { Context, TextMapGetter, TextMapPropagator, TextMapSetter } from '@opentelemetry/api';
import { JaegerPropagatorConfig } from './types';
export declare const UBER_TRACE_ID_HEADER = "uber-trace-id";
export declare const UBER_BAGGAGE_HEADER_PREFIX = "uberctx";
/**
* Propagates {@link SpanContext} through Trace Context format propagation.
* {trace-id}:{span-id}:{parent-span-id}:{flags}
* {trace-id}
* 64-bit or 128-bit random number in base16 format.
* Can be variable length, shorter values are 0-padded on the left.
* Value of 0 is invalid.
* {span-id}
* 64-bit random number in base16 format.
* {parent-span-id}
* Set to 0 because this field is deprecated.
* {flags}
* One byte bitmap, as two hex digits.
* Inspired by jaeger-client-node project.
*/
export declare class JaegerPropagator implements TextMapPropagator {
private readonly _jaegerTraceHeader;
private readonly _jaegerBaggageHeaderPrefix;
constructor(customTraceHeader?: string);
constructor(config?: JaegerPropagatorConfig);
inject(context: Context, carrier: unknown, setter: TextMapSetter): void;
extract(context: Context, carrier: unknown, getter: TextMapGetter): Context;
fields(): string[];
}
//# sourceMappingURL=JaegerPropagator.d.ts.map

View File

@@ -0,0 +1,124 @@
"use strict";
/*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.JaegerPropagator = exports.UBER_BAGGAGE_HEADER_PREFIX = exports.UBER_TRACE_ID_HEADER = void 0;
const api_1 = require("@opentelemetry/api");
const core_1 = require("@opentelemetry/core");
exports.UBER_TRACE_ID_HEADER = 'uber-trace-id';
exports.UBER_BAGGAGE_HEADER_PREFIX = 'uberctx';
/**
* Propagates {@link SpanContext} through Trace Context format propagation.
* {trace-id}:{span-id}:{parent-span-id}:{flags}
* {trace-id}
* 64-bit or 128-bit random number in base16 format.
* Can be variable length, shorter values are 0-padded on the left.
* Value of 0 is invalid.
* {span-id}
* 64-bit random number in base16 format.
* {parent-span-id}
* Set to 0 because this field is deprecated.
* {flags}
* One byte bitmap, as two hex digits.
* Inspired by jaeger-client-node project.
*/
class JaegerPropagator {
_jaegerTraceHeader;
_jaegerBaggageHeaderPrefix;
constructor(config) {
if (typeof config === 'string') {
this._jaegerTraceHeader = config;
this._jaegerBaggageHeaderPrefix = exports.UBER_BAGGAGE_HEADER_PREFIX;
}
else {
this._jaegerTraceHeader =
config?.customTraceHeader || exports.UBER_TRACE_ID_HEADER;
this._jaegerBaggageHeaderPrefix =
config?.customBaggageHeaderPrefix || exports.UBER_BAGGAGE_HEADER_PREFIX;
}
}
inject(context, carrier, setter) {
const spanContext = api_1.trace.getSpanContext(context);
const baggage = api_1.propagation.getBaggage(context);
if (spanContext && (0, core_1.isTracingSuppressed)(context) === false) {
const traceFlags = `0${(spanContext.traceFlags || api_1.TraceFlags.NONE).toString(16)}`;
setter.set(carrier, this._jaegerTraceHeader, `${spanContext.traceId}:${spanContext.spanId}:0:${traceFlags}`);
}
if (baggage) {
for (const [key, entry] of baggage.getAllEntries()) {
setter.set(carrier, `${this._jaegerBaggageHeaderPrefix}-${key}`, encodeURIComponent(entry.value));
}
}
}
extract(context, carrier, getter) {
const uberTraceIdHeader = getter.get(carrier, this._jaegerTraceHeader);
const uberTraceId = Array.isArray(uberTraceIdHeader)
? uberTraceIdHeader[0]
: uberTraceIdHeader;
const baggageValues = getter
.keys(carrier)
.filter(key => key.startsWith(`${this._jaegerBaggageHeaderPrefix}-`))
.map(key => {
const value = getter.get(carrier, key);
return {
key: key.substring(this._jaegerBaggageHeaderPrefix.length + 1),
value: Array.isArray(value) ? value[0] : value,
};
});
let newContext = context;
// if the trace id header is present and valid, inject it into the context
if (typeof uberTraceId === 'string') {
const spanContext = deserializeSpanContext(uberTraceId);
if (spanContext) {
newContext = api_1.trace.setSpanContext(newContext, spanContext);
}
}
if (baggageValues.length === 0)
return newContext;
// if baggage values are present, inject it into the current baggage
let currentBaggage = api_1.propagation.getBaggage(context) ?? api_1.propagation.createBaggage();
for (const baggageEntry of baggageValues) {
if (baggageEntry.value === undefined)
continue;
currentBaggage = currentBaggage.setEntry(baggageEntry.key, {
value: decodeURIComponent(baggageEntry.value),
});
}
newContext = api_1.propagation.setBaggage(newContext, currentBaggage);
return newContext;
}
fields() {
return [this._jaegerTraceHeader];
}
}
exports.JaegerPropagator = JaegerPropagator;
const VALID_HEX_RE = /^[0-9a-f]{1,2}$/i;
/**
* @param {string} serializedString - a serialized span context.
* @return {SpanContext} - returns a span context represented by the serializedString.
**/
function deserializeSpanContext(serializedString) {
const headers = decodeURIComponent(serializedString).split(':');
if (headers.length !== 4) {
return null;
}
const [_traceId, _spanId, , flags] = headers;
const traceId = _traceId.padStart(32, '0');
const spanId = _spanId.padStart(16, '0');
const traceFlags = VALID_HEX_RE.test(flags) ? parseInt(flags, 16) & 1 : 1;
return { traceId, spanId, isRemote: true, traceFlags };
}
//# sourceMappingURL=JaegerPropagator.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
export { JaegerPropagator, UBER_BAGGAGE_HEADER_PREFIX, UBER_TRACE_ID_HEADER, } from './JaegerPropagator';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,23 @@
"use strict";
/*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.UBER_TRACE_ID_HEADER = exports.UBER_BAGGAGE_HEADER_PREFIX = exports.JaegerPropagator = void 0;
var JaegerPropagator_1 = require("./JaegerPropagator");
Object.defineProperty(exports, "JaegerPropagator", { enumerable: true, get: function () { return JaegerPropagator_1.JaegerPropagator; } });
Object.defineProperty(exports, "UBER_BAGGAGE_HEADER_PREFIX", { enumerable: true, get: function () { return JaegerPropagator_1.UBER_BAGGAGE_HEADER_PREFIX; } });
Object.defineProperty(exports, "UBER_TRACE_ID_HEADER", { enumerable: true, get: function () { return JaegerPropagator_1.UBER_TRACE_ID_HEADER; } });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,uDAI4B;AAH1B,oHAAA,gBAAgB,OAAA;AAChB,8HAAA,0BAA0B,OAAA;AAC1B,wHAAA,oBAAoB,OAAA","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\nexport {\n JaegerPropagator,\n UBER_BAGGAGE_HEADER_PREFIX,\n UBER_TRACE_ID_HEADER,\n} from './JaegerPropagator';\n"]}

View File

@@ -0,0 +1,5 @@
export interface JaegerPropagatorConfig {
customTraceHeader?: string;
customBaggageHeaderPrefix?: string;
}
//# sourceMappingURL=types.d.ts.map

View File

@@ -0,0 +1,18 @@
"use strict";
/*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/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\nexport interface JaegerPropagatorConfig {\n customTraceHeader?: string;\n customBaggageHeaderPrefix?: string;\n}\n"]}

View File

@@ -0,0 +1,2 @@
export declare const VERSION = "2.0.0";
//# sourceMappingURL=version.d.ts.map

View File

@@ -0,0 +1,21 @@
"use strict";
/*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.VERSION = void 0;
// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '2.0.0';
//# sourceMappingURL=version.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,OAAO,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\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '2.0.0';\n"]}