Documentation Index
Fetch the curated documentation index at: https://grafana_com_website/llms.txt
Fetch the complete documentation index at: https://grafana_com_website/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: /docs/k6/latest/javascript-api/jslib/http-instrumentation-pyroscope.md (append .md) or send Accept: text/markdown to /docs/k6/latest/javascript-api/jslib/http-instrumentation-pyroscope/. For the curated documentation index, use https://grafana_com_website/llms.txt. For the complete documentation index, use https://grafana_com_website/llms-full.txt.
HTTP instrumentation for Pyroscope
Note
The source code for this library can be found in the grafana/jslib.k6.io GitHub repository.
The http-instrumentation-pyroscope module allows you to instrument HTTP requests in a way that lets you tag Grafana Cloud Profiles with relevant information generated from k6 tests.
About baggage header
The baggage header is a standardized HTTP header used to propagate distributed context. The W3C specification goes into more detail on the specifics, but like many other headers, the baggage header is a list of key-value pairs.
This module, by default, adds three key-value pairs:
- Scenario name
- Name of the request (URL if not set)
- Value of
__ENV.K6_CLOUDRUN_TEST_RUN_ID, which is set automatically in Grafana Cloud k6.
API
| Class/Function | Description |
|---|---|
| instrumentHTTP | Instruments the k6 http module with baggage header. |
| Client | Configurable Client that exposes instrumented HTTP operations. |
Example
This example demonstrates how to use the this library to instrument every HTTP request made in a script with the baggage header.
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

