All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.opentelemetry.exporter.zipkin.EventDataToAnnotation Maven / Gradle / Ivy

There is a newer version: 1.44.1
Show newest version
/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package io.opentelemetry.exporter.zipkin;

import static java.util.stream.Collectors.joining;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.trace.data.EventData;
import java.util.List;

/**
 * Converts an EventData instance to a String representation of that data, with attributes converted
 * to JSON.
 *
 * 

See the * zipkin exporter spec for details. */ final class EventDataToAnnotation { private EventDataToAnnotation() {} static String apply(EventData eventData) { String name = eventData.getName(); String value = toJson(eventData.getAttributes()); return "\"" + name + "\":" + value; } private static String toJson(Attributes attributes) { return attributes.asMap().entrySet().stream() .map(entry -> "\"" + entry.getKey() + "\":" + toValue(entry.getValue())) .collect(joining(",", "{", "}")); } private static String toValue(Object o) { if (o instanceof String) { return "\"" + o + "\""; } if (o instanceof List) { return ((List) o) .stream().map(EventDataToAnnotation::toValue).collect(joining(",", "[", "]")); } return String.valueOf(o); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy