在使用Golang编写的OpenTelemetry导出器方面取得了部分成功。

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

Partial succes on opentelemtry exporter in golang

问题

我正在运行一个开放遥测收集器的Pod,它暴露在端口4318上(运行Node.js演示程序完美运行)。

但是运行这个基本的代码示例(基本上只是在初始化跟踪器并发送跨度后运行一个简单的程序):

package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"os/signal"
	"time"

	"go.opentelemetry.io/otel"

	"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"

	"go.opentelemetry.io/otel/sdk/resource"
	sdktrace "go.opentelemetry.io/otel/sdk/trace"
	semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
)

func initProvider() func() {
	ctx := context.Background()

	_, err := resource.New(ctx,
		resource.WithAttributes(
			semconv.ServiceNameKey.String("test-service"),
		),
	)
	handleErr(err, "failed to create resource")
	traceExporter, err := otlptracehttp.New(ctx,
		otlptracehttp.WithInsecure(),
		otlptracehttp.WithEndpoint("localhost:4318"),
	)

	handleErr(err, "failed to create trace exporter")

	bsp := sdktrace.NewBatchSpanProcessor(traceExporter)
	tracerProvider := sdktrace.NewTracerProvider(
		sdktrace.WithSpanProcessor(bsp),
	)

	otel.SetTracerProvider(tracerProvider)
	return func() {
		handleErr(tracerProvider.Shutdown(ctx), "failed to shutdown TracerProvider")
	}
}

func initialize() {

	traceExp, err := otlptracehttp.New(
		context.Background(),
		otlptracehttp.WithEndpoint("127.0.0.1:8082"),
		otlptracehttp.WithURLPath("v1/traces"),
		otlptracehttp.WithInsecure(),
	)
	if err != nil {
		fmt.Println(err)
	}

	bsp := sdktrace.NewBatchSpanProcessor(traceExp)
	tracerProvider := sdktrace.NewTracerProvider(
		sdktrace.WithSpanProcessor(bsp),
	)

	otel.SetTracerProvider(tracerProvider)
}

func main() {
	log.Printf("Waiting for connection...")

	ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
	defer cancel()

	initProvider()

	tracer := otel.Tracer("demo-client-tracer")
	ctx, span := tracer.Start(context.TODO(), "span-name")

	defer span.End()
	for i := 0; i < 10; i++ {
		_, iSpan := tracer.Start(ctx, fmt.Sprintf("Sample-%d", i))
		log.Printf("Doing really hard work (%d / 10)\n", i+1)

		<-time.After(time.Second)
		iSpan.End()
	}

	log.Printf("Done!")
}

func handleErr(err error, message string) {
	if err != nil {
		log.Fatalf("%s: %v", message, err)
	}
}

我得到了:

OTLP部分成功:空消息(0个跨度被拒绝)

并且没有发送任何跟踪... 有什么想法吗?我漏掉了什么?

英文:

I'm running a pod of open telemetry collector that is exposed to port 4318 (running node js demo working perfectly)

but running this basic code sample (which basically just running a simple program after initiating the Tracer and sending spans)


package main
import (
&quot;context&quot;
&quot;fmt&quot;
&quot;log&quot;
&quot;os&quot;
&quot;os/signal&quot;
&quot;time&quot;
&quot;go.opentelemetry.io/otel&quot;
&quot;go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp&quot;
// &quot;go.opentelemetry.io/otel/propagation&quot;
&quot;go.opentelemetry.io/otel/sdk/resource&quot;
sdktrace &quot;go.opentelemetry.io/otel/sdk/trace&quot;
semconv &quot;go.opentelemetry.io/otel/semconv/v1.4.0&quot;
)
func initProvider() func() {
ctx := context.Background()
_, err := resource.New(ctx,
resource.WithAttributes(
semconv.ServiceNameKey.String(&quot;test-service&quot;),
),
)
handleErr(err, &quot;failed to create resource&quot;)
traceExporter, err := otlptracehttp.New(ctx,
otlptracehttp.WithInsecure(),
otlptracehttp.WithEndpoint(&quot;localhost:4318&quot;),
)
handleErr(err, &quot;failed to create trace exporter&quot;)
bsp := sdktrace.NewBatchSpanProcessor(traceExporter)
tracerProvider := sdktrace.NewTracerProvider(
// sdktrace.WithSampler(sdktrace.AlwaysSample()),
// sdktrace.WithResource(res),
sdktrace.WithSpanProcessor(bsp),
)
otel.SetTracerProvider(tracerProvider)
// otel.SetTextMapPropagator(propagation.TraceContext{})
return func() {
handleErr(tracerProvider.Shutdown(ctx), &quot;failed to shutdown TracerProvider&quot;)
}
}
func initialize() {
traceExp, err := otlptracehttp.New(
context.Background(),
otlptracehttp.WithEndpoint(&quot;127.0.0.1:8082&quot;),
otlptracehttp.WithURLPath(&quot;v1/traces&quot;),
otlptracehttp.WithInsecure(),
)
if err != nil {
fmt.Println(err)
}
bsp := sdktrace.NewBatchSpanProcessor(traceExp)
tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithSpanProcessor(bsp),
)
otel.SetTracerProvider(tracerProvider)
}
func main() {
log.Printf(&quot;Waiting for connection...&quot;)
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
// shutdown := initProvider()
// defer shutdown()
initProvider()
tracer := otel.Tracer(&quot;demo-client-tracer&quot;)
ctx, span := tracer.Start(context.TODO(), &quot;span-name&quot;)
defer span.End()
for i := 0; i &lt; 10; i++ {
_, iSpan := tracer.Start(ctx, fmt.Sprintf(&quot;Sample-%d&quot;, i))
log.Printf(&quot;Doing really hard work (%d / 10)\n&quot;, i+1)
&lt;-time.After(time.Second)
iSpan.End()
}
log.Printf(&quot;Done!&quot;)
}
func handleErr(err error, message string) {
if err != nil {
log.Fatalf(&quot;%s: %v&quot;, message, err)
}
}

and Im getting :

OTLP partial success: empty message (0 spans rejected)

and no traces is being sent...
any ideas?
what am I missing ?

答案1

得分: 1

这是OTLP导出器和收集器之间的一个错误,应该在v1.11.2版本中解决。升级到最新版本的go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp应该可以解决这个问题。

英文:

This was a bug between the OTLP exporter and collector that should have been resolved in the v1.11.2 release. Upgrading to the latest version of the go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp should resolve this.

huangapple
  • 本文由 发表于 2022年11月17日 17:49:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/74473295.html
匿名

发表评论

匿名网友

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

确定