Menu
Choose a product
Viewing: v1.7.x (latest)
Find another version
Scroll for more
Open source
instrumentHTTP
The instrumentHTTP function instruments the k6 HTTP module with additional headers. It transparently replaces each of the k6 http module functions with versions that automatically attach a
baggage header(by default) to every request.
Instrumented functions include del, get, head, options, patch, post, put, and request.
This means that, to instrument the HTTP requests, you don’t need to rewrite any code. Instead, call the module once in the init context. For details about propagation, refer to About baggage header.
Parameters
| Name | Type | Description |
|---|---|---|
generateHeaders | function(method, body, params) headersMap | A function taking the request method, body and params and returning a map of headers that will be attached. By default adding baggage header as explained in the about baggage header |
Example
This example demonstrates how to use the this library to instrument every HTTP request made in a script with baggage header.
JavaScript
JavaScript
import { check } from 'k6';
import pyroscope from 'https://jslib.k6.io/http-instrumentation-pyroscope/1.0.2/index.js';
import http from 'k6/http';
// instrumentHTTP will ensure that all requests made by the `http` module
// from this point forward will have a baggage context attached.
pyroscope.instrumentHTTP();
export default () => {
// the instrumentHTTP call in the init context replaced
// the `http` module with a version that will automatically
// attach a baggage header to every request.
const res = http.get('http://httpbin.org/get', {
headers: {
'X-Example-Header': 'instrumented/get',
},
});
};Was this page helpful?
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video

Performance testing and observability in Grafana Cloud
Optimize user experiences with Grafana Cloud. Learn real-time insights, performance testing with k6, and continuous validation with Synthetic Monitoring.
Events

User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.