|
| 1 | +# Learn how to use OpenTelemetry with F5 NGINX Ingress Controller |
| 2 | + |
| 3 | +NGINX Ingress Controller supports [OpenTelemetry](https://opentelemetry.io/) with the NGINX module [ngx_otel_module](https://nginx.org/en/docs/ngx_otel_module.html). |
| 4 | <
10BC0
span class="diff-text-marker">+ |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. Use a NGINX Ingress Controller image that contains OpenTelemetry. |
| 8 | + |
| 9 | + - All NGINX Ingress Controller v5.1 images or later will contain support for `ngx_otel_module`. |
| 10 | + - Alternatively, you follow [Build NGINX Ingress Controller](https://docs.nginx.com/nginx-ingress-controller/installation/build-nginx-ingress-controller/) using `debian-image` (or `alpine-image` or `ubi-image`) for NGINX or `debian-image-plus` (or `alpine-image-plus`or `ubi-image-plus`) for NGINX Plus. |
| 11 | + |
| 12 | +1. Enable snippets annotations by setting the [`enable-snippets`](https://docs.nginx.com/nginx-ingress-controller/configuration/global-configuration/command-line-arguments/#-enable-snippets) command-line argument to true. |
| 13 | + |
| 14 | +1. Load the OpenTelemetry module. |
| 15 | + |
| 16 | + You need to load the module using the following ConfigMap key: |
| 17 | + |
| 18 | + - `otel-exporter-endpoint`: sets the endpoint to export your OpenTelemetry traces to. |
| 19 | + |
| 20 | + The following example shows how to use this to export data to an OpenTelemetry collector running in your cluster: |
| 21 | + |
| 22 | + ```yaml |
| 23 | + otel-exporter-endpoint: "http://otel-collector.default.svc.cluster.local:4317" |
| 24 | + ``` |
| 25 | +
|
| 26 | +## Enable OpenTelemetry globally |
| 27 | +
|
| 28 | +To enable OpenTelemetry globally (for all Ingress, VirtualServer and VirtualServerRoute resources), set the `otel-trace-in-http` ConfigMap key to `true`: |
| 29 | + |
| 30 | +```yaml |
| 31 | +otel-trace-in-http: "true" |
| 32 | +``` |
| 33 | + |
| 34 | +## Enable or disable OpenTelemetry per Ingress resource |
| 35 | + |
| 36 | +You can use annotations to enable or disable OpenTelemetry for a specific Ingress resource. As mentioned in the prerequisites section, `otel-exporter-endpoint` must be configured. |
| 37 | + |
| 38 | +Consider the following two cases: |
| 39 | + |
| 40 | +### OpenTelemetry is globally disabled |
| 41 | + |
| 42 | +1. To enable OpenTelemetry for a specific Ingress resource, use the server snippet annotation: |
| 43 | + |
| 44 | + ```yaml |
| 45 | + nginx.org/server-snippets: | |
| 46 | + otel_trace on; |
| 47 | + ``` |
| 48 | + |
| 49 | +1. To enable OpenTelemetry for specific paths: |
| 50 | + |
| 51 | + - You need to use [Mergeable Ingress resources](https://docs.nginx.com/nginx-ingress-controller/configuration/ingress-resources/cross-namespace-configuration) |
| 52 | + - You need to use the location snippets annotation to enable OpenTelemetry for the paths of a specific Minion Ingress resource: |
| 53 | + |
| 54 | + ```yaml |
| 55 | + nginx.org/location-snippets: | |
| 56 | + otel_trace on; |
| 57 | + ``` |
| 58 | + |
| 59 | +### OpenTelemetry is globally enabled |
| 60 | + |
| 61 | +1. To disable OpenTelemetry for a specific Ingress resource, use the server snippet annotation: |
| 62 | + |
| 63 | + ```yaml |
| 64 | + nginx.org/server-snippets: | |
| 65 | + otel_trace off; |
| 66 | + ``` |
| 67 | + |
| 68 | +1. To disable OpenTelemetry for specific paths: |
| 69 | + |
| 70 | + - You need to use [Mergeable Ingress resources](https://docs.nginx.com/nginx-ingress-controller/configuration/ingress-resources/cross-namespace-configuration) |
| 71 | + - You need to use the location snippets annotation to disable OpenTelemetry for the paths of a specific Minion Ingress resource: |
| 72 | + |
| 73 | + ```yaml |
| 74 | + nginx.org/location-snippets: | |
| 75 | + otel_trace off; |
| 76 | + ``` |
| 77 | + |
| 78 | +## Customize OpenTelemetry |
| 79 | + |
| 80 | +You can customize OpenTelemetry through the supported [OpenTelemetry module directives](https://nginx.org/en/docs/ngx_otel_module.html). Use the `location-snippets` ConfigMap keys or annotations to insert those directives into the generated NGINX configuration. |
| 81 | + |
| 82 | +> Note: At present, the additional directives in the `otel_exporter` block cannot be modified with snippets. |
0 commit comments