导出 OpenTelemetry 数据到 New Relic 出现问题。

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

Problem with export open telemetry data to newRelic

问题

我有一个关于将开放遥测数据导出并发送到NewRelic的GRPC端点的问题。
这是我尝试连接到NewRelic端点的代码片段:

var headers = map[string]string{
    "api-key": "我的NewRelic API密钥",
}

var clientOpts = []otlptracegrpc.Option{
    otlptracegrpc.WithEndpoint("https://otlp.nr-data.net:4317"),
    otlptracegrpc.WithInsecure(),
    otlptracegrpc.WithReconnectionPeriod(2 * time.Second),
    otlptracegrpc.WithDialOption(grpc.WithBlock()),
    otlptracegrpc.WithTimeout(30 * time.Second),
    otlptracegrpc.WithHeaders(headers),
    otlptracegrpc.WithCompressor("gzip"),
}

otlpExporter, err := otlptrace.New(ctx, otlptracegrpc.NewClient(clientOpts...))
if err != nil {
    return nil, fmt.Errorf("创建OTLP跟踪导出器时出错:%w", err)
}

resource, _ := g.Config.resource(ctx)
tracerProvider := trace.NewTracerProvider(
    trace.WithSampler(trace.AlwaysSample()),
    trace.WithBatcher(otlpExporter),
    trace.WithResource(resource),
)

otel.SetTracerProvider(tracerProvider)

它在otlptrace.New这一步卡住了。

我是OpenTelemetry的新手,我阅读了OpenTelemetry的文档,我可以在控制台打印Otel数据,但是当我想将其导出到NewRelic时,它不起作用。
我也阅读了NewRelic的Otel文档,他们有一个导出器SDK,但已经停用了,他们提供了这个新的GRPC端点,但是文档和示例都不太完善。
你有什么想法吗?

英文:

I have an issue with exporting and sending the open telemetry data to the newRelic's GRPC endpoint.
This is my snippet code that tries to connect to the newRelic endpoint:

var headers = map[string]string{
	"api-key": "my newRelc API key",
}

var clientOpts = []otlptracegrpc.Option{
	otlptracegrpc.WithEndpoint("https://otlp.nr-data.net:4317"),
	otlptracegrpc.WithInsecure(),
	otlptracegrpc.WithReconnectionPeriod(2 * time.Second),
	otlptracegrpc.WithDialOption(grpc.WithBlock()),
	otlptracegrpc.WithTimeout(30 * time.Second),
	otlptracegrpc.WithHeaders(headers),
	otlptracegrpc.WithCompressor("gzip"),
}

otlpExporter, err := otlptrace.New(ctx, otlptracegrpc.NewClient(clientOpts...))
if err != nil {
	return nil, fmt.Errorf("creating OTLP trace exporter: %w", err)
}

resource, _ := g.Config.resource(ctx)
tracerProvider := trace.NewTracerProvider(
	trace.WithSampler(trace.AlwaysSample()),
	trace.WithBatcher(otlpExporter),
	trace.WithResource(resource),
)

otel.SetTracerProvider(tracerProvider)

it stuck in step otlptrace.New.

I'm new in OpenTelemetry, I read the open telemetry documentation and I can print Otel data in the console but when I want to export it to newrelic it does not work.
I read newRelic Otel documentation too and they had an exporter SDK but it discontinued and they provide this new GRPC endpoint but it does not have well documentation and example.
Do you have any idea?

答案1

得分: 0

我找到了问题,问题出在TLS方面。
我将这行代码:

otlptracegrpc.WithInsecure(),

替换为这行代码:

otlptracegrpc.WithTLSCredentials(credentials.NewClientTLSFromCert(nil, "")),
英文:

I found the problem, The issue was about TLS.
I replaced this line:

otlptracegrpc.WithInsecure(),

with this line:

otlptracegrpc.WithTLSCredentials(credentials.NewClientTLSFromCert(nil, "")),

huangapple
  • 本文由 发表于 2021年11月25日 19:08:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/70110038.html
匿名

发表评论

匿名网友

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

确定