Skip to content

Commit

Permalink
Use OTEL Exporter instead of Jaeger Exporter (#18)
Browse files Browse the repository at this point in the history
I have used the otel exporter instead of the jaeger exporter.
Also ran `go get -d -t ./...` and `go mod tidy` and fixed errors caused
by it.

Use the `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`
```bash
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:14268/api/traces
```

---------

Signed-off-by: FlamingSaint <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Co-authored-by: Yuri Shkuro <[email protected]>
  • Loading branch information
FlamingSaint and yurishkuro authored Jul 2, 2024
1 parent c0fd0b7 commit 0f4a6f2
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 104 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ between simulations in each worker.

The tool comes with a built-in configuration for Jaeger's HotROD application that can be printed with:

```sh
```shell
docker run yurishkuro/microsim -o | jq
```

Expand All @@ -35,10 +35,27 @@ docker run yurishkuro/microsim -o | jq

To see all command line options:

```sh
```shell
docker run yurishkuro/microsim -h
```

`microsim` uses OpenTelemetry SDK to export traces. By default it will try to send them to `https://localhost:4318/v1/traces` (with TLS enabled). This can be changed by setting environment variables supported by the SDK:
* `OTEL_EXPORTER_OTLP_ENDPOINT` to point to a different host/port.
* `OTEL_EXPORTER_OTLP_INSECURE=true` if you just want to switch default URL to `http` instead of `https`.

Note that when we run `microsim` as a container, the `localhost` refers to the container's inner network namespace, so it will not be able to reach the collector even if it's running on the same host. You might see an error like this:

```
2024/07/02 18:06:07 traces export: Post "https://localhost:4318/v1/traces": dial tcp [::1]:4318: connect: connection refused
```

To work around that, refer to the IP address of the host instead:

```shell
docker run --env OTEL_EXPORTER_OTLP_ENDPOINT=https://{YOUR_IP_ADDRESS}:4318/v1/traces \
yurishkuro/microsim -w=1 -r=1
```

## License

MIT license.
12 changes: 2 additions & 10 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// Get makes a traced HTTP GET call.
func Get(ctx context.Context, url string, tracer trace.Tracer) error {
func Get(ctx context.Context, url string, tp trace.TracerProvider) error {
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
if err != nil {
return err
Expand All @@ -19,7 +19,7 @@ func Get(ctx context.Context, url string, tracer trace.Tracer) error {
client := http.Client{
Transport: otelhttp.NewTransport(
http.DefaultTransport,
otelhttp.WithTracerProvider(&tracerProvider{tracer}),
otelhttp.WithTracerProvider(tp),
),
}
res, err := client.Do(req)
Expand All @@ -34,11 +34,3 @@ func Get(ctx context.Context, url string, tracer trace.Tracer) error {

return nil
}

type tracerProvider struct {
tracer trace.Tracer
}

func (p *tracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Tracer {
return p.tracer
}
34 changes: 22 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
module github.com/yurishkuro/microsim

go 1.18
go 1.21

toolchain go1.22.3

require (
github.com/opentracing-contrib/go-stdlib v1.0.0
github.com/opentracing/opentracing-go v1.2.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.3
go.opentelemetry.io/otel v1.11.0
go.opentelemetry.io/otel/exporters/jaeger v1.11.0
go.opentelemetry.io/otel/sdk v1.11.0
go.opentelemetry.io/otel/trace v1.11.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0
go.opentelemetry.io/otel v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0
go.opentelemetry.io/otel/sdk v1.27.0
go.opentelemetry.io/otel/trace v1.27.0
)

require (
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
go.opentelemetry.io/otel/metric v0.32.3 // indirect
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
)
73 changes: 44 additions & 29 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/opentracing-contrib/go-stdlib v1.0.0 h1:TBS7YuVotp8myLon4Pv7BtCBzOTo1DeZCld0Z63mW2w=
github.com/opentracing-contrib/go-stdlib v1.0.0/go.mod h1:qtI1ogk+2JhVPIXVc6q+NHziSmy2W5GbdQZFUHADCBU=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.3 h1:SGz6Fnp7blR+sskRZkyuFDb3qI1d8I0ygLh13F+sw6I=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.3/go.mod h1:+OXcluxum2GicWQ9lMXLQkLkOWoaw20OrVbYq6kkPks=
go.opentelemetry.io/otel v1.11.0 h1:kfToEGMDq6TrVrJ9Vht84Y8y9enykSZzDDZglV0kIEk=
go.opentelemetry.io/otel v1.11.0/go.mod h1:H2KtuEphyMvlhZ+F7tg9GRhAOe60moNx61Ex+WmiKkk=
go.opentelemetry.io/otel/exporters/jaeger v1.11.0 h1:Sv2valcFfMlfu6g8USSS+ZUN5vwbuGj1aY/CFtMG33w=
go.opentelemetry.io/otel/exporters/jaeger v1.11.0/go.mod h1:nRgyJbgJ0hmaUdHwyDpTTfBYz61cTTeeGhVzfQc+FsI=
go.opentelemetry.io/otel/metric v0.32.3 h1:dMpnJYk2KULXr0j8ph6N7+IcuiIQXlPXD4kix9t7L9c=
go.opentelemetry.io/otel/metric v0.32.3/go.mod h1:pgiGmKohxHyTPHGOff+vrtIH39/R9fiO/WoenUQ3kcc=
go.opentelemetry.io/otel/sdk v1.11.0 h1:ZnKIL9V9Ztaq+ME43IUi/eo22mNsb6a7tGfzaOWB5fo=
go.opentelemetry.io/otel/sdk v1.11.0/go.mod h1:REusa8RsyKaq0OlyangWXaw97t2VogoO4SSEeKkSTAk=
go.opentelemetry.io/otel/trace v1.11.0 h1:20U/Vj42SX+mASlXLmSGBg6jpI1jQtv682lZtTAOVFI=
go.opentelemetry.io/otel/trace v1.11.0/go.mod h1:nyYjis9jy0gytE9LXGU+/m1sHTKbRY0fX0hulNNDP1U=
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc=
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 h1:9l89oX4ba9kHbBol3Xin3leYJ+252h0zszDtBwyKe2A=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0/go.mod h1:XLZfZboOJWHNKUv7eH0inh0E9VV6eWDFB/9yJyTLPp0=
go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg=
go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 h1:R9DE4kQ4k+YtfLI2ULwX82VtNQ2J8yZmA7ZIF/D+7Mc=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0/go.mod h1:OQFyQVrDlbe+R7xrEyDr/2Wr67Ol0hRUgsfA+V5A95s=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 h1:QY7/0NeRPKlzusf40ZE4t1VlMKbqSNT7cJRYzWuja0s=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0/go.mod h1:HVkSiDhTM9BoUJU8qE6j2eSWLLXvi1USXjyd2BXT8PY=
go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik=
go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak=
go.opentelemetry.io/otel/sdk v1.27.0 h1:mlk+/Y1gLPLn84U4tI8d3GNJmGT/eXe3ZuOXN9kTWmI=
go.opentelemetry.io/otel/sdk v1.27.0/go.mod h1:Ha9vbLwJE6W86YstIywK2xFfPjbWlCuwPtMkKdz/Y4A=
go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw=
go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4=
go.opentelemetry.io/proto/otlp v1.2.0 h1:pVeZGk7nXDC9O2hncA6nHldxEjm6LByfA2aN8IOkz94=
go.opentelemetry.io/proto/otlp v1.2.0/go.mod h1:gGpR8txAl5M03pDhMC79G6SdqNV26naRm/KDsgaHD8A=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 h1:P8OJ/WCl/Xo4E4zoe4/bifHpSmmKwARqyqE4nW6J2GQ=
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5/go.mod h1:RGnPtTG7r4i8sPlNyDeikXF99hMM+hN6QMm4ooG9g2g=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 h1:AgADTJarZTBqgjiUzRgfaBchgYB3/WFTC80GPwsMcRI=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/yurishkuro/microsim/config"
"github.com/yurishkuro/microsim/model"
"github.com/yurishkuro/microsim/tracing"
)

var (
Expand All @@ -24,7 +23,6 @@ var (
)

func main() {
flag.StringVar(&tracing.JaegerCollectorURL, "j", tracing.JaegerCollectorURL, "address of Jaeger collector to submit spans")
flag.Parse()

if *simulation == "" {
Expand Down
10 changes: 5 additions & 5 deletions model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *Config) Run() {
}

func (c *Config) runWorker(instanceName string, stop chan struct{}, done *sync.WaitGroup) {
tracer, shutdown, err := tracing.InitTracer("test-executor", instanceName)
tracerProvider, shutdown, err := tracing.InitTracer("test-executor", instanceName)
if err != nil {
log.Fatalf("failed to create a tracer: %v", err)
}
Expand All @@ -98,7 +98,7 @@ func (c *Config) runWorker(instanceName string, stop chan struct{}, done *sync.W
case <-stop:
return
default:
c.runTest(tracer)
c.runTest(tracerProvider)
}
if repeats > 0 {
repeats--
Expand All @@ -109,19 +109,19 @@ func (c *Config) runWorker(instanceName string, stop chan struct{}, done *sync.W
}
}

func (c *Config) runTest(tracer trace.Tracer) {
func (c *Config) runTest(tracerProvider trace.TracerProvider) {
rootSvc := c.Services[0]
inst := rootSvc.instances[0]
endpoint := inst.Endpoints[0]

tracer := tracerProvider.Tracer("worker")
ctx, rootSpan := tracer.Start(
context.Background(),
"runTest",
trace.WithAttributes(attribute.String("test_name", c.TestName)),
)
defer rootSpan.End()

err := endpoint.Call(ctx, tracer)
err := endpoint.Call(ctx, tracerProvider)
if err != nil {
log.Printf("transaction failed: %v", err)
}
Expand Down
8 changes: 4 additions & 4 deletions model/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func (d *Dependencies) Validate(r *Registry) error {
}

// Call makes calls to all dependencies.
func (d *Dependencies) Call(ctx context.Context, tracer trace.Tracer) error {
func (d *Dependencies) Call(ctx context.Context, tracerProvider trace.TracerProvider) error {
if len(d.Seq) > 0 {
return d.Seq.Call(ctx, tracer)
return d.Seq.Call(ctx, tracerProvider)
}
if d.Par != nil {
return d.Par.Call(ctx, tracer)
return d.Par.Call(ctx, tracerProvider)
}
return d.Service.Call(ctx, tracer)
return d.Service.Call(ctx, tracerProvider)
}
6 changes: 3 additions & 3 deletions model/endpoint_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ func (e *EndpointInstance) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// executes the endpoint, calling dependencies if necessary.
func (e *EndpointInstance) execute(ctx context.Context) error {
if e.Depends != nil {
if err := e.Depends.Call(ctx, e.service.tracing.tracer); err != nil {
if err := e.Depends.Call(ctx, e.service.tracing.tracerProvider); err != nil {
return err
}
}
return e.Perf.Apply(ctx)
}

// Call makes a call to this endpoint.
func (e *EndpointInstance) Call(ctx context.Context, tracer trace.Tracer) error {
func (e *EndpointInstance) Call(ctx context.Context, tracerProvider trace.TracerProvider) error {
url := e.service.server.URL + e.Name
return client.Get(ctx, url, tracer)
return client.Get(ctx, url, tracerProvider)
}
12 changes: 6 additions & 6 deletions model/parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ func (p *Parallel) Validate(r *Registry) error {
}

// Call makes calls to all dependencies.
func (p *Parallel) Call(ctx context.Context, tracer trace.Tracer) error {
func (p *Parallel) Call(ctx context.Context, tracerProvider trace.TracerProvider) error {
if p.MaxPar == 0 {
return p.fullParCall(ctx, tracer)
return p.fullParCall(ctx, tracerProvider)
}
return p.maxParCall(ctx, tracer)
return p.maxParCall(ctx, tracerProvider)
}

func (p *Parallel) fullParCall(ctx context.Context, tracer trace.Tracer) error {
func (p *Parallel) fullParCall(ctx context.Context, tracerProvider trace.TracerProvider) error {
// done := &sync.WaitGroup{}
// done.Add(len(p.Items))

Expand All @@ -54,7 +54,7 @@ func (p *Parallel) fullParCall(ctx context.Context, tracer trace.Tracer) error {
return nil
}

func (p *Parallel) maxParCall(ctx context.Context, tracer trace.Tracer) error {
func (p *Parallel) maxParCall(ctx context.Context, tracerProvider trace.TracerProvider) error {
done := &sync.WaitGroup{}
done.Add(len(p.Items))

Expand All @@ -70,7 +70,7 @@ func (p *Parallel) maxParCall(ctx context.Context, tracer trace.Tracer) error {
for i := 0; i < p.MaxPar; i++ {
go func() {
for n := range ch {
err := p.Items[n].Call(ctx, tracer)
err := p.Items[n].Call(ctx, tracerProvider)
if err != nil {
errMutex.Lock()
topErrors = append(topErrors, err)
Expand Down
4 changes: 2 additions & 2 deletions model/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func (s Sequence) Validate(r *Registry) error {
}

// Call makes calls to all dependencies.
func (s Sequence) Call(ctx context.Context, tracer trace.Tracer) error {
func (s Sequence) Call(ctx context.Context, tracerProvider trace.TracerProvider) error {
for _, dep := range s {
if err := dep.Call(ctx, tracer); err != nil {
if err := dep.Call(ctx, tracerProvider); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions model/service_dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *ServiceDep) Validate(r *Registry) error {
}

// Call makes call to dependency service.
func (s *ServiceDep) Call(ctx context.Context, tracer trace.Tracer) error {
func (s *ServiceDep) Call(ctx context.Context, tracerProvider trace.TracerProvider) error {
url := s.service.NextServerURL() + s.endpoint.Name
return client.Get(ctx, url, tracer)
return client.Get(ctx, url, tracerProvider)
}
22 changes: 5 additions & 17 deletions model/service_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ type ServiceInstance struct {
service *Service
server *httptest.Server
tracing struct {
tracer trace.Tracer
shutdown func()
tracerProvider trace.TracerProvider
shutdown func()
}
}

func startServiceInstance(service *Service, instanceName string) (*ServiceInstance, error) {
tracer, shutdown, err := tracing.InitTracer(service.Name, instanceName)
tracerProvider, shutdown, err := tracing.InitTracer(service.Name, instanceName)
if err != nil {
return nil, err
}
inst := &ServiceInstance{
service: service,
}
inst.tracing.tracer = tracer
inst.tracing.tracerProvider = tracerProvider
inst.tracing.shutdown = shutdown
inst.server = httptest.NewServer(inst.mux())
log.Printf("started service instance %s at %s", instanceName, inst.server.URL)
Expand All @@ -45,7 +45,7 @@ func (inst *ServiceInstance) mux() http.Handler {
wrappedHandler := otelhttp.NewHandler(
endpointInstance,
endpointInstance.Name,
otelhttp.WithTracerProvider(newSingletonTracerProvider(inst.tracing.tracer)),
otelhttp.WithTracerProvider(inst.tracing.tracerProvider),
otelhttp.WithSpanNameFormatter(func(_ string, _ *http.Request) string {
return endpointInstance.Name
}),
Expand All @@ -61,15 +61,3 @@ func (inst *ServiceInstance) Stop() {
inst.tracing.shutdown()
log.Printf("stopped service instance %s", inst.service.Name)
}

type singletonTracerProvider struct {
tracer trace.Tracer
}

func (p *singletonTracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Tracer {
return p.tracer
}

func newSingletonTracerProvider(tracer trace.Tracer) trace.TracerProvider {
return &singletonTracerProvider{tracer}
}
Loading

0 comments on commit 0f4a6f2

Please sign in to comment.