@dynatrace/opentelemetry-core
Version:
Dynatrace OpenTelemetry core package
44 lines (41 loc) • 1.57 kB
JavaScript
;
/*
Copyright 2022 Dynatrace LLC
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
http://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.__testUncacheThreadId = exports.getThreadId = void 0;
const semver_1 = require("semver");
let threadId;
/**
* Returns the current thread id formatted as a hexadecimal encoded string.
*
* On sytems older than 12.x without support for worker_threads, the thread id is always 00000000
*/
let getThreadId = () => {
return "00000000";
};
exports.getThreadId = getThreadId;
if ((0, semver_1.satisfies)(process.version, ">=12")) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const workers = require("worker_threads");
exports.getThreadId = () => {
if (!threadId) {
threadId = workers.threadId.toString(16).toUpperCase().padStart(8, "0");
}
return threadId;
};
}
function __testUncacheThreadId() {
threadId = undefined;
}
exports.__testUncacheThreadId = __testUncacheThreadId;
//# sourceMappingURL=ThreadId.js.map