|
| 1 | +--- |
| 2 | +# We use sentence case and present imperative tone |
| 3 | +title: "Enable OpenTelemetry" |
| 4 | +# Weights are assigned in increments of 100: determines sorting order |
| 5 | +weight: 300 |
| 6 | +# Creates a table of contents and sidebar, useful for large documents |
| 7 | +toc: true |
| 8 | +# Types have a 1:1 relationship with Hugo archetypes, so you shouldn't need to change this |
| 9 | +nd-content-type: how-to |
| 10 | +# Intended for internal catalogue and search, case sensitive: |
| 11 | +# Agent, N4Azure, NIC, NIM, NGF, NAP-DOS, NAP-WAF, NGINX One, NGINX+, Solutions, Unit |
| 12 | +nd-product: NIC |
| 13 | +--- |
| 14 | + |
| 15 | +This topic describes how to enable [OpenTelemetry](https://opentelemetry.io/) for F5 NGINX Ingress Controller using the [native NGINX module](https://nginx.org/en/docs/ngx_otel_module.html). |
| 16 | + |
| 17 | +## Before you begin |
| 18 | + |
| 19 | +To complete this guide, you need the following pre-requisites: |
| 20 | + |
| 21 | +- An [NGINX Ingress Controller installation]({{< ref "/nic/installation/" >}}) with OpenTelemetry (v5.1.0+) |
| 22 | + |
| 23 | +## Load the OpenTelemetry module |
| 24 | + |
| 25 | +To enable OpenTelemetry, you must first load the module by adding the [_otel-exporter-endpoint_ ConfigMap key]({{< ref "/nic/configuration/global-configuration/configmap-resource.md#modules" >}}), which takes an endpoint argument. |
| 26 | + |
| 27 | +The following is an example of a OpenTelemetry collector running in your cluster as the target for exporting data: |
| 28 | + |
| 29 | +```yaml |
| 30 | +otel-exporter-endpoint: "http://otel-collector.default.svc.cluster.local:4317" |
| 31 | +``` |
| 32 | +
|
| 33 | +A complete ConfigMap example with all OpenTelemetry options could look as follows: |
| 34 | +
|
| 35 | +{{< ghcode "https://raw.githubusercontent.com/nginx/kubernetes-ingress/refs/heads/main/examples/shared-examples/otel/nginx-config.yaml" >}} |
| 36 | +
|
| 37 | +## Enable OpenTelemetry |
| 38 | +
|
| 39 | +Once you have loaded the module, you can now enable OpenTelemetry. |
| 40 | +
|
| 41 | +You can configure it globally for all resources, or on a per resource basis. |
| 42 | +
|
| 43 | +### Global |
| 44 | +
|
| 45 | +To enable OpenTelemetry for all resources, set the _otel-trace-in-http_ ConfigMap key to `true`: |
| 46 | + |
| 47 | +```yaml |
| 48 | +otel-trace-in-http: "true" |
| 49 | +``` |
| 50 | + |
| 51 | +### Per resource |
| 52 | + |
| 53 | +You can configure OpenTelemetry on a per resource basis in NGINX Ingress Controller. |
| 54 | + |
| 55 | +For this functionality, you must [enable snippets]({{< ref "/nic/configuration/ingress-resources/advanced-configuration-with-snippets.md" >}}) with the `-enable-snippets` command-line argument. |
| 56 | + |
| 57 | +Based on the state of global configuration, you can selectively enable or disable metrics for each resource. |
| 58 | + |
| 59 | +#### Enable a specific resource or path |
| 60 | + |
| 61 | +With OpenTelemetry **disabled** globally, you can enable it for a specific resource using the server snippet annotation: |
| 62 | + |
| 63 | +```yaml |
| 64 | +nginx.org/server-snippets: | |
| 65 | + otel_trace on; |
| 66 | +``` |
| 67 | + |
| 68 | +You can enable it for specific paths using [Mergeable Ingress resources]({{< ref "/nic/configuration/ingress-resources/cross-namespace-configuration.md" >}}). |
| 69 | + |
| 70 | +Use the server snippet annotation for the paths of a specific Minion Ingress resource: |
| 71 | + |
| 72 | +```yaml |
| 73 | +nginx.org/location-snippets: | |
| 74 | + otel_trace on; |
| 75 | +``` |
| 76 | + |
| 77 | +#### Disable a specific resource or path |
| 78 | + |
| 79 | +With OpenTelemetry **enabled** globally, you can disable it for a specific resource using the server snippet annotation: |
| 80 | + |
| 81 | + ```yaml |
| 82 | +nginx.org/server-snippets: | |
| 83 | + otel_trace off; |
| 84 | +``` |
| 85 | + |
| 86 | +You can disable it for specific paths using [Mergeable Ingress resources]({{< ref "/nic/configuration/ingress-resources/cross-namespace-configuration.md" >}}). |
| 87 | + |
| 88 | +Use the server snippet annotation for the paths of a specific Minion Ingress resource: |
| 89 | + |
| 90 | +```yaml |
| 91 | +nginx.org/location-snippets: | |
| 92 | + otel_trace off; |
| 93 | +``` |
| 94 | + |
| 95 | +## Customize OpenTelemetry |
| 96 | + |
| 97 | +{{< call-out "note" >}} |
| 98 | + |
| 99 | +You cannot modify the additional directives in the _otel_exporter_ block using snippets. |
| 100 | + |
| 101 | +{{< /call-out >}} |
| 102 | + |
| 103 | +You can customize OpenTelemetry through the supported [OpenTelemetry module directives](https://nginx.org/en/docs/ngx_otel_module.html). |
| 104 | + |
| 105 | +Use the `location-snippets` ConfigMap keys or annotations to insert those directives into the generated NGINX configuration. |
0 commit comments