Skip to content

Commit

Permalink
Fix tracing over network to fit standard MTU 1500 size. (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
Baliedge authored Mar 7, 2022
1 parent d4b6196 commit 9194767
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tracing

import (
"context"
"os"
"sync"
"time"

Expand Down Expand Up @@ -35,9 +36,9 @@ var defaultTracer trace.Tracer
// Call after initializing logrus.
// libraryName is typically the application's module name.
func InitTracing(ctx context.Context, libraryName string, opts ...sdktrace.TracerProviderOption) (context.Context, trace.Tracer, error) {
exp, err := jaeger.New(jaeger.WithAgentEndpoint())
exp, err := makeJaegerExporter()
if err != nil {
return ctx, nil, errors.Wrap(err, "error in jaeger.New")
return ctx, nil, errors.Wrap(err, "error in makeJaegerExporter")
}

opts2 := []sdktrace.TracerProviderOption{
Expand Down Expand Up @@ -140,3 +141,25 @@ func TracerFromContext(ctx context.Context) trace.Tracer {
tracer, _ := ctx.Value(tracerKey{}).(trace.Tracer)
return tracer
}

func makeJaegerExporter() (*jaeger.Exporter, error) {
var agentEndpointOpts []jaeger.AgentEndpointOption

agentHost := os.Getenv("OTEL_EXPORTER_JAEGER_AGENT_HOST")
if agentHost != "" && agentHost != "localhost" && agentHost != "127.0.0.1" {
// Default MaxPacketSize=65000, which only works with Jaeger agent on
// localhost (loopback interface).
// For tracing over network, packets must fit in MTU 1500, which has a
// payload size of 1472.
agentEndpointOpts = append(agentEndpointOpts, jaeger.WithMaxPacketSize(1472))
}

exp, err := jaeger.New(
jaeger.WithAgentEndpoint(agentEndpointOpts...),
)
if err != nil {
return nil, errors.Wrap(err, "error in jaeger.New")
}

return exp, nil
}

0 comments on commit 9194767

Please sign in to comment.