What are the some use cases for OpenTelemetry Collectors?

huangapple go评论81阅读模式
英文:

What are the some use cases for OpenTelemetry Collectors?

问题

我们正在尝试多个可观察性工具(如Jaeger、Prometheus等)。

在构建一个将分布式跟踪数据发送到Jaeger的演示应用程序时,我们使用了go.opentelemetry.io/otel/exporters/jaeger来将数据导出到Jaeger。

这个方法运行良好,似乎满足了我们的需求。但是在阅读Otel文档时,我们了解到了"OpenTelemetry Collector"。

尽管我们对其有一个非常高层次的理解,但似乎并没有完全理解Otel Collector在我们直接将数据导出到后端(在我们的情况下是Jaeger)的方法上的正确用例。

简而言之,我们正在尝试理解Otel Collector相对于我们直接导出数据到后端的方法(在我们的情况下是Jaeger)的用例和优势。

附加信息:

以下是用于将跟踪数据发送到Jaeger的Go代码片段。

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)

    // 业务代码
}

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
}

希望对你有所帮助!

英文:

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!

答案1

得分: 2

Open Telemetry Collector的优势在于,您的代码可以完全不关心您用于存储/查询指标和跟踪的供应商。这意味着无论使用哪个供应商,都不再是与您的应用程序相关的细节,如果您想要更改供应商(例如本地开发)的环境中,您只需配置收集器以不同的方式运行即可。

收集器还意味着可以支持更多的导出器跨多种语言。虽然Go实现目前支持直接导出到Jaeger,但在其他语言中可能没有这个选项,但所有语言都应该支持收集器,然后可以导出到您偏好的任何地方。

根据我的个人经验,对于较小的安装,直接导出到Jaeger可能是有意义的。在您的集群中引入另一个组件可能会使事情变得复杂,特别是当您的应用程序相对简单时。使用收集器的阈值取决于许多因素,例如团队的规模,谁负责遥测,是否使用其他语言/运行时等。

英文:

Essentially, the advantage of the Open Telemetry Collector is that your code can remain entirely agnostic to what vendor you use for storing/querying metrics and tracing. It means that whatever that vendor is, is no longer a detail that is relevant to your application and that if in an environment you wanted to change what that was (e.g local development), you can simply configure the collector to behave differently.

The collector also means that more exporters may be supported across multiple languages. Whilst the Go implementation currently supports exporting directly to Jaeger, this may not be an option in other languages, but all languages should support the collector, which can then export off to whatever your preference is.

In my personal experience, for smaller installations it can make sense to export directly to Jaeger. Introducing another component to host within your clusters can complicate matters where your application is relatively simple. The threshold at which it makes sense to use the collector depends on many factors such as the size of your teams, who is responsible for telemetry, if other languages/runtimes are used etc.

答案2

得分: 0

最大的优势是你需要维护的代码更少,并且开箱即用提供了更多的导出选项。这个答案还提到了其他的优势。

这篇文章(下面是相关摘录)解释了sdkscollector之间的区别。我的理解是使用sdk+collector与你自己做所有事情是一样的,就像你说的那样。

> 在收集和摄取数据方面,有两个组件在起作用:
> - SDK:负责收集数据。
> - Collector:负责接收、处理和导出遥测数据的组件。

英文:

The greatest advantages are less code for you to maintain and more exporter options out of the box. This answer also mentions other advantages.

This post (relevant excerpt below) explains the difference between the sdks and collector. My understanding is that using the sdk+collector would be the same as doing everything yourself, like you said you did.

> When it comes to collecting and ingesting the data, there are two components in play:
> - The SDK: in charge of collecting the data.
> - The Collector: the component responsible for how to receive, process, and export
> telemetry data.

huangapple
  • 本文由 发表于 2021年8月31日 20:20:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/68998567.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定