Skip to content

Commit 0142330

Browse files
Adds Brave Encoding support for v2 (#208)
This adds two new artifacts to allow StackdriverSender to have no zipkin dependency: * zipkin-encoder-stackdriver: zipkin2.Span encoder from before * brave-encoder-stackdriver: new brave.handler.MutableSpan encoder The main change is `StackdriverEncoder.V2` is moved to a new package: `zipkin2.reporter.stackdriver.zipkin`, where it was formerly one level up. This is the part that decouples the classpath. Most won't use this encoder anymore as you can use Brave directly like so: ```java spanHandler = AsyncZipkinSpanHandler.newBuilder(sender).build(new StackdriverV2Encoder(Tags.ERROR)); ``` Signed-off-by: Adrian Cole <adrian@tetrate.io>
1 parent 269a5f1 commit 0142330

File tree

40 files changed

+1056
-200
lines changed

40 files changed

+1056
-200
lines changed

README.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,52 @@
33
[![Maven Central](https://img.shields.io/maven-central/v/io.zipkin.gcp/zipkin-module-gcp.svg)](https://search.maven.org/search?q=g:io.zipkin.gcp%20AND%20a:zipkin-module-gcp)
44

55
# zipkin-gcp
6-
Shared libraries that provide Zipkin integration with the Google Cloud Platform. Requires JRE 8 or later.
6+
Shared libraries that provide Zipkin integration with the Google Cloud Platform. Requires JRE 11 or later.
77

88
# Usage
99
These components integrate traced applications and servers through Google Cloud services
1010
via interfaces defined in [Zipkin](https://github.com/openzipkin/zipkin)
1111
and [zipkin-reporter-java](https://github.com/openzipkin/zipkin-reporter-java).
1212

1313
## Senders
14-
The component in an traced application that sends timing data (spans)
14+
The component in a traced application that sends timing data (spans)
1515
out of process is called a Sender. Senders are called on interval by an
1616
[async reporter](https://github.com/openzipkin/zipkin-reporter-java#asyncreporter).
1717

1818
NOTE: Applications can be written in any language, while we currently
1919
only have senders in Java, senders in other languages are welcome.
2020

21-
Sender | Description
22-
--- | ---
23-
[Stackdriver Trace](./sender/stackdriver) | Free cloud service provider
21+
| Sender | Description |
22+
|-------------------------------------------|-----------------------------|
23+
| [Stackdriver Trace](./sender-stackdriver) | Free cloud service provider |
24+
25+
### Encoders
26+
27+
Encoding is library-specific, as some libraries use `zipkin2.Span` and others
28+
`brave.handler.MutableSpan`. Both options are available to encode to the
29+
StackDriver Trave V2 format.
30+
31+
| Encoder | Description |
32+
|---------------------------------------------------------|------------------------------------------------|
33+
| [`StackdriverEncoder.V2`](./encoder-stackdriver-zipkin) | zipkin-reporter `AsyncReporter<Span>` |
34+
| [`StackdriverV2Encoder`](./encoder-stackdriver-brave) | zipkin-reporter-brave `AsyncZipkinSpanHandler` |
2435

2536
## Collectors
2637
The component in a zipkin server that receives trace data is called a
2738
collector. This decodes spans reported by applications and persists them
2839
to a configured storage component.
2940

30-
Collector | Description
31-
--- | ---
41+
| Collector | Description |
42+
|-----------|-------------|
3243

3344
## Storage
3445
The component in a zipkin server that persists and queries collected
3546
data is called `StorageComponent`. This primarily supports the Zipkin
3647
Api and all collector components.
3748

38-
Storage | Description
39-
--- | ---
40-
[Stackdriver Trace](./storage/stackdriver) | Free cloud service provider
49+
| Storage | Description |
50+
|--------------------------------------------|-----------------------------|
51+
| [Stackdriver Trace](./storage/stackdriver) | Free cloud service provider |
4152

4253
## Server integration
4354
In order to integrate with zipkin-server, you need to use properties

benchmarks/pom.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<artifactId>zipkin-gcp-parent</artifactId>
2222
<groupId>io.zipkin.gcp</groupId>
23-
<version>1.1.2-SNAPSHOT</version>
23+
<version>2.0.0-SNAPSHOT</version>
2424
</parent>
2525

2626
<artifactId>benchmarks</artifactId>
@@ -38,6 +38,16 @@
3838
<artifactId>zipkin-storage-stackdriver</artifactId>
3939
<version>${project.version}</version>
4040
</dependency>
41+
<dependency>
42+
<groupId>${project.groupId}</groupId>
43+
<artifactId>zipkin-encoder-stackdriver</artifactId>
44+
<version>${project.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>${project.groupId}</groupId>
48+
<artifactId>brave-encoder-stackdriver</artifactId>
49+
<version>${project.version}</version>
50+
</dependency>
4151
<dependency>
4252
<groupId>${project.groupId}</groupId>
4353
<artifactId>zipkin-sender-stackdriver</artifactId>
@@ -49,6 +59,11 @@
4959
</exclusion>
5060
</exclusions>
5161
</dependency>
62+
<dependency>
63+
<groupId>${brave.groupId}</groupId>
64+
<artifactId>brave</artifactId>
65+
<version>${brave.version}</version>
66+
</dependency>
5267

5368
<dependency>
5469
<groupId>org.openjdk.jmh</groupId>

benchmarks/src/main/java/zipkin2/reporter/stackdriver/TracesParserBenchmarks.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 The OpenZipkin Authors
2+
* Copyright 2016-2024 The OpenZipkin Authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
55
* in compliance with the License. You may obtain a copy of the License at
@@ -31,9 +31,10 @@
3131
import org.openjdk.jmh.runner.RunnerException;
3232
import org.openjdk.jmh.runner.options.Options;
3333
import org.openjdk.jmh.runner.options.OptionsBuilder;
34+
import zipkin2.reporter.stackdriver.zipkin.StackdriverEncoder;
3435

35-
import static zipkin2.reporter.stackdriver.StackdriverEncoderBenchmarks.CLIENT_SPAN;
3636
import static zipkin2.reporter.stackdriver.StackdriverSender.SPAN_ID_PREFIX;
37+
import static zipkin2.reporter.stackdriver.zipkin.StackdriverEncoderBenchmarks.CLIENT_SPAN;
3738

3839
@Measurement(iterations = 5, time = 1)
3940
@Warmup(iterations = 10, time = 1)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright 2016-2024 The OpenZipkin Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
package zipkin2.reporter.stackdriver.brave;
15+
16+
import brave.Tags;
17+
import brave.handler.MutableSpan;
18+
import brave.handler.MutableSpanBytesEncoder;
19+
import java.util.concurrent.TimeUnit;
20+
import org.openjdk.jmh.annotations.Benchmark;
21+
import org.openjdk.jmh.annotations.BenchmarkMode;
22+
import org.openjdk.jmh.annotations.Fork;
23+
import org.openjdk.jmh.annotations.Measurement;
24+
import org.openjdk.jmh.annotations.Mode;
25+
import org.openjdk.jmh.annotations.OutputTimeUnit;
26+
import org.openjdk.jmh.annotations.Scope;
27+
import org.openjdk.jmh.annotations.State;
28+
import org.openjdk.jmh.annotations.Threads;
29+
import org.openjdk.jmh.annotations.Warmup;
30+
import org.openjdk.jmh.runner.Runner;
31+
import org.openjdk.jmh.runner.RunnerException;
32+
import org.openjdk.jmh.runner.options.Options;
33+
import org.openjdk.jmh.runner.options.OptionsBuilder;
34+
35+
@Measurement(iterations = 5, time = 1)
36+
@Warmup(iterations = 10, time = 1)
37+
@Fork(3)
38+
@BenchmarkMode(Mode.AverageTime)
39+
@OutputTimeUnit(TimeUnit.MICROSECONDS)
40+
@State(Scope.Thread)
41+
@Threads(1)
42+
public class StackdriverV2EncoderBenchmarks {
43+
static final StackdriverV2Encoder encoder = new StackdriverV2Encoder(Tags.ERROR);
44+
static final MutableSpanBytesEncoder braveEncoder =
45+
MutableSpanBytesEncoder.zipkinJsonV2(Tags.ERROR);
46+
static final MutableSpan CLIENT_SPAN = clientSpan();
47+
48+
static MutableSpan clientSpan() {
49+
MutableSpan braveSpan = new MutableSpan();
50+
braveSpan.traceId("7180c278b62e8f6a216a2aea45d08fc9");
51+
braveSpan.parentId("6b221d5bc9e6496c");
52+
braveSpan.id("5b4185666d50f68b");
53+
braveSpan.name("get");
54+
braveSpan.kind(brave.Span.Kind.CLIENT);
55+
braveSpan.localServiceName("frontend");
56+
braveSpan.localIp("127.0.0.1");
57+
braveSpan.remoteServiceName("backend");
58+
braveSpan.remoteIpAndPort("192.168.99.101", 9000);
59+
braveSpan.startTimestamp(1472470996199000L);
60+
braveSpan.finishTimestamp(1472470996199000L + 207000L);
61+
braveSpan.annotate(1472470996238000L, "foo");
62+
braveSpan.annotate(1472470996403000L, "bar");
63+
braveSpan.tag("clnt/finagle.version", "6.45.0");
64+
braveSpan.tag("http.path", "/api");
65+
return braveSpan;
66+
}
67+
68+
@Benchmark
69+
public int sizeInBytesClientSpan_json_zipkin_json() {
70+
return braveEncoder.sizeInBytes(CLIENT_SPAN);
71+
}
72+
73+
@Benchmark
74+
public int sizeInBytesClientSpan_json_stackdriver_proto3() {
75+
return encoder.sizeInBytes(CLIENT_SPAN);
76+
}
77+
78+
@Benchmark
79+
public byte[] encodeClientSpan_json_zipkin_json() {
80+
return braveEncoder.encode(CLIENT_SPAN);
81+
}
82+
83+
@Benchmark
84+
public byte[] encodeClientSpan_json_stackdriver_proto3() {
85+
return encoder.encode(CLIENT_SPAN);
86+
}
87+
88+
// Convenience main entry-point
89+
public static void main(String[] args) throws RunnerException {
90+
Options opt =
91+
new OptionsBuilder()
92+
.include(".*" + StackdriverV2EncoderBenchmarks.class.getSimpleName() + ".*")
93+
.build();
94+
95+
new Runner(opt).run();
96+
}
97+
}

benchmarks/src/main/java/zipkin2/reporter/stackdriver/StackdriverEncoderBenchmarks.java renamed to benchmarks/src/main/java/zipkin2/reporter/stackdriver/zipkin/StackdriverEncoderBenchmarks.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 The OpenZipkin Authors
2+
* Copyright 2016-2024 The OpenZipkin Authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
55
* in compliance with the License. You may obtain a copy of the License at
@@ -11,7 +11,7 @@
1111
* or implied. See the License for the specific language governing permissions and limitations under
1212
* the License.
1313
*/
14-
package zipkin2.reporter.stackdriver;
14+
package zipkin2.reporter.stackdriver.zipkin;
1515

1616
import java.util.concurrent.TimeUnit;
1717
import org.openjdk.jmh.annotations.Benchmark;
@@ -40,7 +40,7 @@
4040
@State(Scope.Thread)
4141
@Threads(1)
4242
public class StackdriverEncoderBenchmarks {
43-
static final Span CLIENT_SPAN =
43+
public static final Span CLIENT_SPAN =
4444
Span.newBuilder()
4545
.traceId("7180c278b62e8f6a216a2aea45d08fc9")
4646
.parentId("6b221d5bc9e6496c")

collector-pubsub/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<parent>
1919
<artifactId>zipkin-gcp-parent</artifactId>
2020
<groupId>io.zipkin.gcp</groupId>
21-
<version>1.1.2-SNAPSHOT</version>
21+
<version>2.0.0-SNAPSHOT</version>
2222
</parent>
2323
<modelVersion>4.0.0</modelVersion>
2424

encoder-stackdriver-brave/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# encoder-stackdriver-brave
2+
3+
This encodes brave spans into Stackdriver proto3 format.
4+
5+
```java
6+
// connect the sender to the correct encoding
7+
spanHandler = AsyncZipkinSpanHandler.newBuilder(sender).build(new StackdriverV2Encoder(Tags.ERROR));
8+
```

encoder-stackdriver-brave/pom.xml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2016-2024 The OpenZipkin Authors
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7+
in compliance with the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software distributed under the License
12+
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13+
or implied. See the License for the specific language governing permissions and limitations under
14+
the License.
15+
16+
-->
17+
<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">
18+
<parent>
19+
<artifactId>zipkin-gcp-parent</artifactId>
20+
<groupId>io.zipkin.gcp</groupId>
21+
<version>2.0.0-SNAPSHOT</version>
22+
</parent>
23+
<modelVersion>4.0.0</modelVersion>
24+
25+
<artifactId>brave-encoder-stackdriver</artifactId>
26+
<name>Brave Encoder: Google Stackdriver Trace</name>
27+
28+
<properties>
29+
<main.basedir>${project.basedir}/..</main.basedir>
30+
</properties>
31+
32+
<dependencies>
33+
<!-- Translation deps -->
34+
<dependency>
35+
<groupId>com.google.api.grpc</groupId>
36+
<artifactId>proto-google-common-protos</artifactId>
37+
<version>${proto-google-common-protos.version}</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>com.google.api.grpc</groupId>
42+
<artifactId>proto-google-cloud-trace-v2</artifactId>
43+
<version>${grpc-google-cloud-trace.version}</version>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>com.google.protobuf</groupId>
48+
<artifactId>protobuf-java</artifactId>
49+
<version>${protobuf.version}</version>
50+
<!-- We use provided scope to avoid pinning a protobuf version -->
51+
<scope>provided</scope>
52+
</dependency>
53+
54+
<!-- Encoder/Data type deps -->
55+
<dependency>
56+
<groupId>io.zipkin.reporter2</groupId>
57+
<artifactId>zipkin-reporter-brave</artifactId>
58+
<version>${zipkin-reporter.version}</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>${brave.groupId}</groupId>
62+
<artifactId>brave</artifactId>
63+
<version>${brave.version}</version>
64+
<!-- Don't pin Brave -->
65+
<scope>provided</scope>
66+
</dependency>
67+
</dependencies>
68+
</project>

0 commit comments

Comments
 (0)