This is documentation for the next version of K6. For the latest stable release, go to the latest version.
instrumentHTTP
The instrumentHTTP
function instruments the k6 http module with tracing capabilities. It transparently replaces each of the k6 http module functions with versions that automatically attach a trace context to every request. Instrumented functions include del,get,head,options,patch,post,put, and request.
The instrumentHTTP
automatically adds tracing information to HTTP requests performed using the k6/http
module functions (mentioned above).
This means that, to instrument the HTTP requests, you don’t need to rewrite any code.
Instead, call it once in the init context.
From that point forward, all requests made by the HTTP module from that point forward will have a trace context header added to them, and the metadata for the data-point output will have the used trace_id
. For details about propagation, refer to About trace contexts.
Parameters
Name | Type | Description |
---|---|---|
options | Options | Configures the tracing behavior with the provided Options object. |
Example
This example demonstrates how to call the instrumentHTTP
function in the script’s init context. From that point forward, all the requests made by the HTTP module have a trace context header attached.
import { check } from 'k6';
import tempo from 'https://jslib.k6.io/http-instrumentation-tempo/1.0.0/index.js';
import http from 'k6/http';
// instrumentHTTP will ensure that all requests made by the http module
// will be traced. The first argument is a configuration object that
// can be used to configure the tracer.
//
// Currently supported HTTP methods are: get, post, put, patch, head,
// del, options, and request.
tempo.instrumentHTTP({
// propagator defines the trace context propagation format.
// Currently supported: w3c and jaeger.
// Default: w3c
propagator: 'w3c',
});
export default () => {
const res = http.get('http://httpbin.org/get', {
headers: {
'X-Example-Header': 'instrumented/get',
},
});
};