Skip to content

Commit

Permalink
Add Zipkin support.
Browse files Browse the repository at this point in the history
  • Loading branch information
rnburn committed Jul 13, 2017
1 parent 09d9a68 commit 46c54f7
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 4 deletions.
10 changes: 9 additions & 1 deletion config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
$ngx_addon_dir/utility/include/ngx_opentracing_utility.h"

. $ngx_addon_dir/lightstep/tracer_config
if [ "$NGINX_OPENTRACING_VENDOR" = "LIGHTSTEP" ]
then
. $ngx_addon_dir/lightstep/tracer_config
elif [ "$NGINX_OPENTRACING_VENDOR" = "ZIPKIN" ]
then
. $ngx_addon_dir/zipkin/tracer_config
else
. $ngx_addon_dir/zipkin/tracer_config
fi

NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
$ngx_addon_dir/module/src/ngx_http_opentracing_module.cpp \
Expand Down
4 changes: 2 additions & 2 deletions lightstep/src/lightstep_tracer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <opentracing/noop.h>
#include <lightstep/tracer.h>
#include <lightstep/tracer.h>
#include <ngx_opentracing_tracer_options.h>
#include <ngx_opentracing_utility.h>
#include <opentracing/noop.h>
#include <string>
using namespace lightstep;
using namespace opentracing;
Expand Down
2 changes: 1 addition & 1 deletion lightstep/tracer_config
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ $ngx_addon_dir/lightstep/include/ngx_opentracing_tracer_commands.def"
CORE_LIBS="$CORE_LIBS \
-lgrpc++ \
-lgrpc \
-lprotobuf
-lprotobuf \
-llightstep_tracer"
3 changes: 3 additions & 0 deletions scripts/run_clang_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
find . -path ./example/node_modules -prune -o \( -name '*.h' -or -name '*.cpp' \) \
-exec clang-format -i {} \;
12 changes: 12 additions & 0 deletions zipkin/include/ngx_opentracing_tracer_commands.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ngx_string("zipkin_service_name"),
NGX_HTTP_MAIN_CONF | NGX_CONF_TAKE1, ngx_conf_set_str_slot,
NGX_HTTP_MAIN_CONF_OFFSET,
offsetof(opentracing_main_conf_t, tracer_options.service_name), nullptr},
{ngx_string("zipkin_collector_host"),
NGX_HTTP_MAIN_CONF | NGX_CONF_TAKE1, ngx_conf_set_str_slot,
NGX_HTTP_MAIN_CONF_OFFSET,
offsetof(opentracing_main_conf_t, tracer_options.collector_host), nullptr},
{ngx_string("zipkin_collector_port"),
NGX_HTTP_MAIN_CONF | NGX_CONF_TAKE1, ngx_conf_set_str_slot,
NGX_HTTP_MAIN_CONF_OFFSET,
offsetof(opentracing_main_conf_t, tracer_options.collector_port), nullptr},
16 changes: 16 additions & 0 deletions zipkin/include/ngx_opentracing_tracer_options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

extern "C" {
#include <nginx.h>
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
}

namespace ngx_opentracing {
struct tracer_options_t {
ngx_str_t collector_host;
ngx_str_t collector_port;
ngx_str_t service_name;
};
} // namespace ngx_opentracing
24 changes: 24 additions & 0 deletions zipkin/src/zipkin_tracer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <ngx_opentracing_tracer_options.h>
#include <ngx_opentracing_utility.h>
#include <opentracing/noop.h>
#include <zipkin/opentracing.h>
#include <string>
using namespace zipkin;
using namespace opentracing;

namespace ngx_opentracing {
std::shared_ptr<Tracer> make_tracer(const tracer_options_t &options) {
ZipkinOtTracerOptions tracer_options;
if (options.collector_host.data)
tracer_options.collector_host = to_string(options.collector_host);
if (options.collector_port.data)
// TODO: Check for errors here?
tracer_options.collector_port =
std::stoi(to_string(options.collector_port));
if (options.service_name.data)
tracer_options.service_name = to_string(options.service_name);
else
tracer_options.service_name = "nginx";
return makeZipkinOtTracer(tracer_options);
}
} // namespace ngx_opentracing
10 changes: 10 additions & 0 deletions zipkin/tracer_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE_INCS="$CORE_INCS $ngx_addon_dir/zipkin/include"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
$ngx_addon_dir/zipkin/src/zipkin_tracer.cpp"
NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
$ngx_addon_dir/zipkin/include/ngx_opentracing_tracer_options.h \
$ngx_addon_dir/zipkin/include/ngx_opentracing_tracer_commands.def"
CORE_LIBS="$CORE_LIBS \
-lcurl \
-lzipkin \
-lzipkin_opentracing"

0 comments on commit 46c54f7

Please sign in to comment.