|
| 1 | +# OpenTracing Support |
| 2 | +The Ingress Controller supports [OpenTracing](http://opentracing.io/) with the third-party module [opentracing-contrib/nginx-opentracing](https://github.com/opentracing-contrib/nginx-opentracing). |
| 3 | + |
| 4 | +This document explains how to use OpenTracing with the Ingress Controller. Additionally, we have an [example](../examples/opentracing/README.md) on how to enable OpenTracing for a simple web application using Jaeger as a tracer. |
| 5 | + |
| 6 | +## Prerequisites |
| 7 | +1. **Use the Ingress Controller image with OpenTracing.** The default Ingress Controller images don’t include the OpenTraing module. To use OpenTracing, you need to build the image with that module. Follow the build instructions to build the image using `DockerfileWithOpentracing` for NGINX or `DockerfileWithOpentracingForPlus` for NGINX Plus. |
| 8 | +By default, the Dockerfiles install Jaeger as a tracer. However, it is possible to replace Jaeger with other supported [tracers](https://github.com/opentracing-contrib/nginx-opentracing#building-from-source). For that, please modify the Dockerfile accordingly: |
| 9 | + 1. Change the download line in the tracer-downloader stage of the Dockerfile to download the right tracer. |
| 10 | + 1. Edit the COPY line of the final image to copy the previously downloaded tracer to the image |
| 11 | + |
| 12 | +1. **Load the OpenTracing module.** You need to load the module with the configuration for the chosen tracer using the following ConfigMap keys: |
| 13 | + * `opentracing-tracer`: sets the path to the vendor tracer binary plugin. This is the path you used in the COPY line of step *ii* above. |
| 14 | + * `opentracing-tracer-config`: sets the tracer configuration in JSON format. |
| 15 | + |
| 16 | + Below an example on how to use those keys to load the module with Jaeger tracer: |
| 17 | + ```yaml |
| 18 | + opentracing-tracer: "/usr/local/lib/libjaegertracing_plugin.so" |
| 19 | + opentracing-tracer-config: | |
| 20 | + { |
| 21 | + "service_name": "nginx-ingress", |
| 22 | + "sampler": { |
| 23 | + "type": "const", |
| 24 | + "param": 1 |
| 25 | + }, |
| 26 | + "reporter": { |
| 27 | + "localAgentHostPort": "jaeger-agent.default.svc.cluster.local:6831" |
| 28 | + } |
| 29 | + } |
| 30 | + ``` |
| 31 | +
|
| 32 | +## Enable OpenTracing Globally |
| 33 | +To enable OpenTracing globally (for all Ingress, VirtualServer and VirtualServerRoute resources), set the `opentracing` ConfigMap key to `True`: |
| 34 | + |
| 35 | +```yaml |
| 36 | +opentracing: True |
| 37 | +``` |
| 38 | + |
| 39 | +## Enable/Disable OpenTracing per Ingress Resource |
| 40 | + |
| 41 | +It is possible to use annotations to enable or disable OpenTracing for a specific Ingress Resource. As mentioned in the prerequisites section, both `opentracing-tracer` and `opentracing-tracer-config` must be configured. |
| 42 | + |
| 43 | +Consider the following two cases: |
| 44 | +1. OpenTracing is globally disabled. |
| 45 | + 1. To enable OpenTracing for a specific Ingress Resource, use the server snippet annotation: |
| 46 | + ```yaml |
| 47 | + nginx.org/server-snippets: | |
| 48 | + opentracing on; |
| 49 | + ``` |
| 50 | + 1. To enable OpenTracing for specific paths, (1) you need to use [Mergeable Ingress resources](../examples/mergeable-ingress-types/README.md) and (2) use the location snippets annotation to enable OpenTracing for the paths of a specific Minion Ingress resource: |
| 51 | + ```yaml |
| 52 | + nginx.org/location-snippets: | |
| 53 | + opentracing on; |
| 54 | + ``` |
| 55 | + |
| 56 | +2. OpenTracing is globally enabled: |
| 57 | + 1. To disable OpenTracing for a specific Ingress Resource, use the server snippet annotation: |
| 58 | + ```yaml |
| 59 | + nginx.org/server-snippets: | |
| 60 | + opentracing off; |
| 61 | + ``` |
| 62 | + |
| 63 | + 1. To disable OpenTracing for specific paths, (1) you need to use [Mergeable Ingress resources](../examples/mergeable-ingress-types/README.md) and (2) use the location snippets annotation to disable OpenTracing for the paths of a specific Minion Ingress resource: |
| 64 | + ```yaml |
| 65 | + nginx.org/location-snippets: | |
| 66 | + opentracing off; |
| 67 | + ``` |
| 68 | + |
| 69 | +## Customize OpenTracing |
| 70 | + |
| 71 | +You can customize OpenTracing though the supported [OpenTracing module directives](https://github.com/opentracing-contrib/nginx-opentracing/blob/master/doc/Reference.md). Use the snippets ConfigMap keys or annotations to insert those directives into the http, server or location contexts of the generated NGINX configuration. |
| 72 | + |
| 73 | +For example, to propagate the active span context for upstream requests, it is required to set the `opentracing_propagate_context` directive, which you can add to an Ingress resource using the location snippets annotation: |
| 74 | + |
| 75 | +```yaml |
| 76 | +nginx.org/location-snippets: | |
| 77 | + opentracing_propagate_context; |
| 78 | +``` |
| 79 | + |
| 80 | +**Note**: `opentracing_propagate_context` and `opentracing_grpc_propagate_context` directives can be used in http, server or location contexts according to the [module documentation](https://github.com/opentracing-contrib/nginx-opentracing/blob/master/doc/Reference.md#opentracing_propagate_context). However, because of the way the module works and how the Ingress Controller generates the NGINX configuration, it is only possible to use the directive in the location context. |
0 commit comments