Jaeger-lib is a client library used for distributed tracing in distributed systems. It integrates with various client libraries such as the go client, and facilitates data sharing between components by allowing them to generate, propagate, and collect trace data.
Jaeger-lib provides support for different programming languages, including Go, Java, Node.js, Python, C++, and C#. It uses OpenTracing, a vendor-neutral API, to instrument and trace application code. The OpenTracing API allows developers to add tracing to their applications without being tied to a specific tracing system.
The Go client library, github.com/uber/jaeger-client-go, is an example of how Jaeger-lib integrates with a specific client library. It provides a simple and efficient way to generate and propagate trace data in Go applications. The Go client library uses the Go Kit middleware to instrument and trace application code.
Here is an example of how to use the Go client library to instrument a Go application:
import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace"
jaegercfg "github.com/jaegertracing/jaeger/cmd/jaeger-agent/config"
jaeger "github.com/uber/jaeger-client-go"
)
func newTracerProvider() *trace.TracerProvider {
cfg := jaegercfg.Configuration{
ServiceName: "my-service",
Sampler: &jaegercfg.SamplerConfig{
Type: jaeger.SamplerTypeConst,
Param: 1,
},
Reporter: &jaegercfg.ReporterConfig{
LogSpans: true,
LocalAgentHostPort: "localhost:6831",
},
}
jClient, err := cfg.NewJaegerClient()
if err != nil {
panic(fmt.Sprintf("Failed to create Jaeger client: %v", err))
}
tp := trace.NewTracerProvider(
trace.WithBatcher(jClient),
trace.WithResource(resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String("my-service"),
)),
)
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.B3{}, propagation.Baggage{}))
return tp
}
In this example, the newTracerProvider
function creates a new Jaeger tracer provider that sends trace data to a local Jaeger agent running on localhost:6831
. The tracer provider is then set as the global tracer provider using the OpenTelemetry API.
Jaeger-lib also provides support for remote sampling configuration, which allows distributed applications to negotiate sampling rates dynamically. The remote sampling configuration API is defined in the sampling.proto
IDL file and is implemented by both the Jaeger agent and collector.
Here is an example of how to use the remote sampling configuration API in Go:
import (
"context"
"fmt"
"github.com/jaegertracing/jaeger/model"
"google.golang.org/grpc"
)
func newRemoteSampler(ctx context.Context, endpoint string) (model.Sampler, error) {
conn, err := grpc.DialContext(ctx, endpoint, grpc.WithInsecure())
if err != nil {
return nil, fmt.Errorf("failed to connect to remote sampler: %w", err)
}
client := model.NewSamplingServiceClient(conn)
return model.NewRemoteSampler(client), nil
}
In this example, the newRemoteSampler
function creates a new remote sampler that negotiates sampling rates with a remote Jaeger sampler running at the specified endpoint.
In summary, Jaeger-lib is a client library that integrates with various client libraries to facilitate data sharing between components in distributed systems. It provides support for different programming languages and uses OpenTracing to instrument and trace application code. The Go client library, github.com/uber/jaeger-client-go, is an example of how Jaeger-lib integrates with a specific client library. Jaeger-lib also provides support for remote sampling configuration, which allows distributed applications to negotiate sampling rates dynamically.