-
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 the encoder below: # encoder-brave This encodes brave spans into OTLP proto format. ```java // Use OTLP encoder when sending to an OTLP backend spanHandler = AsyncZipkinSpanHandler.newBuilder(sender).build(new OtlpProtoV1Encoder(Tags.ERROR)); ``` --------- Co-authored-by: Marcin Grzejszczak <[email protected]>
- Loading branch information
1 parent
7a9d0c9
commit 442a436
Showing
16 changed files
with
1,631 additions
and
29 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
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,8 @@ | ||
# encoder-brave | ||
|
||
This encodes brave spans into OTLP proto format. | ||
|
||
```java | ||
// Use OTLP encoder when sending to an OTLP backend | ||
spanHandler = AsyncZipkinSpanHandler.newBuilder(sender).build(new OtlpProtoV1Encoder(Tags.ERROR)); | ||
``` |
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,119 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright The OpenZipkin Authors | ||
SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>io.zipkin.contrib.otel</groupId> | ||
<artifactId>zipkin-otel-parent</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>encoder-brave</artifactId> | ||
<name>Brave Encoder: OpenTelemetry Trace</name> | ||
|
||
<properties> | ||
<main.basedir>${project.basedir}/..</main.basedir> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.opentelemetry</groupId> | ||
<artifactId>opentelemetry-api</artifactId> | ||
<version>${opentelemetry.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.opentelemetry</groupId> | ||
<artifactId>opentelemetry-sdk-common</artifactId> | ||
<version>${opentelemetry.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.opentelemetry.proto</groupId> | ||
<artifactId>opentelemetry-proto</artifactId> | ||
<version>${opentelemetry-proto.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.opentelemetry.semconv</groupId> | ||
<artifactId>opentelemetry-semconv</artifactId> | ||
<version>${opentelemetry-semconv.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.protobuf</groupId> | ||
<artifactId>protobuf-java</artifactId> | ||
<version>${protobuf.version}</version> | ||
<!-- We use provided scope to avoid pinning a protobuf version --> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Encoder/Data type deps --> | ||
<dependency> | ||
<groupId>io.zipkin.reporter2</groupId> | ||
<artifactId>zipkin-reporter-brave</artifactId> | ||
<version>${zipkin-reporter.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${brave.groupId}</groupId> | ||
<artifactId>brave</artifactId> | ||
<version>${brave.version}</version> | ||
<!-- Don't pin Brave --> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${brave.groupId}</groupId> | ||
<artifactId>brave-instrumentation-http</artifactId> | ||
<version>${brave.version}</version> | ||
<!-- Don't pin Brave --> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.squareup.okhttp3</groupId> | ||
<artifactId>okhttp</artifactId> | ||
<version>${okhttp.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.zipkin.reporter2</groupId> | ||
<artifactId>zipkin-sender-okhttp3</artifactId> | ||
<version>${zipkin-reporter.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${armeria.groupId}</groupId> | ||
<artifactId>armeria-junit5</artifactId> | ||
<version>${armeria.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>testcontainers</artifactId> | ||
<version>${testcontainers.version}</version> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<version>${testcontainers.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
</build> | ||
</project> |
38 changes: 38 additions & 0 deletions
38
encoder-brave/src/main/java/zipkin2/reporter/otel/brave/BraveScope.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,38 @@ | ||
/* | ||
* Copyright The OpenZipkin Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package zipkin2.reporter.otel.brave; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.UncheckedIOException; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Define InstrumentationScope for encoder-brave | ||
*/ | ||
final class BraveScope { | ||
static final String NAME; | ||
|
||
static final String VERSION; | ||
|
||
static { | ||
try (InputStream stream = BraveScope.class.getClassLoader().getResourceAsStream("scope.properties")) { | ||
if (stream != null) { | ||
Properties props = new Properties(); | ||
props.load(stream); | ||
NAME = props.getProperty("name"); | ||
VERSION = props.getProperty("version"); | ||
} | ||
else { | ||
NAME = "unknown"; | ||
VERSION = "unknown"; | ||
} | ||
} | ||
catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
encoder-brave/src/main/java/zipkin2/reporter/otel/brave/OtlpProtoV1Encoder.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,39 @@ | ||
/* | ||
* Copyright The OpenZipkin Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package zipkin2.reporter.otel.brave; | ||
|
||
import brave.Tag; | ||
import brave.handler.MutableSpan; | ||
import io.opentelemetry.proto.trace.v1.TracesData; | ||
import zipkin2.reporter.BytesEncoder; | ||
import zipkin2.reporter.Encoding; | ||
|
||
public final class OtlpProtoV1Encoder implements BytesEncoder<MutableSpan> { | ||
final SpanTranslator spanTranslator; | ||
|
||
public OtlpProtoV1Encoder(Tag<Throwable> errorTag) { | ||
if (errorTag == null) throw new NullPointerException("errorTag == null"); | ||
this.spanTranslator = new SpanTranslator(errorTag); | ||
} | ||
|
||
@Override | ||
public Encoding encoding() { | ||
return Encoding.PROTO3; | ||
} | ||
|
||
@Override public int sizeInBytes(MutableSpan span) { | ||
// TODO: Create a proto size function to avoid allocations here | ||
TracesData convert = translate(span); | ||
return encoding().listSizeInBytes(convert.getSerializedSize()); | ||
} | ||
|
||
@Override public byte[] encode(MutableSpan span) { | ||
return translate(span).toByteArray(); | ||
} | ||
|
||
TracesData translate(MutableSpan span) { | ||
return spanTranslator.translate(span); | ||
} | ||
} |
Oops, something went wrong.