From 9df375a68fe1210162e296a48c0710524cd5e216 Mon Sep 17 00:00:00 2001 From: oleiade Date: Fri, 13 Jan 2023 13:55:05 +0100 Subject: [PATCH] Register a k6/experimental/tracing Although we do not expose any of user-facing logic at this point, we register the "k6/experimental/tracing" module in k6 to prepare for further implementation of public APIs --- js/jsmodules.go | 2 + js/modules/k6/experimental/tracing/module.go | 42 ++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 js/modules/k6/experimental/tracing/module.go diff --git a/js/jsmodules.go b/js/jsmodules.go index f58a48edbf04..4b95099c2e8f 100644 --- a/js/jsmodules.go +++ b/js/jsmodules.go @@ -8,6 +8,7 @@ import ( "go.k6.io/k6/js/modules/k6/data" "go.k6.io/k6/js/modules/k6/encoding" "go.k6.io/k6/js/modules/k6/execution" + "go.k6.io/k6/js/modules/k6/experimental/tracing" "go.k6.io/k6/js/modules/k6/grpc" "go.k6.io/k6/js/modules/k6/html" "go.k6.io/k6/js/modules/k6/http" @@ -30,6 +31,7 @@ func getInternalJSModules() map[string]interface{} { "k6/experimental/redis": redis.New(), "k6/experimental/websockets": &expws.RootModule{}, "k6/experimental/timers": timers.New(), + "k6/experimental/tracing": tracing.New(), "k6/net/grpc": grpc.New(), "k6/html": html.New(), "k6/http": http.New(), diff --git a/js/modules/k6/experimental/tracing/module.go b/js/modules/k6/experimental/tracing/module.go new file mode 100644 index 000000000000..6d802a661b33 --- /dev/null +++ b/js/modules/k6/experimental/tracing/module.go @@ -0,0 +1,42 @@ +// Package tracing implements a k6 JS module for instrumenting k6 scripts with tracing context information. +package tracing + +import ( + "go.k6.io/k6/js/modules" +) + +type ( + // RootModule is the global module instance that will create Client + // instances for each VU. + RootModule struct{} + + // ModuleInstance represents an instance of the JS module. + ModuleInstance struct { + vu modules.VU + } +) + +// Ensure the interfaces are implemented correctly +var ( + _ modules.Instance = &ModuleInstance{} + _ modules.Module = &RootModule{} +) + +// New returns a pointer to a new RootModule instance +func New() *RootModule { + return &RootModule{} +} + +// NewModuleInstance implements the modules.Module interface and returns +// a new instance for each VU. +func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance { + return &ModuleInstance{ + vu: vu, + } +} + +// Exports implements the modules.Instance interface and returns +// the exports of the JS module. +func (mi *ModuleInstance) Exports() modules.Exports { + return modules.Exports{} +}