Skip to content

Commit

Permalink
Expose the instrumentHTTP function as part of the module's public API
Browse files Browse the repository at this point in the history
  • Loading branch information
oleiade committed Jan 19, 2023
1 parent 7f254ae commit 06bb82e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion js/modules/k6/experimental/tracing/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance {
func (mi *ModuleInstance) Exports() modules.Exports {
return modules.Exports{
Named: map[string]interface{}{
"Client": mi.NewClient,
"Client": mi.NewClient,
"instrumentHTTP": mi.InstrumentHTTP,
},
}
}
24 changes: 24 additions & 0 deletions samples/experimental/tracing/tracing-instrumentHTTP.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import http from "k6/http";
import { check } from "k6";
import tracing from "k6/experimental/tracing";

// 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: "w3c",
});

export default () => {
let res = http.get("http://httpbin.org/get", {
headers: {
"X-Example-Header": "instrumented/get",
},
});
check(res, {
"status is 200": (r) => r.status === 200,
});
};

0 comments on commit 06bb82e

Please sign in to comment.