Skip to content

Latest commit

 

History

History
53 lines (42 loc) · 3 KB

File metadata and controls

53 lines (42 loc) · 3 KB
title excerpt canonicalUrl
instrumentHTTP
instrumentHTTP instruments the k6 http module with tracing capabilities.

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 calling the instrumentHTTP function in the init context of a script once ensures that all requests made by the HTTP module from that point forward will have a trace context header attached.

<CodeGroup labels={["example-tracing-instrumentHTTP.js"]} lineNumbers={[]} showCopyButton={[true]}>

import { check } from "k6";
import tracing from "k6/experimental/tracing";
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.
tracing.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",
    },
  });
};