Skip to content

Commit

Permalink
setup: switch to using otlp instead of jaeger
Browse files Browse the repository at this point in the history
Switch to using the oltp exporter instead of jaeger since jaeger
is deprecated.

This follows some from:
https://docs.google.com/document/d/1NJt-YMO4-hAwG6waN4mQvFx4BIAjcBx3Wig4e5J4cSs/edit?tab=t.0

This is a breaking change and clients will need to manually update
envs and function names.
  • Loading branch information
travisshivers committed Nov 12, 2024
1 parent 5fac441 commit c958ae9
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 58 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

This repo contains OpenTelemetry-related code.

### JaegerSetup
### OtelSetup

JaegerSetup provides boilerplate, slightly Arista-optimized production of Jaeger TracerProviders.
OtelSetup provides boilerplate, slightly Arista-optimized production of Otel TracerProviders.

Typical applications require some environment. Kubernetes example:

Expand All @@ -15,18 +15,22 @@ spec:
spec:
containers:
env:
- name: JAEGER_ENABLED
- name: OTEL_SDK_DISABLED
value: "false"
- name: OTEL_EXPORTER_OTLP_INSECURE
value: "true"
- name: OTEL_EXPORTER_JAEGER_AGENT_HOST
- name: HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: OTEL_SAMPLER_JAEGER_CONFIG_URL_TEMPLATE
value: http://${OTEL_EXPORTER_JAEGER_AGENT_HOST}:5778/sampling
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: "http://$(HOST_IP):4317"
- name: OTEL_REMOTE_SAMPLING_URL
value: "http://$(HOST_IP):5778/sampling"
```

Please note that the URL_TEMPLATE should *not* be formed `/sampling?service={}`,
and that the use of `{}` to designate the TracerProvider name is no longer supported.
The old envs `OTEL_EXPORTER_JAEGER_AGENT_HOST`, `OTEL_SAMPLER_JAEGER_CONFIG_URL_TEMPLATE`, and `JAEGER_ENABLED` are no longer used.
The grpc otel exporter can be configured through the standard envs described https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc#pkg-overview

### EnvironCarrier

Expand Down
10 changes: 3 additions & 7 deletions example/basic/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"errors"
"fmt"
"os"
"time"

otelb "barney.ci/go-otel"
Expand All @@ -20,9 +19,7 @@ import (
var tracer trace.Tracer

func setup(ctx context.Context) {
os.Setenv("JAEGER_ENABLED", "true")

tp, closer, err := otelb.JaegerSetup(
tp, closer, err := otelb.OtelSetup(
"barney.ci/go-otel/example/basic",
// logger first so that any errors can be reported.
otelb.WithLogger(logr.FromContextOrDiscard(ctx)),
Expand All @@ -31,7 +28,7 @@ func setup(ctx context.Context) {
otelb.WithShutdownTimeout(time.Minute),
otelb.WithGeneralPropagatorSetup(),
otelb.WithRemoteSampler(),
otelb.WithAgentExporter(),
otelb.WithOtlpExporter(),
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -60,8 +57,7 @@ func doTracing(ctx context.Context) {
}

func ExampleTracer() {
// - OTEL_EXPORTER_JAEGER_AGENT_HOST is used for the agent address host
// - OTEL_EXPORTER_JAEGER_AGENT_PORT is used for the agent address port
// - OTEL_EXPORTER_OTLP_ENDPOINT is used for the otlp exporter

ctx := context.TODO()
setup(ctx)
Expand Down
11 changes: 9 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,26 @@ require (
github.com/segmentio/kafka-go v0.4.47
go.opentelemetry.io/contrib/samplers/jaegerremote v0.26.0
go.opentelemetry.io/otel v1.32.0
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0
go.opentelemetry.io/otel/sdk v1.32.0
go.opentelemetry.io/otel/trace v1.32.0
)

require (
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/pierrec/lz4/v4 v4.1.15 // indirect
github.com/stretchr/objx v0.5.2 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0 // indirect
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
)
28 changes: 20 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
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.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -12,6 +14,8 @@ 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/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 h1:ad0vkEBuk23VJzZR9nkLVG0YAoN9coASF1GusYX6AlU=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0/go.mod h1:igFoXX2ELCW06bol23DWPB5BEWfZISOzSP5K2sbLea0=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
Expand All @@ -24,8 +28,6 @@ github.com/segmentio/kafka-go v0.4.47 h1:IqziR4pA3vrZq7YdRxaT3w1/5fvIH5qpCwstUan
github.com/segmentio/kafka-go v0.4.47/go.mod h1:HjF6XbOKh0Pjlkr5GVZxt6CsjjwnmhVOfURM5KMd8qg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
Expand All @@ -43,14 +45,20 @@ go.opentelemetry.io/contrib/samplers/jaegerremote v0.26.0 h1:/SKXyZLAnuj981HVc8G
go.opentelemetry.io/contrib/samplers/jaegerremote v0.26.0/go.mod h1:cOEzME0M2OKeHB45lJiOKfvUCdg/r75mf7YS5w0tbmE=
go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U=
go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg=
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4=
go.opentelemetry.io/otel/exporters/jaeger v1.17.0/go.mod h1:nPCqOnEH9rNLKqH/+rrUjiMzHJdV1BlpKcTwRTyKkKI=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0 h1:IJFEoHiytixx8cMiVAO+GmHR6Frwu+u5Ur8njpFO6Ac=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0/go.mod h1:3rHrKNtLIoS0oZwkY2vxi+oJcwFRWdtUyRII+so45p8=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0 h1:9kV11HXBHZAvuPUZxmMWrH8hZn/6UnHX4K0mu36vNsU=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0/go.mod h1:JyA0FHXe22E1NeNiHmVp7kFHglnexDQ7uRWDiiJ1hKQ=
go.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M=
go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8=
go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4=
go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU=
go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM=
go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8=
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand All @@ -69,8 +77,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -100,8 +108,8 @@ golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
Expand All @@ -114,6 +122,10 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 h1:M0KvPgPmDZHPlbRbaNU1APr28TvwvvdUPlSv7PUvy8g=
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:dguCy7UOdZhTvLzDyt15+rOrawrpM4q7DD9dQ1P11P4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 h1:XVhgTWWV3kGQlwJHR3upFWZeTsei6Oks1apkZSeonIE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
71 changes: 38 additions & 33 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"go.opentelemetry.io/contrib/samplers/jaegerremote"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
trace "go.opentelemetry.io/otel/sdk/trace"
Expand All @@ -42,10 +42,14 @@ func (f closerFunc) Close() error {
return f()
}

const EnvSamplerTemplateName = "OTEL_SAMPLER_JAEGER_CONFIG_URL_TEMPLATE"
const EnvGateName = "JAEGER_ENABLED"
const EnvSamplingUrl = "OTEL_REMOTE_SAMPLING_URL"
const EnvGateCue = "true"

// These envs are standard. See:
// https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/
// https://opentelemetry.io/docs/specs/otel/protocol/exporter/
const EnvGateName = "OTEL_SDK_DISABLED"

// nullExporter implements the trace.SpanExporter interface
type nullExporter struct{}

Expand All @@ -57,8 +61,8 @@ func (n nullExporter) Shutdown(ctx context.Context) error {
return nil
}

// WithEnvGate causes a call to JaegerSetup to be a no-op
// unless the environment variable defined by EnvGatename
// WithEnvGate causes a call to OtelSetup to be a no-op
// if the environment variable defined by EnvGatename
// is set to the value defined by EnvGateCue
func WithEnvGate() setupOptionFunc {
return setupOptionFunc(func(opts *setupConfig) {
Expand All @@ -67,14 +71,14 @@ func WithEnvGate() setupOptionFunc {
}

// WithShutdownTimeout limits the amount of time
// that the close function returned by JaegerSetup may wait
// that the close function returned by OtelSetup may wait
func WithShutdownTimeout(t time.Duration) setupOptionFunc {
return setupOptionFunc(func(opts *setupConfig) {
opts.shutdownTimeout = t
})
}

// WithGeneralPropagatorSetup causes JaegerSetup to configure
// WithGeneralPropagatorSetup causes OtelSetup to configure
// the default propagator with some basic propagators
func WithGeneralPropagatorSetup() setupOptionFunc {
p := propagation.NewCompositeTextMapPropagator(
Expand All @@ -97,47 +101,48 @@ func WithLogger(logger logr.Logger) setupOptionFunc {
})
}

// WithSampler causes JaegerSetup to configure Jaeger
// WithSampler causes OtelSetup to configure otel
// with the provided sampler only
func WithSampler(s trace.Sampler) setupOptionFunc {
return setupOptionFunc(func(opts *setupConfig) {
opts.sampler = s
})
}

// WithRemoteSampler causes JaegerSetup to configure Jaeger
// WithOtlpExporter causes OtelSetup to configure an
// exporter targeting the exporter otlp endpoint
func WithOtlpExporter() setupOptionFunc {
return setupOptionFunc(func(opts *setupConfig) {
exporter, err := otlptracegrpc.New(context.Background())
if err != nil {
panic(fmt.Sprintf("cannot create otlp exporter: %s", err))
}

opts.exporter = exporter
})
}

// WithRemoteSampler causes OtelSetup to be configured
// with a remote sampler URL constructed using the environment
// variable defined by EnvSamplerTemplateName, falling back
// variable defined by EnvSamplingUrl, falling back
// to any previously configured sampler
func WithRemoteSampler() setupOptionFunc {
return setupOptionFunc(func(opts *setupConfig) {
if samplerURL := os.Getenv(EnvSamplerTemplateName); samplerURL != "" {
if strings.Contains(samplerURL, "{}") {
if samplingURL := os.Getenv(EnvSamplingUrl); samplingURL != "" {
if strings.Contains(samplingURL, "{}") {
panic(fmt.Sprintf("%s no longer supports {} macro; "+
"please see the barney.ci/go-otel readme", EnvSamplerTemplateName))
"please see the barney.ci/go-otel readme", EnvSamplingUrl))
}
samplerURL = os.ExpandEnv(samplerURL)
samplingURL = os.ExpandEnv(samplingURL)
opts.sampler = jaegerremote.New(opts.name,
jaegerremote.WithSamplingServerURL(samplerURL),
jaegerremote.WithSamplingServerURL(samplingURL),
jaegerremote.WithInitialSampler(opts.sampler),
jaegerremote.WithLogger(opts.logger),
)
}
})
}

// WithAgentExpoter causes JaegerSetup to configure an
// exporter targeting the Jaeger agent endpoint
func WithAgentExporter() setupOptionFunc {
return setupOptionFunc(func(opts *setupConfig) {
exporter, err := jaeger.New(jaeger.WithAgentEndpoint())
if err != nil {
panic(fmt.Sprintf("cannot create jaeger exporter: %s", err))
}
opts.exporter = exporter
})
}

func getIPAddress() (string, error) {
addrs, err := net.InterfaceAddrs()
if err != nil {
Expand All @@ -154,7 +159,7 @@ func getIPAddress() (string, error) {
return "", fmt.Errorf("no IP address found")
}

// JaegerSetup returns a jaeger TracerProvider
// OtelSetup returns a otel TracerProvider
// and a closer function to shut down the provider.
//
// Options order can be important. For example, WithRemoteSampler
Expand All @@ -164,7 +169,7 @@ func getIPAddress() (string, error) {
//
// It's a good idea to pass WithLogger first, so errors
// raised by subsequent options will be sent to that callback.
func JaegerSetup(name string, with ...setupOptionFunc) (
func OtelSetup(name string, with ...setupOptionFunc) (
tp *trace.TracerProvider, closer closerFunc, err error,
) {
// Always return working no-ops instead of nils
Expand All @@ -180,20 +185,20 @@ func JaegerSetup(name string, with ...setupOptionFunc) (
// Apply options and return an error if one panics
opts := &setupConfig{
name: name,
sampler: trace.AlwaysSample(),
sampler: trace.ParentBased(trace.AlwaysSample()),
exporter: nullExporter{},
logger: stdr.New(log.Default()),
}
defer func() {
if r := recover(); r != nil {
opts.logger.Error(fmt.Errorf("%s", r), "panic occurred in JaegerSetup")
opts.logger.Error(fmt.Errorf("%s", r), "panic occurred in OtelSetup")
}
}()
for _, fn := range with {
fn(opts)
}

if opts.envGate && os.Getenv(EnvGateName) != EnvGateCue {
if opts.envGate && os.Getenv(EnvGateName) == EnvGateCue {
return
}

Expand Down Expand Up @@ -237,7 +242,7 @@ func JaegerSetup(name string, with ...setupOptionFunc) (
}
err := tp.Shutdown(ctx)
if err != nil {
opts.logger.Error(err, "jaeger shutdown error")
opts.logger.Error(err, "otel shutdown error")
}
return err
})
Expand Down

0 comments on commit c958ae9

Please sign in to comment.