Industry:
API Management Software
Use Case:
Trace-based Testing
Employees:
100-1000
HQ:
London, England
Tracetest ensures reliable testing across local and CI envs and has a permanent spot in the Tyk toolkit to ensure our future releases are rock solid.
We’ve just launched Tyk API Gateway’s support for OpenTelemetry, which means that with Tyk’s native OpenTelemetry integration, developers and API platform teams gain complete visibility into their API traffic, making troubleshooting and issue resolution faster.
In our development process, our team questioned: How do we ensure our instrumentation undergoes thorough testing with every Tyk Gateway update? How do we prevent errors from reporting misleading information and impacting our users’ API monitoring?
In this blog post, I want to share how we have implemented Tracetest for effective integration testing of OpenTelemetry in Tyk’s open source Gateway.
Tyk’s diverse proxying capabilities—encompassing HTTP, HTTPS, gRPC, GraphQL, and our proprietary Tyk internal proxy protocol—introduce complexity to our environment.
This diversity, alongside a dynamic middleware chain that adjusts based on the Tyk API configuration, presents a distinctive challenge: guaranteeing that our OpenTelemetry implementation accurately captures and reports data across these varied protocols.
In our search for a solution, we found our answer in Tracetest. Designed specifically for Observability-Driven Development (ODD), Tracetest became an indispensable tool in our arsenal. It allowed us to build and execute comprehensive end-to-end tests encompassing the full breadth of our API scenarios.
A key aspect of our integration strategy was ensuring a seamless and consistent testing experience locally and on our Continuous Integration (CI) platform. This approach was crucial for improving the Developer Experience (DX), allowing our team to test new features efficiently and fix issues under similar conditions, irrespective of the environment.
We achieved this by crafting a comprehensive Taskfile, which included a series of commands for setting up, executing, and tearing down our e2e OpenTelemetry+Tyk+Tracetest testing environment. These commands – detailed in our Taskfile – are integral to our testing workflow and include:
Our GitHub Actions pipeline, which can be viewed in detail here, is configured to trigger each pull request to the master branch, ensuring that every change proposed is thoroughly vetted for compatibility and performance before integration.
Thanks to the verbose option of Tracetest CLI, we can have a clear understanding of what’s tested and what scenarios fail on each PR, for example:
This uniformity between local and CI testing environments not only streamlines the development process but also instils confidence in our team. Developers can replicate the exact testing scenarios locally executed in CI, ensuring that any issues are caught early and reliably.
Our approach to testing goes far beyond basic checks; it’s a comprehensive exploration of the varied landscape that an API gateway presents:
This is an example of a basic test scenario for a valid Tyk API request:
```
type: Test
spec:
id: 4pnmVurVg
name: HTTP Test API - ok request
trigger:
type: http
httpRequest:
method: GET
url: 'tyk:8080/test/ip'
headers:
- key: Content-Type
value: application/json
specs:
- selector: 'span[tracetest.span.type="http" name="GET /test/ip" http.method="GET"]'
name: Test main span attributes
assertions:
- 'attr:http.method = "GET"'
- 'attr:http.status_code = 200'
- 'attr:http.user_agent = "Go-http-client/1.1"'
- 'attr:http.wrote_bytes != 0'
- 'attr:tracetest.span.type = "http"'
- 'attr:tyk.api.id = "3"'
- 'attr:tyk.api.name = "TestAPI"'
- 'attr:tyk.api.orgid = "default"'
- 'attr:tyk.api.tags not-contains "test"'
- 'attr:tyk.api.path = "/test/"'
- selector: >-
span[tracetest.span.type="general" name="Tracetest trigger"]
span[tracetest.span.type="general"]
name: Check if it contains Version and Rate middlewares
assertions:
- 'attr:tracetest.selected_spans.count = 2'
- 'attr:tracetest.span.parent_id != ""'
- selector: 'span[tracetest.span.type="general" name="RateCheckMW"]'
name: Check for RateCheckMiddleware
assertions:
- 'attr:name = "RateCheckMW"'
- selector: 'span[tracetest.span.type="general" name="VersionCheck"]'
name: VersionCheck MW attributes
assertions:
- 'attr:tyk.api.version = "Non Versioned"'
```
You can find the whole list of tested scenarios here.
This endeavour goes beyond a one-time integration; it’s about continuous improvement and adaptation. As we add more scenarios to our tests, we refine our approach, ensuring that every step in our API management is accurately reflected in our traces.
In embracing OpenTelemetry for Tyk API Gateway, we needed to ensure robust integration testing. Tracetest is our solution to accurate data reporting across diverse protocols. Now seamlessly woven into our workflow, Tracetest ensures consistent, reliable testing across local and CI environments and has a permanent spot in the Tyk toolkit to make sure our future releases are rock solid.
Want to connect with the team about Tyk API Gateway’s support for OpenTelemetry? You can ask us anything here.
This blog post was initially published on tyk.io.
Tracetest lets you build integration and end-to-end tests 98% faster with distributed traces. No plumbing, no mocks, no fakes – test against real data. Assert against both the response and trace data at every point of a request transaction. Validate timing of trace spans, including databases. Assert against side-effects, including Kafka and message queues. Save and run tests visually and programatically with CI build jobs. Get started with Tracetest for free and start building tests in minutes instead of days.