|
| 1 | +--- |
| 2 | +title: Tyk API Gateway's Native OpenTelemetry Integration |
| 3 | +linkTitle: Tyk API Gateway's Native OpenTelemetry Integration |
| 4 | +date: 2023-11-07 |
| 5 | +author: >- |
| 6 | + [Sonja Chevre](https://github.com/SonjaChevre) (Tyk Technologies) |
| 7 | +--- |
| 8 | + |
| 9 | +{{< blog/integration-badge >}} |
| 10 | + |
| 11 | +We're excited to announce that |
| 12 | +[Tyk API Gateway](https://github.com/TykTechnologies/tyk) has first-class |
| 13 | +support for OpenTelemetry, with native instrumentation built directly into the |
| 14 | +gateway. With Tyk's native OpenTelemetry support, developers and API platform |
| 15 | +teams get end-to-end observability into their API traffic, enabling faster |
| 16 | +troubleshooting and problem resolution. |
| 17 | + |
| 18 | +## Why OpenTelemetry |
| 19 | + |
| 20 | +API gateways, as the front-line proxies for APIs, play a crucial role in both |
| 21 | +the management and security of API traffic. A multitude of critical actions |
| 22 | +occur at the API gateway level. It is essential to monitor all requests, |
| 23 | +including those that never reach the upstream services because of rate-limiting |
| 24 | +rules, an authentication problem, or a caching mechanism. Collecting telemetry |
| 25 | +data at the API Gateway gives a clear entrance point and a complete picture of |
| 26 | +the journey of all the API consumers. |
| 27 | + |
| 28 | +Before OpenTelemetry, Tyk Gateway already supported over 10 different formats |
| 29 | +for exporting metrics, logs, and traces. Maintaining this support demanded |
| 30 | +substantial engineering resources. OpenTelemetry streamlines this process, |
| 31 | +enabling a more efficient and standardized approach to collecting and exporting |
| 32 | +telemetry data. As a result, our users gain the flexibility to transmit their |
| 33 | +telemetry data to an even broader array of |
| 34 | +[observability tools and vendors](/ecosystem/vendors/). |
| 35 | + |
| 36 | +We have now deprecated our support for OpenTracing in favor of OpenTelemetry for |
| 37 | +distributed tracing and plan to leverage OpenTelemetry to streamline the export |
| 38 | +of metrics and logs in the future. |
| 39 | + |
| 40 | +## How to Integrate Tyk with OpenTelemetry |
| 41 | + |
| 42 | +Starting with version 5.2, |
| 43 | +[Tyk API Gateway has native support for OpenTelemetry distributed tracing](https://tyk.io/docs/product-stack/tyk-gateway/advanced-configurations/distributed-tracing/open-telemetry/open-telemetry-overview/). |
| 44 | +Here is how to configure it, enable detailed tracing per API and instrumenting |
| 45 | +custom plugins. |
| 46 | + |
| 47 | +### Enable OpenTelemetry at Gateway Level |
| 48 | + |
| 49 | +Edit Tyk Gateway configuration file to enable OpenTelemetry support, like this: |
| 50 | + |
| 51 | +```json |
| 52 | +{ |
| 53 | + "opentelemetry": { |
| 54 | + "enabled": true |
| 55 | + } |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +You can also enable OpenTelemetry by setting the corresponding environment |
| 60 | +variable: `TYK_GW_OPENTELEMETRY_ENABLED=TRUE`. |
| 61 | + |
| 62 | +By default, OpenTelemetry spans are exported using the gRPC protocol to |
| 63 | +`localhost:4317`. For more configuration options and default values, refer to |
| 64 | +the |
| 65 | +[documentation](https://tyk.io/docs/tyk-oss-gateway/configuration/#opentelemetry). |
| 66 | + |
| 67 | +Tyk will export two spans: one for the total duration of the API call and one |
| 68 | +span for the call to the upstream service, as shown in the following screenshot |
| 69 | +from Jaeger. |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +### Detailed tracing per APIs |
| 74 | + |
| 75 | +Upon enabling OpenTelemetry at the gateway level, you gain the flexibility to |
| 76 | +activate detailed tracing for particular APIs. To do so, simply adjust the |
| 77 | +corresponding API definition and toggle the `detailed_tracing` option to either |
| 78 | +`true` or `false`. The default value for this setting is `false`. With this |
| 79 | +configuration, Tyk will generate a span for every middleware operation carried |
| 80 | +out throughout the API request/response lifecycle. This includes actions like |
| 81 | +API version validation, authentication, authorization, rate limiting, and |
| 82 | +request and response transformation. |
| 83 | + |
| 84 | +Here you can quickly spot an issue reported by the rate limiting middleware: |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +### Instrumenting custom plugins with OpenTelemetry |
| 89 | + |
| 90 | +Tyk supports the use of custom plugins (also called custom middleware) to extend |
| 91 | +its functionality, making it a highly flexible and customizable API gateway |
| 92 | +solution. This extensibility allows developers to tailor Tyk to their specific |
| 93 | +needs, whether it's for enhancing security, adding new authentication methods, |
| 94 | +integrating with third-party services, or implementing custom request/response |
| 95 | +transformations. |
| 96 | + |
| 97 | +By instrumenting custom plugins with OpenTelemetry SDK or Tyk’s OpenTelemetry |
| 98 | +library implementation (wrapper of the OpenTelemetry SDK that all Tyk components |
| 99 | +are sharing for convenience), Tyk users can gain additional insights into their |
| 100 | +custom plugin behavior for better monitoring and quicker troubleshooting. More |
| 101 | +information in Tyk’s documentation: |
| 102 | +[OpenTelemetry Instrumentation in Go Plugins](https://tyk.io/docs/product-stack/tyk-gateway/advanced-configurations/plugins/otel-plugins/). |
| 103 | + |
| 104 | +## What's next? |
| 105 | + |
| 106 | +Now that the |
| 107 | +[first stable release of OTel Go metric SDK has been announced](/blog/2023/otel-go-metrics-sdk-stable/), |
| 108 | +we will be investigating support for OpenTelemetry metrics. Stay tuned for |
| 109 | +updates and don't hesitate to |
| 110 | +[reach out on Tyk's community with any feedback](https://community.tyk.io/). |
0 commit comments