Skip to content

Commit

Permalink
add Nginx tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
steveww committed Jun 25, 2021
1 parent e80da6d commit d71c121
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ To see the application performance results in the Instana dashboard, you will fi
## Build from Source
To optionally build from source (you will need a newish version of Docker to do this) use Docker Compose. Optionally edit the `.env` file to specify an alternative image registry and version tag; see the official [documentation](https://docs.docker.com/compose/env-file/) for more information.

To download the tracing module for Nginx, it needs a valid Instana agent key. Set this in the environment before starting the build.

```shell
$ export INSTANA_AGENT_KEY="<your agent key>"
```

Now build all the images.

```shell
$ docker-compose build
```
Expand Down
17 changes: 10 additions & 7 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
- robot-shop
healthcheck:
test: [ "CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost:8080/health" ]
interval: 1s
interval: 10s
timeout: 10s
retries: 3
logging:
Expand All @@ -49,7 +49,7 @@ services:
- robot-shop
healthcheck:
test: [ "CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost:8080/health" ]
interval: 1s
interval: 10s
timeout: 10s
retries: 3
logging:
Expand All @@ -64,7 +64,7 @@ services:
- robot-shop
healthcheck:
test: [ "CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost:8080/health" ]
interval: 1s
interval: 10s
timeout: 10s
retries: 3
logging:
Expand All @@ -89,7 +89,7 @@ services:
- robot-shop
healthcheck:
test: ["CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost:8080/health"]
interval: 1s
interval: 10s
timeout: 10s
retries: 3
logging:
Expand All @@ -106,7 +106,7 @@ services:
- mysql
healthcheck:
test: ["CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost/_health"]
interval: 1s
interval: 10s
timeout: 10s
retries: 3
logging:
Expand All @@ -121,7 +121,7 @@ services:
- robot-shop
healthcheck:
test: ["CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost:8080/health"]
interval: 1s
interval: 10s
timeout: 10s
retries: 3
# Uncomment to change payment gateway
Expand All @@ -142,6 +142,9 @@ services:
web:
build:
context: web
args:
# agent key to download tracing libs
KEY: ${INSTANA_AGENT_KEY}
image: ${REPO}/rs-web:${TAG}
depends_on:
- catalogue
Expand All @@ -154,7 +157,7 @@ services:
- robot-shop
healthcheck:
test: [ "CMD", "curl", "-H", "X-INSTANA-SYNTHETIC: 1", "-f", "http://localhost:8080/" ]
interval: 1s
interval: 10s
timeout: 10s
retries: 3
# Uncomment to enable Instana EUM
Expand Down
24 changes: 22 additions & 2 deletions web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
FROM nginx:1.19
FROM alpine AS build
ARG KEY

WORKDIR /instana

RUN apk add --update --no-cache curl

RUN curl \
--output instana.zip \
--user "_:$KEY" \
https://artifact-public.instana.io/artifactory/shared/com/instana/nginx_tracing/1.1.2/linux-amd64-glibc-nginx-1.20.1.zip && \
unzip instana.zip && \
mv glibc-libinstana_sensor.so libinstana_sensor.so && \
mv glibc-nginx-1.20.1-ngx_http_ot_module.so ngx_http_opentracing_module.so


FROM nginx:1.20.1

EXPOSE 8080

Expand All @@ -7,7 +23,11 @@ ENV CATALOGUE_HOST=catalogue \
CART_HOST=cart \
SHIPPING_HOST=shipping \
PAYMENT_HOST=payment \
RATINGS_HOST=ratings
RATINGS_HOST=ratings \
INSTANA_SERVICE_NAME=nginx-web

# Instana tracing
COPY --from=build /instana/*.so /tmp/

COPY entrypoint.sh /root/
ENTRYPOINT ["/root/entrypoint.sh"]
Expand Down
4 changes: 4 additions & 0 deletions web/default.conf.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Instana tracing
opentracing_load_tracer /usr/local/lib/libinstana_sensor.so /etc/instana-config.json;
opentracing_propagate_context;

server {
listen 8080;
server_name localhost;
Expand Down
18 changes: 18 additions & 0 deletions web/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,23 @@ chmod 644 $BASE_DIR/eum.html
# apply environment variables to default.conf
envsubst '${CATALOGUE_HOST} ${USER_HOST} ${CART_HOST} ${SHIPPING_HOST} ${PAYMENT_HOST} ${RATINGS_HOST}' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf

# Patching for Instana tracing
mv /tmp/ngx_http_opentracing_module.so /usr/lib/nginx/modules
mv /tmp/libinstana_sensor.so /usr/local/lib
cat - /etc/nginx/nginx.conf << !EOF! > /tmp/nginx.conf
# Extra configuration for Instana tracing
load_module modules/ngx_http_opentracing_module.so;
# Pass through these env vars
env INSTANA_SERVICE_NAME;
env INSTANA_AGENT_HOST;
env INSTANA_AGENT_PORT;
env INSTANA_MAX_BUFFERED_SPANS;
env INSTANA_DEV;
!EOF!

mv /tmp/nginx.conf /etc/nginx/nginx.conf
echo "{}" > /etc/instana-config.json

exec nginx-debug -g "daemon off;"

0 comments on commit d71c121

Please sign in to comment.