<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>HTTP instrumentation for Pyroscope on Grafana Labs</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/</link><description>Recent content in HTTP instrumentation for Pyroscope on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/index.xml" rel="self" type="application/rss+xml"/><item><title>instrumentHTTP</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/instrumenthttp/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/instrumenthttp/</guid><content><![CDATA[&lt;h1 id=&#34;instrumenthttp&#34;&gt;instrumentHTTP&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;instrumentHTTP&lt;/code&gt; 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 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/#about-baggage-header&#34;&gt;baggage header&lt;/a&gt;(by default) to every request.&lt;/p&gt;
&lt;p&gt;Instrumented functions include 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/del/&#34;&gt;del&lt;/a&gt;,
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/get/&#34;&gt;get&lt;/a&gt;,
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/head/&#34;&gt;head&lt;/a&gt;,
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/options/&#34;&gt;options&lt;/a&gt;,
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/patch/&#34;&gt;patch&lt;/a&gt;,
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/post/&#34;&gt;post&lt;/a&gt;,
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/head/&#34;&gt;put&lt;/a&gt;, and 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/request/&#34;&gt;request&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This means that, to instrument the HTTP requests, you don&amp;rsquo;t need to rewrite any code.
Instead, call the module once in the init context.
For details about propagation, refer to 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/#about-baggage-header&#34;&gt;About baggage header&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Name&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Type&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;code&gt;generateHeaders&lt;/code&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;code&gt;function(method, body, params) headersMap&lt;/code&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;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 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/#about-baggage-header&#34;&gt;about baggage header&lt;/a&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;This example demonstrates how to use the this library to instrument every HTTP request made in a script with baggage header.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { check } from &amp;#39;k6&amp;#39;;
import pyroscope from &amp;#39;https://jslib.k6.io/http-instrumentation-pyroscope/1.0.2/index.js&amp;#39;;
import http from &amp;#39;k6/http&amp;#39;;

// 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 () =&amp;gt; {
  // 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(&amp;#39;http://httpbin.org/get&amp;#39;, {
    headers: {
      &amp;#39;X-Example-Header&amp;#39;: &amp;#39;instrumented/get&amp;#39;,
    },
  });
};&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="instrumenthttp">instrumentHTTP&lt;/h1>
&lt;p>The &lt;code>instrumentHTTP&lt;/code> 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
&lt;a href="/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/#about-baggage-header">baggage header&lt;/a>(by default) to every request.&lt;/p></description></item><item><title>Client</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/client/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/client/</guid><content><![CDATA[&lt;h1 id=&#34;client&#34;&gt;Client&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;Client&lt;/code&gt; is an HTTP client constructor that attaches baggage headers to its requests.
Use the &lt;code&gt;Client&lt;/code&gt; class to include a context in HTTP requests so that &lt;a href=&#34;/oss/pyroscope/&#34;&gt;Grafana pyroscope&lt;/a&gt; can incorporate their results.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;Client&lt;/code&gt; class acts as a drop-in replacement for the standard &lt;code&gt;http&lt;/code&gt; module and attaches a &lt;a href=&#34;https://www.w3.org/TR/baggage/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;baggage header&lt;/a&gt; to the request. For details about propagation, refer to 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/#about-baggage-header&#34;&gt;About baggage header&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;Client&lt;/code&gt; constructor accepts a function that takes the method, the body, and the params of each request and returns a map of headers to be added to the request. By default, it appends the baggage header with the info necessary for Grafana Cloud Profiling to integrate with Grafana Cloud k6.&lt;/p&gt;
&lt;p&gt;For details about propagation, refer to 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/#about-baggage-header&#34;&gt;About baggage header&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;This example demonstrates how to instantiate a client and use it to instrument HTTP calls. The example also illustrates how you can use the client alongside the standard &lt;code&gt;http&lt;/code&gt; module to perform non-instrumented HTTP calls.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { check } from &amp;#39;k6&amp;#39;;
import pyroscope from &amp;#39;https://jslib.k6.io/http-instrumentation-pyroscope/1.0.2/index.js&amp;#39;;
import http from &amp;#39;k6/http&amp;#39;;

// Explicitly instantiating a Pyroscope client allows to distinguish
// instrumented from non-instrumented HTTP calls, by keeping APIs separate.
const instrumentedHTTP = new pyroscope.Client();

const testData = { name: &amp;#39;Bert&amp;#39; };

export default () =&amp;gt; {
  // Using the pyroscope client instance, HTTP calls will have
  // baggage header added.
  let res = instrumentedHTTP.request(&amp;#39;GET&amp;#39;, &amp;#39;http://httpbin.org/get&amp;#39;, null, {
    headers: {
      &amp;#39;X-Example-Header&amp;#39;: &amp;#39;instrumented/request&amp;#39;,
    },
  });

  // The client offers more flexibility over
  // the `instrumentHTTP` function, as it leaves the
  // imported standard `http` module untouched. Thus,
  // one can still perform non-instrumented HTTP calls
  // using it.
  res = http.post(&amp;#39;http://httpbin.org/post&amp;#39;, JSON.stringify(testData), {
    headers: { &amp;#39;X-Example-Header&amp;#39;: &amp;#39;noninstrumented/post&amp;#39; },
  });

  res = instrumentedHTTP.del(&amp;#39;http://httpbin.org/delete&amp;#39;, null, {
    headers: { &amp;#39;X-Example-Header&amp;#39;: &amp;#39;instrumented/delete&amp;#39; },
  });
};&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;http-module-functions-equivalents&#34;&gt;HTTP module functions equivalents&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;Client&lt;/code&gt; class exposes the same API as the standard &lt;code&gt;http&lt;/code&gt; module except for the &lt;code&gt;batch&lt;/code&gt; method, which is absent from &lt;code&gt;Client&lt;/code&gt;. The following table lists the &lt;code&gt;Client&lt;/code&gt; methods which have an equivalent in the standard &lt;code&gt;http&lt;/code&gt; module:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Method&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;HTTP equivalent&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;code&gt;Client.del(url, [body], [params])&lt;/code&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/del/&#34;&gt;http.del&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Performs an instrumented HTTP DELETE request. The method has the same prototype as the &lt;code&gt;http.del&lt;/code&gt; function and should transparently act as a drop-in replacement for it.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;code&gt;Client.get(url, [params])&lt;/code&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/get/&#34;&gt;http.get&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Performs an instrumented HTTP GET request. The method has the same prototype as the &lt;code&gt;http.get&lt;/code&gt; function and should transparently act as a drop-in replacement for it.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;code&gt;Client.head(url, [params])&lt;/code&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/head/&#34;&gt;http.head&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Performs an instrumented HTTP HEAD request. The method has the same prototype as the &lt;code&gt;http.head&lt;/code&gt; function and should transparently act as a drop-in replacement for it.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;code&gt;Client.options(url, [body], [params])&lt;/code&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/options/&#34;&gt;http.options&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Performs an instrumented HTTP OPTIONS request. The method has the same prototype as the &lt;code&gt;http.options&lt;/code&gt; function and should transparently act as a drop-in replacement for it.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;code&gt;Client.patch(url, [body], [params])&lt;/code&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/patch/&#34;&gt;http.patch&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Performs an instrumented HTTP PATCH request. The method has the same prototype as the &lt;code&gt;http.patch&lt;/code&gt; function and should transparently act as a drop-in replacement for it.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;code&gt;Client.post(url, [body], [params])&lt;/code&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/post/&#34;&gt;http.post&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Performs an instrumented HTTP POST request. The method has the same prototype as the &lt;code&gt;http.post&lt;/code&gt; function and should transparently act as a drop-in replacement for it.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;code&gt;Client.put(url, [body], [params])&lt;/code&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/head/&#34;&gt;http.put&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Performs an instrumented HTTP HEAD request. The method has the same prototype as the &lt;code&gt;http.put&lt;/code&gt; function and should transparently act as a drop-in replacement for it.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;code&gt;Client.request(method, url, [body], [params])&lt;/code&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/request/&#34;&gt;http.request&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Performs an instrumented HTTP request. The method has the same prototype as the &lt;code&gt;http.request&lt;/code&gt; function and should transparently act as a drop-in replacement for it.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;&lt;code&gt;Client.asyncRequest(method, url, [body], [params])&lt;/code&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/asyncrequest/&#34;&gt;http.asyncRequest&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Performs an instrumented HTTP asynchronous request. The method has the same prototype as the &lt;code&gt;http.asyncRequest&lt;/code&gt; function and should transparently act as a drop-in replacement for it.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;]]></content><description>&lt;h1 id="client">Client&lt;/h1>
&lt;p>&lt;code>Client&lt;/code> is an HTTP client constructor that attaches baggage headers to its requests.
Use the &lt;code>Client&lt;/code> class to include a context in HTTP requests so that &lt;a href="/oss/pyroscope/">Grafana pyroscope&lt;/a> can incorporate their results.&lt;/p></description></item></channel></rss>