gogf / gf

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
https://goframe.org
MIT License
11.76k stars 1.6k forks source link

contrib/trace/otlpgrpc: grpc connection to opentelemetry collector authentication failed #3893

Open ivothgle opened 3 weeks ago

ivothgle commented 3 weeks ago

Go version

go1.20

GoFrame version

2.7.0

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

  1. 使用 github.com/gogf/gf/contrib/trace/otlpgrpc/v2 上传数据到 OpenTelemetry Collector,
  2. 当我给Collector 的 receivers 添加认证时,如 basicauth 或 bearertokenauth 如配置
    
    extensions:
    health_check:
    bearertokenauth:
    token: "your-secret-token"

receivers: otlp: protocols: grpc: auth: authenticator: bearertokenauth ...

然后使用

otlpgrpc.Init(serviceName, ""localhost:4317"), "Bearer your-secret-token")



这将会报告认证失败 `traces export: rpc error: code = Unknown desc = authentication didn't succeed`

为什么会这样?
经过一天的排查我发现了问题原因
在例子中 https://github.com/gogf/gf/blob/master/example/trace/otlp/grpc/main.go 这里使用的阿里云
同时根据阿里云文档 https://help.aliyun.com/zh/arms/tracing-analysis/connect-opentelemetry-to-tracing-analysis 和 https://help.aliyun.com/zh/opentelemetry/user-guide/connect-to-managed-service-for-opentelemetry-and-authenticate-clients

这里的认证头是使用 `Authentication` 实现的
所以在 https://github.com/gogf/gf/blob/master/contrib/trace/otlpgrpc/otlpgrpc.go#L60 固定了hander

但是在 OpenTelemetry Collector 中是用 `authorization` 来接受认证头的,所以这导致认证失败
虽然只找到这个说明 https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configgrpc/README.md 和 https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configauth/README.md
但我实测确实是用  `authorization`  能认证通过

期望这个能调整这个内容,或者在例子中额外说明,这个只适用于阿里云而可能不适用于其他接收器

### What did you see happen?

报错
traces export: rpc error: code = Unknown desc = authentication didn't succeed

### What did you expect to see?

不应该报错
ivothgle commented 3 weeks ago

OpenTelemetry Collector 中获取 token hander 的相关代码 https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/extension/bearertokenauthextension/bearertokenauth.go#L187

houseme commented 1 week ago

otlpgrpcOpenTelemetry Collector 俩个不同的处理,OpenTelemetry Collector 需要自己单独处理一下

建议参考自定义一个 OpenTelemetry client。 https://github.com/gogf/gf/blob/master/example/trace/provider/grpc/main.go

ivothgle commented 4 days ago

@houseme 我知道可以自己实现,但我更希望至少在文档上说明清楚,避免后续的人踩同样的坑

Issues-translate-bot commented 4 days ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@houseme I know I can implement it myself, but I would rather at least explain it clearly in the documentation to avoid subsequent people falling into the same trap.

houseme commented 4 days ago

@houseme 我知道可以自己实现,但我更希望至少在文档上说明清楚,避免后续的人踩同样的坑

辛苦您补充一下文档内容,感谢🙏

Issues-translate-bot commented 4 days ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@houseme I know I can implement it myself, but I would rather at least explain it clearly in the documentation to avoid subsequent people falling into the same trap.

Could you please add the content of the document, thank you🙏