Correlate results with Grafana Cloud Traces
When you run a cloud test, in addition to analyzing the metrics and logs generated by the k6 instances, you can also dive deeper into what was happening inside the services while the test was running, thanks to the k6 integration with Grafana Cloud Traces.
k6 aggregates and correlates all the tracing telemetry your services generate during the test, summarizes it, and gives you the tools to analyze it and extract the insights you need.
To leverage this integration, there are two steps you need to do:
- Send your services tracing data to Grafana Cloud Traces.
- Enable the tracing feature in your k6 test.
Note
It can take up to 12 hours for our systems to enable the tracing integration in your Grafana Cloud account after you send your first traces to Grafana Cloud Traces. If you don’t see data in the Tracing tab in your test results, please wait a few hours and try running the test again. If the problem persists, please contact Support.
Requirements
- k6 v0.46.0 or higher
- Grafana Cloud account
- A basic understanding of tracing. Refer to Get Started with Grafana Tempo if you want to learn more about tracing.
Get started
The first step is to send your services tracing data to Grafana Cloud Traces. Usually, this can be done by modifying your tracing pipeline (for example, agents) to send the traces to the cloud. This step only needs to be done once, and usually, the Platform/SRE team in your organization is the one who has ownership over it.
The second step required is to enable the tracing feature in your k6 tests. You need to import the tracing module and
use the instrumentHTTP
helper to enable tracing. Make sure to set the propagator to the one your application
understands (in most cases, that will be w3c).
import tracing from 'k6/experimental/tracing';
import http from 'k6/http';
tracing.instrumentHTTP({
// possible values: "w3c", "jaeger"
propagator: 'w3c',
});
export default () => {
http.get('http://httpbin.org/get');
};
Once you do this, k6 will generate the traceID and propagate it downwards to your services. Later on, the platform uses this to correlate k6’s data with your tracing data.
That’s it. Now, when you run a test in Grafana Cloud k6 or run a test locally and stream the results, you will get access to the new Tracing tab in the test results. This tab shows you all your tracing data aggregated in an easy-to-consume way.
Note
If you are running your tests using the Cloud output, you must pass
K6_CLOUD_TRACES_ENABLED=true
to enable the feature. For example:K6_CLOUD_TRACES_ENABLED=true k6 run --out cloud script.js
Explore results
To explore the results generated by this integration, you can:
- Navigate to a test result view.
- Open the HTTP tab.
- Click on a request.
- Click on “View Traces”.
Now, you have access to a summary of all the server-side tracing data generated by this k6 request. In this table, each row is a span. A span is a unit of work within a trace that has a start time relative to the beginning of the trace, a duration, and an operation name for the unit of work.
With this data, you can quickly pinpoint if any span is failing a lot or taking too much time out of your request.
To inspect a span in detail:
- Select its row.
- In the expanded row, inspect the different metrics available (Duration, Count) and their aggregations.
This helps you understand how a span has performed during different parts of the test run. Also, all these charts have exemplars, small green dots that represent individual requests, so you can jump from the aggregations we provide to the source tracing data easily:
- Click on an exemplar.
- Click on “Query with Tempo”.
- Dive deeper into that specific trace thanks to the “Trace View” that “Explore” provides.
Was this page helpful?
Related resources from Grafana Labs
![Getting started with the Grafana LGTM Stack](/static/assets/featured/getting-started-with-grafana-lgtm-stack-amer_featured.png?w=200 200w, /static/assets/featured/getting-started-with-grafana-lgtm-stack-amer_featured.png?w=400 400w)
![Intro to Kubernetes monitoring in Grafana Cloud](/media/webinar/Screenshot-2024-02-12-at-4.09.30-PM.png?w=200 200w, /media/webinar/Screenshot-2024-02-12-at-4.09.30-PM.png?w=400 400w)
![Building advanced Grafana dashboards](/media/webinar/AMER_buildadv_notxt.png?w=200 200w, /media/webinar/AMER_buildadv_notxt.png?w=400 400w)