UNPKG

@dynatrace/opentelemetry-core

Version:

Dynatrace OpenTelemetry core package

46 lines (43 loc) 1.72 kB
"use strict"; /* 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.sanitizeTenantUuid = sanitizeTenantUuid; exports.calculateTenantId = calculateTenantId; const crypto_1 = require("crypto"); // ============================================================================ function sanitizeTenantUuid(tenantUuid) { const buf = Buffer.from(tenantUuid, "binary"); for (let i = 0; i < buf.length; i++) { // eslint-disable-next-line no-bitwise if ((buf[i] & 0x80) !== 0) { buf[i] = 0x3f; } } return buf.toString("binary"); } // ---------------------------------------------------------------------------- function calculateTenantId(tenantUuid) { if (tenantUuid.length === 0) { throw new Error("tenantUuid is empty"); } const md5Digest = (0, crypto_1.createHash)("md5").update(tenantUuid).digest(); let hash = 0; for (let i = 0; i < 16; i++) { const shift = (3 - (i % 4)) * 8; // eslint-disable-next-line no-bitwise hash ^= md5Digest[i] << shift; } return hash; } //# sourceMappingURL=TenantId.js.map