Updated OtlpGrpcExporter to take an optional WithAddress argument
MODIFY
clients/go/gengo.go
clients/go/gengo.go
@@ -270,8 +270,8 @@ func doNothing(baseTransport http.RoundTripper, spanNameCtxValue interface{}, tp
func determineSampling() (samplingProbability float64, err error) {
- // // If we're running locally, then turn off sampling. Otherwise sample
- // // 1% or whatever TRACING_SAMPLING_PROBABILITY specifies.
+ // If we're running locally, then turn off sampling. Otherwise sample
+ // 1% or whatever TRACING_SAMPLING_PROBABILITY specifies.
samplingProbability = 0.01
isLocal := os.Getenv("_IS_LOCAL") == "true"
if isLocal {

MODIFY
tracing/tracing.go
tracing/tracing.go
@@ -25,14 +25,41 @@ const (
//propagator to use
var propagator propagation.TextMapPropagator = propagation.TraceContext{} // traceparent header
+type Option interface {
+ apply(*options)
+}
+type options struct {
+ address string
+}
+
+//WithAddress takes an address in the form of Host:Port
+func WithAddress(addr string) Option {
+ return addrOption{address: addr}
+}
+
+type addrOption struct {
+ address string
+}
+
+func (o addrOption) apply(opts *options) {
+ opts.address = o.address
+}
//OtlpGrpcExporter uses the otlptracegrpc modules and the otlptrace module to produce a new exporter at our default addr
-func OtlpGrpcExporter(ctx context.Context) sdktrace.SpanExporter {
+func OtlpGrpcExporter(ctx context.Context, opts ...Option) sdktrace.SpanExporter {
+
DefaultCollectorHost := "localhost"
var defaultCollectorPort uint16 = 4317
-
addr := fmt.Sprintf("%s:%d", DefaultCollectorHost, defaultCollectorPort)
+ options := options{
+ address: addr,
+ }
+
+ for _, o := range opts {
+ o.apply(&options)
+ }
+
otlpClient := otlptracegrpc.NewClient(
otlptracegrpc.WithEndpoint(addr), //Not strictly needed as we use the defaults
otlptracegrpc.WithReconnectionPeriod(15*time.Second),
@@ -52,11 +79,6 @@ func OtlpGrpcExporter(ctx context.Context) sdktrace.SpanExporter {
}
-//RoundTripperInstrumentor is probably a redundant wrap around a wrap.
-func RoundTripperInstrumentor(tp sdktrace.TracerProvider, baseRT http.RoundTripper, ctx context.Context) (http.RoundTripper, error) {
- return InstrumentedTransport(baseRT, ctx, tp), nil
-}
-
func newTracerProvider(exporter sdktrace.SpanExporter, samplingProbability float64, resource *resource.Resource) *sdktrace.TracerProvider {
return sdktrace.NewTracerProvider(
// We use the default ID generator. In order for sampling to work (at least with this sampler)

Updated OtlpGrpcExporter to take an optional WithAddress argument