---
title: "instrumentHTTP | Grafana k6 documentation"
description: "instrumentHTTP instruments the k6 http module with tracing capabilities."
---

# 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](/docs/k6/latest/javascript-api/k6-http/del/), [get](/docs/k6/latest/javascript-api/k6-http/get/), [head](/docs/k6/latest/javascript-api/k6-http/head/), [options](/docs/k6/latest/javascript-api/k6-http/options/), [patch](/docs/k6/latest/javascript-api/k6-http/patch/), [post](/docs/k6/latest/javascript-api/k6-http/post/), [put](/docs/k6/latest/javascript-api/k6-http/head/), and [request](/docs/k6/latest/javascript-api/k6-http/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 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](/docs/k6/latest/javascript-api/jslib/http-instrumentation-tempo/#about-trace-contexts).

## Parameters

Expand table

| Name      | Type                                                                                  | Description                                                                                                                                     |
|-----------|---------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `options` | [`Options`](/docs/k6/latest/javascript-api/jslib/http-instrumentation-tempo/options/) | Configures the tracing behavior with the provided [`Options`](/docs/k6/latest/javascript-api/jslib/http-instrumentation-tempo/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.

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
import { check } from 'k6';
import tempo from 'https://jslib.k6.io/http-instrumentation-tempo/1.0.1/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',
    },
  });
};
```
