Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 48e3f6d

Browse files
authored
OpenCensus Zipkin Exporter (#139)
OpenCensus zipkin exporter.
1 parent 9a3f609 commit 48e3f6d

7 files changed

Lines changed: 874 additions & 0 deletions

File tree

WORKSPACE

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,60 @@ load("@com_github_jupp0r_prometheus_cpp//:repositories.bzl",
104104
# Load dependencies individually since we load some of them above.
105105
load_prometheus_client_model()
106106
load_civetweb()
107+
108+
# Curl library - used by zipkin exporter.
109+
new_http_archive(
110+
name = "com_github_curl",
111+
urls = ["https://github.com/curl/curl/archive/master.zip"],
112+
strip_prefix = "curl-master",
113+
build_file_content =
114+
"""
115+
load("@io_opencensus_cpp//opencensus:curl.bzl", "CURL_COPTS")
116+
package(features = ['no_copts_tokenization'])
117+
118+
config_setting(
119+
name = "windows",
120+
values = {"cpu": "x64_windows"},
121+
visibility = [ "//visibility:private" ],
122+
)
123+
124+
cc_library(
125+
name = "curl",
126+
srcs = glob([
127+
"lib/**/*.c",
128+
]),
129+
hdrs = glob([
130+
"include/curl/*.h",
131+
"lib/**/*.h",
132+
]),
133+
includes = ["include/", "lib/"],
134+
copts = CURL_COPTS + [
135+
"-DOS=\\"os\\"",
136+
"-DCURL_EXTERN_SYMBOL=__attribute__((__visibility__(\\"default\\")))",
137+
],
138+
visibility = ["//visibility:public"],
139+
)
140+
"""
141+
)
142+
143+
# Rapidjson library - used by zipkin exporter.
144+
new_http_archive(
145+
name = "com_github_rapidjson",
146+
urls = ["https://github.com/Tencent/rapidjson/archive/master.zip"],
147+
strip_prefix = "rapidjson-master",
148+
build_file_content =
149+
"""
150+
cc_library(
151+
name = "rapidjson",
152+
srcs = [],
153+
hdrs = glob([
154+
"include/rapidjson/*.h",
155+
"include/rapidjson/internal/*.h",
156+
"include/rapidjson/error/*.h",
157+
]),
158+
includes = ["include/"],
159+
defines = ["RAPIDJSON_HAS_STDSTRING=1",],
160+
visibility = ["//visibility:public"],
161+
)
162+
"""
163+
)

opencensus/curl.bzl

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
# Copyright 2018, OpenCensus Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# 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
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Compiler options for building libcurl.
16+
17+
CURL_COPTS = select({
18+
# TODO: Add in windows defines
19+
"//:windows": [
20+
# Disable everything else except HTTP protocol.
21+
"-DHTTP_ONLY=1",
22+
],
23+
24+
# Default defines
25+
"//conditions:default": [
26+
# Disable everything else except HTTP protocol.
27+
"-DHTTP_ONLY=1",
28+
29+
"-DENABLE_IPV6=1",
30+
"-DGETHOSTNAME_TYPE_ARG2=size_t",
31+
"-DGETSERVBYPORT_R_ARGS=6",
32+
"-DGETSERVBYPORT_R_BUFSIZE=4096",
33+
"-DHAVE_ALARM=1",
34+
"-DHAVE_ALLOCA_H=1",
35+
"-DHAVE_ARPA_INET_H=1",
36+
"-DHAVE_ARPA_TFTP_H=1",
37+
"-DHAVE_ASSERT_H=1",
38+
"-DHAVE_BASENAME=1",
39+
"-DHAVE_BOOL_T=1",
40+
"-DHAVE_CLOCK_GETTIME_MONOTONIC=1",
41+
"-DHAVE_CONNECT=1",
42+
"-DHAVE_DLFCN_H=1",
43+
"-DHAVE_ENGINE_LOAD_BUILTIN_ENGINES=1",
44+
"-DHAVE_ERRNO_H=1",
45+
"-DHAVE_FCNTL=1",
46+
"-DHAVE_FCNTL_H=1",
47+
"-DHAVE_FCNTL_O_NONBLOCK=1",
48+
"-DHAVE_FDOPEN=1",
49+
"-DHAVE_FREEADDRINFO=1",
50+
"-DHAVE_FREEIFADDRS=1",
51+
"-DHAVE_FSETXATTR=1",
52+
"-DHAVE_FSETXATTR_5=1",
53+
"-DHAVE_FTRUNCATE=1",
54+
"-DHAVE_GAI_STRERROR=1",
55+
"-DHAVE_GETADDRINFO=1",
56+
"-DHAVE_GETADDRINFO_THREADSAFE=1",
57+
"-DHAVE_GETEUID=1",
58+
"-DHAVE_GETHOSTBYADDR=1",
59+
"-DHAVE_GETHOSTBYADDR_R=1",
60+
"-DHAVE_GETHOSTBYADDR_R_8=1",
61+
"-DHAVE_GETHOSTBYNAME=1",
62+
"-DHAVE_GETHOSTBYNAME_R=1",
63+
"-DHAVE_GETHOSTBYNAME_R_6=1",
64+
"-DHAVE_GETHOSTNAME=1",
65+
"-DHAVE_GETIFADDRS=1",
66+
"-DHAVE_GETNAMEINFO=1",
67+
"-DHAVE_GETPPID=1",
68+
"-DHAVE_GETPWUID=1",
69+
"-DHAVE_GETPWUID_R=1",
70+
"-DHAVE_GETRLIMIT=1",
71+
"-DHAVE_GETSERVBYPORT_R=1",
72+
"-DHAVE_GETTIMEOFDAY=1",
73+
"-DHAVE_GMTIME_R=1",
74+
"-DHAVE_IFADDRS_H=1",
75+
"-DHAVE_IF_NAMETOINDEX=1",
76+
"-DHAVE_INET_NTOP=1",
77+
"-DHAVE_INET_PTON=1",
78+
"-DHAVE_INTTYPES_H=1",
79+
"-DHAVE_IOCTL=1",
80+
"-DHAVE_IOCTL_FIONBIO=1",
81+
"-DHAVE_IOCTL_SIOCGIFADDR=1",
82+
"-DHAVE_LIBGEN_H=1",
83+
"-DHAVE_LINUX_TCP_H=1",
84+
"-DHAVE_LL=1",
85+
"-DHAVE_LOCALE_H=1",
86+
"-DHAVE_LOCALTIME_R=1",
87+
"-DHAVE_LONGLONG=1",
88+
"-DHAVE_MALLOC_H=1",
89+
"-DHAVE_MEMORY_H=1",
90+
"-DHAVE_MSG_NOSIGNAL=1",
91+
"-DHAVE_NETDB_H=1",
92+
"-DHAVE_NETINET_IN_H=1",
93+
"-DHAVE_NETINET_TCP_H=1",
94+
"-DHAVE_NET_IF_H=1",
95+
"-DHAVE_PIPE=1",
96+
"-DHAVE_POLL=1",
97+
"-DHAVE_POLL_FINE=1",
98+
"-DHAVE_POLL_H=1",
99+
"-DHAVE_POSIX_STRERROR_R=1",
100+
"-DHAVE_PTHREAD_H=1",
101+
"-DHAVE_PWD_H=1",
102+
"-DHAVE_RECV=1",
103+
"-DHAVE_SELECT=1",
104+
"-DHAVE_SEND=1",
105+
"-DHAVE_SETJMP_H=1",
106+
"-DHAVE_SETLOCALE=1",
107+
"-DHAVE_SETRLIMIT=1",
108+
"-DHAVE_SETSOCKOPT=1",
109+
"-DHAVE_SGTTY_H=1",
110+
"-DHAVE_SIGACTION=1",
111+
"-DHAVE_SIGINTERRUPT=1",
112+
"-DHAVE_SIGNAL=1",
113+
"-DHAVE_SIGNAL_H=1",
114+
"-DHAVE_SIGSETJMP=1",
115+
"-DHAVE_SIG_ATOMIC_T=1",
116+
"-DHAVE_SOCKADDR_IN6_SIN6_SCOPE_ID=1",
117+
"-DHAVE_SOCKET=1",
118+
"-DHAVE_SOCKETPAIR=1",
119+
"-DHAVE_STDBOOL_H=1",
120+
"-DHAVE_STDINT_H=1",
121+
"-DHAVE_STDIO_H=1",
122+
"-DHAVE_STDLIB_H=1",
123+
"-DHAVE_STRCASECMP=1",
124+
"-DHAVE_STRDUP=1",
125+
"-DHAVE_STRERROR_R=1",
126+
"-DHAVE_STRINGS_H=1",
127+
"-DHAVE_STRING_H=1",
128+
"-DHAVE_STRNCASECMP=1",
129+
"-DHAVE_STROPTS_H=1",
130+
"-DHAVE_STRSTR=1",
131+
"-DHAVE_STRTOK_R=1",
132+
"-DHAVE_STRTOLL=1",
133+
"-DHAVE_STRUCT_SOCKADDR_STORAGE=1",
134+
"-DHAVE_STRUCT_TIMEVAL=1",
135+
"-DHAVE_SYS_IOCTL_H=1",
136+
"-DHAVE_SYS_PARAM_H=1",
137+
"-DHAVE_SYS_POLL_H=1",
138+
"-DHAVE_SYS_RESOURCE_H=1",
139+
"-DHAVE_SYS_SELECT_H=1",
140+
"-DHAVE_SYS_SOCKET_H=1",
141+
"-DHAVE_SYS_STAT_H=1",
142+
"-DHAVE_SYS_TIME_H=1",
143+
"-DHAVE_SYS_TYPES_H=1",
144+
"-DHAVE_SYS_UIO_H=1",
145+
"-DHAVE_SYS_UN_H=1",
146+
"-DHAVE_SYS_WAIT_H=1",
147+
"-DHAVE_SYS_XATTR_H=1",
148+
"-DHAVE_TERMIOS_H=1",
149+
"-DHAVE_TERMIO_H=1",
150+
"-DHAVE_TIME_H=1",
151+
"-DHAVE_UNISTD_H=1",
152+
"-DHAVE_UTIME=1",
153+
"-DHAVE_UTIMES=1",
154+
"-DHAVE_UTIME_H=1",
155+
"-DHAVE_VARIADIC_MACROS_C99=1",
156+
"-DHAVE_VARIADIC_MACROS_GCC=1",
157+
"-DHAVE_WRITABLE_ARGV=1",
158+
"-DHAVE_WRITEV=1",
159+
"-DRECV_TYPE_ARG1=int",
160+
"-DRECV_TYPE_ARG2=void*",
161+
"-DRECV_TYPE_ARG3=size_t",
162+
"-DRECV_TYPE_ARG4=int",
163+
"-DRECV_TYPE_RETV=ssize_t",
164+
"-DRETSIGTYPE=void",
165+
"-DSELECT_QUAL_ARG5=",
166+
"-DSELECT_TYPE_ARG1=int",
167+
"-DSELECT_TYPE_ARG234=fd_set*",
168+
"-DSELECT_TYPE_RETV=int",
169+
"-DSEND_QUAL_ARG2=const",
170+
"-DSEND_TYPE_ARG1=int",
171+
"-DSEND_TYPE_ARG2=void*",
172+
"-DSEND_TYPE_ARG3=size_t",
173+
"-DSEND_TYPE_ARG4=int",
174+
"-DSEND_TYPE_RETV=ssize_t",
175+
"-DSIZEOF_CURL_OFF_T=8",
176+
"-DSIZEOF_INT=4",
177+
"-DSIZEOF_LONG=8",
178+
"-DSIZEOF_OFF_T=8",
179+
"-DSIZEOF_SHORT=2",
180+
"-DSIZEOF_SIZE_T=8",
181+
"-DSIZEOF_TIME_T=8",
182+
"-DSTDC_HEADERS=1",
183+
"-DSTRERROR_R_TYPE_ARG3=size_t",
184+
"-DTIME_WITH_SYS_TIME=1",
185+
"-DUSE_THREADS_POSIX=1",
186+
"-DUSE_UNIX_SOCKETS=1",
187+
188+
# Extra defines needed by curl
189+
"-DBUILDING_LIBCURL",
190+
"-DCURL_HIDDEN_SYMBOLS",
191+
],
192+
})
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2018, OpenCensus Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# 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
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
load("//opencensus:copts.bzl", "DEFAULT_COPTS", "TEST_COPTS")
16+
17+
licenses(["notice"]) # Apache License 2.0
18+
19+
package(default_visibility = ["//visibility:public"])
20+
21+
# Libraries
22+
# ========================================================================= #
23+
24+
cc_library(
25+
name = "zipkin_exporter",
26+
srcs = [
27+
"internal/zipkin_exporter.cc",
28+
],
29+
hdrs = [
30+
"zipkin_exporter.h",
31+
],
32+
copts = DEFAULT_COPTS,
33+
deps = [
34+
"//opencensus/trace",
35+
"@com_google_absl//absl/base:core_headers",
36+
"@com_google_absl//absl/memory",
37+
"@com_google_absl//absl/strings",
38+
"@com_github_curl//:curl",
39+
"@com_github_rapidjson//:rapidjson",
40+
],
41+
)
42+
43+
# Tests
44+
# ========================================================================= #
45+
46+
cc_test(
47+
name = "zipkin_exporter_test",
48+
srcs = ["internal/zipkin_exporter_test.cc"],
49+
copts = TEST_COPTS,
50+
deps = [
51+
":zipkin_exporter",
52+
"//opencensus/trace",
53+
"@com_google_absl//absl/time",
54+
"@com_google_googletest//:gtest_main",
55+
],
56+
)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Zipkin Export Example
2+
3+
This is a simple example program to demonstrate how to export tracing information
4+
to Zipkin using OpenCensus.
5+
6+
Usage:
7+
8+
Start the zipkin server.
9+
```shell
10+
java -jar zipkin.jar --logging.level.zipkin=DEBUG --logging.level.zipkin2=DEBUG
11+
```
12+
13+
Build and run the OpenCensus example.
14+
```shell
15+
bazel build opencensus/...
16+
./bazel-bin/opencensus/exporters/trace/zipkin/zipkin_exporter_test
17+
```
18+
19+
## Zipkin:
20+
21+
A Zipkin server needs to be running to collect the spans. Zipkin can be found [here](https://github.com/openzipkin/zipkin). Instructions on running the server can be found [here](https://github.com/openzipkin/zipkin/tree/master/zipkin-server). The Zipkin server should by default listen on port 9411. If you are running the server locally, the spans should be sent to "http://127.0.0.1:9411/api/v2/spans".
22+
23+
Zipkin's tracing model is not identical to the model used by OpenCensus. Here is
24+
a list of some of the differences when converting from OpenCensus to Zipkin.
25+
26+
**OpenCensus -> Zipkin**
27+
* message events -> annotations (serialized as <SENT/RECEIVED>/\<Id\>/\<size\>)
28+
* attributes -> tags (which are a dict of key/value pairs in Zipkin)
29+
* links -> Not Supported
30+
31+
## Viewing Example Trace
32+
33+
The traces will show up on the Zipkin webpage UI. If you are using the default address it will be "http://127.0.0.1:9411/zipkin". Click on find traces. The trace sent from the exporter should appear. Click on it and it should look something like this:
34+
35+
![Example Trace](https://i.imgur.com/7bNWraI.png)
36+
37+
The individual spans can be clicked on, which will list the tracing information
38+
for that particular span.
39+
40+
![Example Span](https://i.imgur.com/S2yVHtu.png)

0 commit comments

Comments
 (0)