UNPKG

@dynatrace/opentelemetry-core

Version:

Dynatrace OpenTelemetry core package

71 lines (68 loc) 2.52 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.verboseFormatException = verboseFormatException; exports.formatException = formatException; exports.prettyPrintObject = prettyPrintObject; exports.spanToString = spanToString; // ============================================================================ /** * can be used to convert an exception object to a meaningful string including * stack if possible. * @param error */ function verboseFormatException(error) { var _a; return (error instanceof Error) ? (_a = error.stack) !== null && _a !== void 0 ? _a : `${formatException(error)} [missing stacktrace]` : (typeof (error) === "string") ? error : `Failed to format exception: ${error}`; } // ---------------------------------------------------------------------------- /** * Format an error object as string. * @param error */ function formatException(error) { return (error instanceof Error) ? `${error.name}: ${error.message}` : (typeof (error) === "string") ? error : `Failed to format exception: ${error}`; } // ---------------------------------------------------------------------------- /** * Stringify all own properties of an object into a string. * @param obj to object to serialize */ function prettyPrintObject(obj) { return Object.entries(obj) .filter(([, v]) => v != null) .map(([k, v]) => `${k}=${v}`) .join(", "); } // ---------------------------------------------------------------------------- /** * Stringify a span into "<traceId>:<spanId>:<isRecording>" or "-"" if no span is given * @param span the span */ function spanToString(span) { if (span != null) { const ctx = span.spanContext(); return `${ctx.traceId}:${ctx.spanId}:${span.isRecording()}`; } return "-"; } //# sourceMappingURL=LoggingUtils.js.map