Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix context propagation #37

Merged
merged 86 commits into from
Jun 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
544460e
Add directive for propagation.
rnburn Apr 23, 2018
b001c1e
Add code to discover span context keys.
rnburn May 4, 2018
8ad45f5
Store propagation keys in config.
rnburn May 7, 2018
db03190
Set headers to correspond to the discovered keys.
rnburn May 7, 2018
ceef954
Add a prefix variable for span context expansion.
rnburn May 8, 2018
4472649
Remove singleton.
rnburn May 9, 2018
1be6551
Move context code to handler.
rnburn May 9, 2018
6ef6fe8
Remove unused files.
rnburn May 9, 2018
251a79a
Added SpanContextQuerier.
rnburn May 9, 2018
c04cfac
Add span context expansion.
rnburn May 10, 2018
b4b6165
Add error handling for variable.
rnburn May 14, 2018
43c8474
Handle directive exceptions.
rnburn May 14, 2018
621a49e
Add more error handling to querier.
rnburn May 14, 2018
5a338ee
Add additional error handling.
rnburn May 14, 2018
f9616a8
Add missing exception specifications.
rnburn May 14, 2018
049625f
Remove unused file.
rnburn May 14, 2018
edebae5
Run clang-format.
rnburn May 14, 2018
27e03e7
Replace casting with utility function.
rnburn May 14, 2018
2f713f2
Document propagation code.
rnburn May 15, 2018
7e7ff18
Document opentracing_propagate_context directive.
rnburn May 15, 2018
1419998
Change wording.
rnburn May 15, 2018
a783324
Start converting trivial example.
rnburn May 15, 2018
0879894
Fix propagation in trivial example.
rnburn May 16, 2018
d548e9b
Convert zoo example.
rnburn May 17, 2018
b0fb7ee
Update README.
rnburn May 17, 2018
e15040b
Correct README.
rnburn May 17, 2018
657fc99
Correct README.
rnburn May 17, 2018
2e6af8e
Remove vendor-specific modules.
rnburn May 17, 2018
55ca124
Update opentracing version.
rnburn May 17, 2018
2a7b2c3
Fix CI test.
rnburn May 17, 2018
f9baa07
Disable leak sanitizer.
rnburn May 17, 2018
5c69d51
Fix tracing for internal redirects.
rnburn May 22, 2018
9668e2f
Set up system.testing.
rnburn May 26, 2018
81576e8
Fix permissions.
rnburn May 26, 2018
c20b952
Fix CI commands.
rnburn May 26, 2018
5e9b389
Fix CI commands.
rnburn May 26, 2018
4680023
Fix CI commands.
rnburn May 26, 2018
35514a3
Fix CI commands.
rnburn May 26, 2018
0d06761
Fix CI commands.
rnburn May 26, 2018
22e26cd
Fix CI commands.
rnburn May 26, 2018
9b9c24b
Fix CI commands.
rnburn May 26, 2018
935a748
Fix CI commands.
rnburn May 26, 2018
18e6b3c
Fix CI commands.
rnburn May 26, 2018
1e69bb1
Fix CI commands.
rnburn May 26, 2018
d2cbb85
Fix CI commands.
rnburn May 26, 2018
c2d2e81
Fix CI commands.
rnburn May 26, 2018
57b4bf8
Fix CI commands.
rnburn May 26, 2018
0f42541
Fix CI commands.
rnburn May 26, 2018
8f048f7
Fix CI commands.
rnburn May 26, 2018
68a9c9a
Fix CI commands.
rnburn May 26, 2018
55b64f2
Fix CI commands.
rnburn May 26, 2018
39f3c52
Fix CI commands.
rnburn May 26, 2018
8f677d7
Fix CI commands.
rnburn May 26, 2018
edcebca
Fix CI commands.
rnburn May 26, 2018
2525327
Fix CI commands.
rnburn May 26, 2018
83901ab
Fix CI commands.
rnburn May 26, 2018
300a3d1
Fix CI commands.
rnburn May 26, 2018
ea66fe1
Fix CI commands.
rnburn May 26, 2018
289cd55
Fix CI commands.
rnburn May 26, 2018
946ee93
Fix CI commands.
rnburn May 26, 2018
0ec9570
Fix CI commands.
rnburn May 26, 2018
f6f7d0b
Make test more verbose.
rnburn May 26, 2018
df1f3fb
Add more logging to test.
rnburn May 26, 2018
9d1c4b6
Log docker-compose up commands.
rnburn May 26, 2018
a868a67
Rearrange sleep
rnburn May 26, 2018
6e00521
Store artifacts from testing.
rnburn May 26, 2018
96cd47e
Fix artifacts.
rnburn May 26, 2018
851d899
Fix artifacts.
rnburn May 26, 2018
bcdb3eb
Fix artifacts.
rnburn May 26, 2018
d966c03
Fix artifacts.
rnburn May 26, 2018
24713bc
Fix tearDown.
rnburn May 26, 2018
535ad75
Fix permissions.
rnburn May 26, 2018
0502510
Remove old testing code.
rnburn May 26, 2018
5f212e2
Replace print statements in tests with verbosity.
rnburn May 27, 2018
d08cca0
Add test for tracing locations.
rnburn May 27, 2018
17795d7
Add test for internal redirects.
rnburn May 27, 2018
785b236
Add test for custom tags.
rnburn May 27, 2018
905b88f
Refactor to use opentracing_context_ variable.
rnburn May 28, 2018
3ac3efd
Refactor CI config.
rnburn May 29, 2018
298e058
Add docker build to CI.
rnburn May 29, 2018
521cefe
Document opentracing_context_ variable.
rnburn May 29, 2018
21dc379
Convert examples to use prebuilt docker image.
rnburn May 29, 2018
641411c
Break out the trivial example into separate examples for zipkin and j…
rnburn May 30, 2018
fe6feae
Update tutorial.
rnburn May 31, 2018
acc05f9
Remove hotrod and browser examples.
rnburn May 31, 2018
5a6f5ce
Merge branch 'master' of https://github.com/opentracing-contrib/nginx…
rnburn Jun 1, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
version: 2
jobs:
build:
system_testing:
machine: true
steps:
- checkout
- run:
name: Build nginx-opentracing-ci Docker image
command: docker build -t nginx-opentracing-ci ci
name: system.testing
command: |
pyenv global 3.5.2
python3 --version
pip3.5 --version
pip3.5 install setuptools
pip3.5 install docker
pip3.5 install docker-compose
sudo mkdir /test-log
sudo chmod a+rwx /test-log
export LOG_DIR=/test-log
./ci/do_ci.sh system.testing
- store_artifacts:
path: /test-log
docker_image:
machine: true
steps:
- checkout
- run:
name: Build and Test
command: ./ci/run_ci_docker.sh './ci/do_ci.sh'
command: docker build -t opentracing/nginx-opentracing .

workflows:
version: 2
build_test_and_deploy:
jobs:
- system_testing
- docker_image
27 changes: 13 additions & 14 deletions docker/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ ARG NGINX_LABEL=latest

FROM nginx:${NGINX_LABEL}

ARG OPENTRACING_CPP_VERSION=v1.2.0
ARG ZIPKIN_CPP_VERSION=v0.2.0
ARG LIGHTSTEP_VERSION=v0.6.1
ARG JAEGER_CPP_VERSION=v0.2.0
ARG OPENTRACING_CPP_VERSION=v1.4.0
ARG ZIPKIN_CPP_VERSION=v0.3.1
ARG LIGHTSTEP_VERSION=v0.7.0
ARG JAEGER_CPP_VERSION=v0.4.1
ARG GRPC_VERSION=v1.4.x
ARG NGINX_OPENTRACING_VERSION=v0.2.1

COPY . /src

RUN set -x \
# install nginx-opentracing package dependencies
Expand Down Expand Up @@ -59,16 +60,18 @@ RUN set -x \
&& cmake -DBUILD_SHARED_LIBS=1 -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF .. \
&& make && make install \
&& cd "$tempDir" \
&& ln -s /usr/local/lib/libzipkin_opentracing.so /usr/local/lib/libzipkin_opentracing_plugin.so \
### Build Jaeger cpp-client
&& git clone -b $JAEGER_CPP_VERSION https://github.com/jaegertracing/cpp-client.git jaeger-cpp-client \
&& cd jaeger-cpp-client \
&& mkdir .build && cd .build \
&& cmake -DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DJAEGERTRACING_WITH_YAML_CPP=OFF .. \
-DJAEGERTRACING_WITH_YAML_CPP=ON .. \
&& make && make install \
&& export HUNTER_INSTALL_DIR=$(cat _3rdParty/Hunter/install-root-dir) \
&& cd "$tempDir" \
&& ln -s /usr/local/lib/libjaegertracing.so /usr/local/lib/libjaegertracing_plugin.so \
### Build gRPC
&& git clone -b $GRPC_VERSION https://github.com/grpc/grpc \
&& cd grpc \
Expand All @@ -83,8 +86,8 @@ RUN set -x \
&& cmake -DBUILD_SHARED_LIBS=1 -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF .. \
&& make && make install \
&& cd "$tempDir" \
&& ln -s /usr/local/lib/liblightstep_tracer.so /usr/local/lib/liblightstep_tracer_plugin.so \
### Build nginx-opentracing modules
&& git clone -b $NGINX_OPENTRACING_VERSION https://github.com/opentracing-contrib/nginx-opentracing.git \
&& NGINX_VERSION=`nginx -v 2>&1` && NGINX_VERSION=${NGINX_VERSION#*nginx/} \
&& echo "deb-src http://nginx.org/packages/mainline/debian/ stretch nginx" >> /etc/apt/sources.list \
&& apt-get update \
Expand All @@ -95,18 +98,14 @@ RUN set -x \
&& NGINX_MODULES_PATH=$(nginx -V 2>&1 | grep -oP "modules-path=\K[^\s]*") \
&& auto/configure \
--with-compat \
--add-dynamic-module=${tempDir}/nginx-opentracing/opentracing \
--add-dynamic-module=${tempDir}/nginx-opentracing/zipkin \
--add-dynamic-module=${tempDir}/nginx-opentracing/lightstep \
--add-dynamic-module=${tempDir}/nginx-opentracing/jaeger \
--add-dynamic-module=/src/opentracing \
--with-cc-opt="-I$HUNTER_INSTALL_DIR/include" \
--with-ld-opt="-L$HUNTER_INSTALL_DIR/lib" \
--with-debug \
&& make modules \
&& cp objs/ngx_http_opentracing_module.so $NGINX_MODULES_PATH/ \
&& cp objs/ngx_http_zipkin_module.so $NGINX_MODULES_PATH/ \
&& cp objs/ngx_http_lightstep_module.so $NGINX_MODULES_PATH/ \
&& cp objs/ngx_http_jaeger_module.so $NGINX_MODULES_PATH/ \
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
&& rm -rf /src \
&& rm -rf $HOME/.hunter \
&& if [ -n "$tempDir" ]; then \
apt-get purge -y --auto-remove \
Expand Down
55 changes: 55 additions & 0 deletions Dockerfile-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM ubuntu:18.04

ARG OPENTRACING_CPP_VERSION=v1.4.0
ARG NGINX_VERSION=1.13.12

COPY . /src

RUN set -x \
&& apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y \
build-essential \
gettext \
cmake \
git \
gnupg2 \
software-properties-common \
curl \
python3 \
jq \
ca-certificates \
wget \
libpcre3 libpcre3-dev \
zlib1g-dev \
gcc-8 \
g++-8 \
### Use gcc-8 (the default gcc has this problem when using with address sanitizer:
### https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84428)
&& update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8 \
### Build opentracing-cpp
&& cd / \
&& git clone -b $OPENTRACING_CPP_VERSION https://github.com/opentracing/opentracing-cpp.git \
&& cd opentracing-cpp \
&& mkdir .build && cd .build \
&& cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="-fno-omit-frame-pointer -fsanitize=address" \
-DCMAKE_SHARED_LINKER_FLAGS="-fno-omit-frame-pointer -fsanitize=address" \
-DCMAKE_EXE_LINKER_FLAGS="-fno-omit-frame-pointer -fsanitize=address" \
-DBUILD_TESTING=OFF .. \
&& make && make install \
### Build nginx
&& cd /src \
&& wget -O nginx-release-${NGINX_VERSION}.tar.gz https://github.com/nginx/nginx/archive/release-${NGINX_VERSION}.tar.gz \
&& tar zxf nginx-release-${NGINX_VERSION}.tar.gz \
&& cd /src/nginx-release-${NGINX_VERSION} \
# Temporarily disable leak sanitizer to get around false positives in build
&& export ASAN_OPTIONS=detect_leaks=0 \
&& export CFLAGS="-Wno-error" \
&& auto/configure \
--with-compat \
--with-debug \
--with-cc-opt="-O1 -g -fno-omit-frame-pointer -fsanitize=address" \
--with-ld-opt="-g -fno-omit-frame-pointer -fsanitize=address" \
--add-dynamic-module=/src/opentracing \
&& make && make install
CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]
95 changes: 63 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,63 +23,94 @@ Building
```
$ tar zxvf nginx-1.9.x.tar.gz
$ cd nginx-1.9.x
$ ./configure --add-dynamic-module=/absolute/path/to/nginx-opentracing/opentracing \
# To enable tracing with Jaeger
--add-dynamic-module=/absolute/path/to/nginx-opentracing/jaeger \
# To enable tracing with Zipkin
--add-dynamic-module=/absolute/path/to/nginx-opentracing/zipkin \
# To enable tracing with LightStep
--add-dynamic-module=/absolute/path/to/nginx-opentracing/lightstep
$ ./configure --add-dynamic-module=/absolute/path/to/nginx-opentracing/opentracing
$ make && sudo make install
```

You will also need to install a C++ tracer for either [Jaeger](https://github.com/jaegertracing/jaeger-client-cpp), [LightStep](
https://github.com/lightstep/lightstep-tracer-cpp), or [Zipkin](https://github.com/rnburn/zipkin-cpp-opentracing). For linux x86-64, portable binary plugins are available:
```
# Jaeger
wget https://github.com/jaegertracing/jaeger-client-cpp/releases/download/v0.4.0/libjaegertracing_plugin.linux_amd64.so -O /usr/local/lib/libjaegertracing_plugin.so

# LightStep
wget -O - https://github.com/lightstep/lightstep-tracer-cpp/releases/download/v0.7.0/linux-amd64-liblightstep_tracer_plugin.so.gz | gunzip -c > /usr/local/lib/liblightstep_tracer_plugin.so

# Zipkin
wget -O - https://github.com/rnburn/zipkin-cpp-opentracing/releases/download/v0.3.1/linux-amd64-libzipkin_opentracing_plugin.so.gz gunzip -c > /usr/local/lib/libzipkin_opentracing_plugin.so

```

Getting Started
---------------
First, write a configuration for the tracer used. Below's an example of what
a Jaeger configuration might look like:

/etc/jaeger-nginx-config.json
```
{
"service_name": "nginx",
"sampler": {
"type": "const",
"param": 1
},
"reporter": {
"localAgentHostPort": "jaeger:6831"
},
"headers": {
"jaegerDebugHeader": "jaeger-debug-id",
"jaegerBaggageHeader": "jaeger-baggage",
"traceBaggageHeaderPrefix": "uberctx-",
},
"baggage_restrictions": {
"denyBaggageOnInitializationFailure": false,
"hostPort": ""
}
}
```

See the vendor documentation for details on what options are available.

You can then set up NGINX for distributed tracing by adding the following to
nginx.conf:
```
# Load the OpenTracing dynamic module.
load_module modules/ngx_http_opentracing_module.so;

# Load a vendor OpenTracing dynamic module.
# For example,
# load_module modules/ngx_http_jaeger_module.so;
# or
# load_module modules/ngx_http_zipkin_module.so;
# or
# load_module modules/ngx_http_lightstep_module.so;

http {
# Configure your vendor's tracer.
# For example,
# jaeger_service_name my-nginx-server;
# ...
# or
# zipkin_collector_host localhost;
# ...
# or
# lightstep_access_token ACCESSTOKEN;
# ....
# Load a vendor tracer
opentracing_load_tracer /usr/local/lib/libjaegertracing_plugin.so /etc/jaeger-nginx-config.json;

# or
# opentracing_load_tracer /usr/local/lib/liblightstep_tracer_plugin.so /path/to/config;
# or
# opentracing_load_tracer /usr/local/lib/libzipkin_opentracing_plugin.so /path/to/config;

# Enable tracing for all requests.
opentracing on;

# Optionally, set additional tags.
opentracing_tag http_user_agent $http_user_agent;

location ~ \.php$ {
upstream backend {
server app-service:9001;
}

location ~ {
# The operation name used for spans defaults to the name of the location
# block, but you can use this directive to customize it.
opentracing_operation_name $uri;

fastcgi_pass 127.0.0.1:1025;
# Propagate the active span context upstream, so that the trace can be
# continued by the backend.
# See http://opentracing.io/documentation/pages/api/cross-process-tracing.html
opentracing_propagate_context;

proxy_pass http://backend;
}
}
```

See [Tutorial](doc/Tutorial.md) for a more complete example,
[Reference](doc/Directives.md) for a list of available OpenTracing-related
directives, and [Jaeger](jaeger/doc/Directives.md),
[Zipkin](zipkin/doc/Directives.md), and
[LightStep](lightstep/doc/Directives.md) for a list of vendor tracing
[Reference](doc/Reference.md) for a list of available OpenTracing-related
directives.

35 changes: 0 additions & 35 deletions ci/Dockerfile

This file was deleted.

28 changes: 9 additions & 19 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@

set -e

NGINX_VERSION=`nginx -v 2>&1` && NGINX_VERSION=${NGINX_VERSION#*nginx/}
NGINX_MODULES_PATH=$(nginx -V 2>&1 | grep -oP "modules-path=\K[^\s]*")
cd /src/nginx-release-${NGINX_VERSION}
auto/configure \
--with-compat \
--add-dynamic-module=/src/nginx-opentracing/opentracing
make modules
cp objs/ngx_http_opentracing_module.so $NGINX_MODULES_PATH/
cd /src/nginx-opentracing
export MOCKTRACER_LIBRARY=/usr/local/lib/libopentracing_mocktracer.so
export NGINX_OPENTRACING_MODULE="$NGINX_MODULES_PATH/ngx_http_opentracing_module.so"
export NGINX_OPENTRACING_TEST_DIR=/nginx-opentracing-test
mkdir $NGINX_OPENTRACING_TEST_DIR
chmod a+rwx $NGINX_OPENTRACING_TEST_DIR
cd test
for i in *;
do
"$i/run.sh"
done
[ -z "${SRC_DIR}" ] && export SRC_DIR="`pwd`"

if [[ "$1" == "system.testing" ]]; then
docker build -t nginx-opentracing-test/nginx -f Dockerfile-test .
cd test
docker build -t nginx-opentracing-test/backend -f Dockerfile-backend .
python3 nginx_opentracing_test.py
exit 0
fi
14 changes: 0 additions & 14 deletions ci/run_ci_docker.sh

This file was deleted.

Loading