No results for

Powered byAlgolia
⚠️ This is the archived documentation for k6 v0.47. Go to the latest version.

Experimental module

While we intend to keep experimental modules as stable as possible, we may need to introduce breaking changes. This could happen at future k6 releases until the module becomes fully stable and graduates as a k6 core module. For more information, refer to the extension graduation process.

Experimental modules maintain a high level of stability and follow regular maintenance and security measures. Feel free to open an issue if you have any feedback or suggestions.

With this experimental module, you can instrument HTTP requests so that they emit traces as the test runs.

About trace contexts

A trace context is a set of standardized HTTP headers added to a request that lets a tracing system correlate the request with other requests as they navigate through a system. The trace context specifications, such as the supported W3C Trace Context and Jaeger Trace Context, define specific header names and an encoding format for the header values.

A trace context generally consists of, at least, a trace_id, a span_id, and a sampled flag. The trace_id is a unique identifier for the trace, the span_id is a unique identifier for the request, and the sampled flag is a boolean that indicates whether the request should be traced. For instance, the W3C Trace Context defines the Traceparent header, whose value contains a trace_id, a span_id and a sampled flag, encoded as a dash (-) separated list of hexadecimal values. When a trace context header is attached to an HTTP request, we refer to it as being propagated to the downstream service.

API

Class/FunctionDescription
instrumentHTTPinstruments the k6 http module with tracing capabilities.
Clientconfigurable Client that exposes instrumented HTTP operations and allows selectively instrumenting requests with tracing.

Example

This example demonstrates how to use the tracing API to instrument every HTTP request made in a script with tracing information.

example-tracing-module.js
import { check } from "k6";
import tracing from "k6/experimental/tracing";
import http from "k6/http";
// instrumentHTTP will ensure that all requests made by the http module
// from this point forward will have a trace context attached.
//
// The first argument is a configuration object that
// can be used to configure the tracer.
tracing.instrumentHTTP({
// possible values: "w3c", "jaeger"
propagator: "w3c",
});
export default () => {
// the instrumentHTTP call in the init context replaced
// the http module with a version that will automatically
// attach a trace context to every request.
//
// Because the instrumentHTTP call was configured with the
// w3c trace propagator, this request will as a result have
// a `traceparent` header attached.
const res = http.get("http://httpbin.org/get", {
headers: {
"X-Example-Header": "instrumented/get",
},
});
};