-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This pull request adds an OTLP/HTTP implementation of the Zipkin Collector. It mostly follows the following document, but does not implement fallback for remoteEndpoint name and deprecated attribute names have been changed to new ones. https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/zipkin.md Also, the mapping of resource attributes is TBD in this document, and is not implemented in this PR, but I would like to open a separate issue to discuss the mapping of resource attributes. --------- Co-authored-by: minux <[email protected]>
- Loading branch information
Showing
11 changed files
with
1,513 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# zipkin-collector-otel-http | ||
# collector-http | ||
|
||
This component implements | ||
the [OTLP/HTTP protocol](https://opentelemetry.io/docs/specs/otlp/#otlphttp) | ||
with [Armeria](https://armeria.dev/). | ||
This component implements the [OTLP/HTTP protocol](https://opentelemetry.io/docs/specs/otlp/#otlphttp) with [Armeria](https://armeria.dev/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
collector-http/src/main/java/zipkin2/collector/otel/http/ProtoUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright The OpenZipkin Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package zipkin2.collector.otel.http; | ||
|
||
import java.util.List; | ||
|
||
import com.google.protobuf.TextFormat; | ||
import io.opentelemetry.proto.common.v1.AnyValue; | ||
import io.opentelemetry.proto.common.v1.KeyValue; | ||
|
||
import static java.util.stream.Collectors.joining; | ||
|
||
final class ProtoUtils { | ||
static String kvListToJson(List<KeyValue> attributes) { | ||
return attributes.stream() | ||
.map(entry -> "\"" + entry.getKey() + "\":" + valueToJson(entry.getValue())) | ||
.collect(joining(",", "{", "}")); | ||
} | ||
|
||
static String valueToString(AnyValue value) { | ||
if (value.hasStringValue()) { | ||
return value.getStringValue(); | ||
} | ||
if (value.hasArrayValue()) { | ||
// While https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/README.md#attribute says | ||
// that an array should be encoded as a json, | ||
// the Otel Zipkin Exporter doesn't implement like that https://github.com/open-telemetry/opentelemetry-java/blob/main/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformerTest.java#L382-L385 | ||
// Also Brave doesn't use the json encoding. | ||
// So follow the comma separator here. | ||
return value.getArrayValue().getValuesList().stream() | ||
.map(ProtoUtils::valueToString) | ||
.collect(joining(",")); | ||
} | ||
return valueToJson(value); | ||
} | ||
|
||
static String valueToJson(AnyValue value) { | ||
if (value.hasStringValue()) { | ||
return "\"" + value.getStringValue() + "\""; | ||
} | ||
if (value.hasArrayValue()) { | ||
return value.getArrayValue().getValuesList().stream() | ||
.map(ProtoUtils::valueToJson) | ||
.collect(joining(",", "[", "]")); | ||
} | ||
if (value.hasKvlistValue()) { | ||
return kvListToJson(value.getKvlistValue().getValuesList()); | ||
} | ||
if (value.hasBoolValue()) { | ||
return String.valueOf(value.getBoolValue()); | ||
} | ||
if (value.hasDoubleValue()) { | ||
return String.valueOf(value.getDoubleValue()); | ||
} | ||
if (value.hasIntValue()) { | ||
return String.valueOf(value.getIntValue()); | ||
} | ||
if (value.hasBytesValue()) { | ||
// TODO | ||
return TextFormat.escapeBytes(value.getBytesValue()); | ||
} | ||
return value.toString(); | ||
} | ||
} |
Oops, something went wrong.