We are trying out multiple observability tools (like Jaeger, Prometheus, etc).
While building a demo application that sends the distributed tracing data to Jaeger. We used 'go.opentelemetry.io/otel/exporters/jaeger' to export the data to tracing data to Jaeger.
Which works fine and seem to fulfil our purpose. But while going through the Otel Documentation, we found out about "OpenTelemetry Collector".
Although we have a very high level understanding, but we do not seem to fully understand the correct use case for Otel Collector over the exporter that we are using.
TLDR; We are trying to understand the use cases and advantages of Otel Collector over the method were we directly export data to backed (In our case Jaeger).
Additional Information:
Following is the code snippet (written in Go) used to send the tracing data to Jaeger.
func tracerProvider(url string) (*tracesdk.TracerProvider, error) {
exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url)))
if err != nil {
return nil, err
}
tp := tracesdk.NewTracerProvider(
tracesdk.WithBatcher(exp),
tracesdk.WithResource(resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String(service),
attribute.String("environment", environment),
)),
)
return tp, nil
}
func main() {
tp, err := tracerProvider("http://localhost:14268/api/traces")
if err != nil {
log.Fatal(err)
}
otel.SetTracerProvider(tp)
propagator := propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{})
otel.SetTextMapPropagator(propagator)
// Business code
}
func serviceTwoCall(ctx context.Context, throwerror bool) *http.Response {
url := fmt.Sprintf("http://localhost:8080", throwerror)
req, _ := http.NewRequest(http.MethodGet, url, nil)
otelhttptrace.Inject(ctx, req)
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
fmt.Printf("Service Two Error %v", err.Error())
}
return res
}
Thanks!