Skip to content

Commit

Permalink
Add TracerProvider to VU State
Browse files Browse the repository at this point in the history
  • Loading branch information
ka3de committed Nov 10, 2023
1 parent a5948c7 commit 615f6cf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/test_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func loadTest(gs *state.GlobalState, cmd *cobra.Command, args []string) (*loaded
val, ok := gs.Env[key]
return val, ok
},
TracerProvider: gs.TracerProvider,
}

test := &loadedTest{
Expand Down
1 change: 1 addition & 0 deletions js/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func (r *Runner) newVU(
Tags: lib.NewVUStateTags(vu.Runner.RunTags),
Group: r.defaultGroup,
BuiltinMetrics: r.preInitState.BuiltinMetrics,
TracerProvider: r.preInitState.TracerProvider,
}
vu.moduleVUImpl.state = vu.state
_ = vu.Runtime.Set("console", vu.Console)
Expand Down
2 changes: 2 additions & 0 deletions lib/test_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/sirupsen/logrus"
"go.k6.io/k6/event"
"go.k6.io/k6/lib/trace"
"go.k6.io/k6/metrics"
)

Expand All @@ -18,6 +19,7 @@ type TestPreInitState struct {
KeyLogger io.Writer
LookupEnv func(key string) (val string, ok bool)
Logger logrus.FieldLogger
TracerProvider *trace.TracerProvider
}

// TestRunState contains the pre-init state as well as all of the state and
Expand Down
9 changes: 9 additions & 0 deletions lib/vu_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"

"github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/trace"
"golang.org/x/time/rate"

"go.k6.io/k6/metrics"
Expand All @@ -19,6 +20,11 @@ type DialContexter interface {
DialContext(ctx context.Context, network, addr string) (net.Conn, error)
}

// TracerProvider provides methods for OTEL tracers initialization.
type TracerProvider interface {
Tracer(name string, options ...trace.TracerOption) trace.Tracer
}

// State provides the volatile state for a VU.
//
// TODO: rename to VUState or, better yet, move to some other Go package outside
Expand Down Expand Up @@ -75,6 +81,9 @@ type State struct {
// unique globally across k6 instances (taking into account execution
// segments).
GetScenarioGlobalVUIter func() uint64

// Tracing instrumentation.
TracerProvider TracerProvider
}

// VUStateTags wraps the current VU's tags and ensures a thread-safe way to
Expand Down

0 comments on commit 615f6cf

Please sign in to comment.