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.
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.