CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
transform.js92 linesDownload Raw Back to src
1"use strict";2/*3 * Copyright The OpenTelemetry Authors4 *5 * Licensed under the Apache License, Version 2.0 (the "License");6 * you may not use this file except in compliance with the License.7 * You may obtain a copy of the License at8 *9 *      https://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17Object.defineProperty(exports, "__esModule", { value: true });18exports._toZipkinAnnotations = exports._toZipkinTags = exports.toZipkinSpan = exports.defaultStatusErrorTagName = exports.defaultStatusCodeTagName = void 0;19const api = require("@opentelemetry/api");20const core_1 = require("@opentelemetry/core");21const zipkinTypes = require("./types");22const ZIPKIN_SPAN_KIND_MAPPING = {23    [api.SpanKind.CLIENT]: zipkinTypes.SpanKind.CLIENT,24    [api.SpanKind.SERVER]: zipkinTypes.SpanKind.SERVER,25    [api.SpanKind.CONSUMER]: zipkinTypes.SpanKind.CONSUMER,26    [api.SpanKind.PRODUCER]: zipkinTypes.SpanKind.PRODUCER,27    // When absent, the span is local.28    [api.SpanKind.INTERNAL]: undefined,29};30exports.defaultStatusCodeTagName = 'otel.status_code';31exports.defaultStatusErrorTagName = 'error';32/**33 * Translate OpenTelemetry ReadableSpan to ZipkinSpan format34 * @param span Span to be translated35 */36function toZipkinSpan(span, serviceName, statusCodeTagName, statusErrorTagName) {37    const zipkinSpan = {38        traceId: span.spanContext().traceId,39        parentId: span.parentSpanContext?.spanId,40        name: span.name,41        id: span.spanContext().spanId,42        kind: ZIPKIN_SPAN_KIND_MAPPING[span.kind],43        timestamp: (0, core_1.hrTimeToMicroseconds)(span.startTime),44        duration: Math.round((0, core_1.hrTimeToMicroseconds)(span.duration)),45        localEndpoint: { serviceName },46        tags: _toZipkinTags(span, statusCodeTagName, statusErrorTagName),47        annotations: span.events.length48            ? _toZipkinAnnotations(span.events)49            : undefined,50    };51    return zipkinSpan;52}53exports.toZipkinSpan = toZipkinSpan;54/** Converts OpenTelemetry Span properties to Zipkin Tags format. */55function _toZipkinTags({ attributes, resource, status, droppedAttributesCount, droppedEventsCount, droppedLinksCount, }, statusCodeTagName, statusErrorTagName) {56    const tags = {};57    for (const key of Object.keys(attributes)) {58        tags[key] = String(attributes[key]);59    }60    if (status.code !== api.SpanStatusCode.UNSET) {61        tags[statusCodeTagName] = String(api.SpanStatusCode[status.code]);62    }63    if (status.code === api.SpanStatusCode.ERROR && status.message) {64        tags[statusErrorTagName] = status.message;65    }66    /* Add droppedAttributesCount as a tag */67    if (droppedAttributesCount) {68        tags['otel.dropped_attributes_count'] = String(droppedAttributesCount);69    }70    /* Add droppedEventsCount as a tag */71    if (droppedEventsCount) {72        tags['otel.dropped_events_count'] = String(droppedEventsCount);73    }74    /* Add droppedLinksCount as a tag */75    if (droppedLinksCount) {76        tags['otel.dropped_links_count'] = String(droppedLinksCount);77    }78    Object.keys(resource.attributes).forEach(name => (tags[name] = String(resource.attributes[name])));79    return tags;80}81exports._toZipkinTags = _toZipkinTags;82/**83 * Converts OpenTelemetry Events to Zipkin Annotations format.84 */85function _toZipkinAnnotations(events) {86    return events.map(event => ({87        timestamp: Math.round((0, core_1.hrTimeToMicroseconds)(event.time)),88        value: event.name,89    }));90}91exports._toZipkinAnnotations = _toZipkinAnnotations;92//# sourceMappingURL=transform.js.map