Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加UseRequestContext支持 #44

Open
2 of 10 tasks
alimy opened this issue Feb 9, 2024 · 0 comments
Open
2 of 10 tasks

添加UseRequestContext支持 #44

alimy opened this issue Feb 9, 2024 · 0 comments
Assignees
Labels
Milestone

Comments

@alimy
Copy link
Owner

alimy commented Feb 9, 2024

源由:

最近在集成OpenTelemetry到使用gin的项目中,使用otelginotelgorm进行 Trace链路追踪(详情请见paopao-ce),集成过程中遇到一些问题,比如使用go-mir生成的代码默认是不带Engine Context或 HTTP Request Context,而otelgin是使用 HTTP Request Context来透传OpenTelemetry相关上下文的,如果需要将从HTTP Request 到DB数据库之间的链路串连在一起,就需要显示的Context来透传链路的上下文信息,也就是需要显示获取最原始请求的HTTP Request Context。目前go-mir支持代码生成的接口显示带有Engine Context,比如Gin的*gin.Context,只需要在接口定义处添加Context原语,一般HTTP Request Context可以从Engine Context中获取。还有一种获取HTTP Request Context的方法就是在请求参数Bind的时候获取,比如在默认的Bind函数中获取HTTP Request Context后赋值给接口的请求参数。以上两种方法都能满足需求,但都是采用了取巧的法子来完成,本提按提供一种直接在生成代码的接口方法中直接带上HTTP Request Context来满足需求。

需求:

  • 使用UseRequestContext Option选项开启添加HTTP Request Context到接口方法的功能;
  • 默认不开启UseRequestContext功能;
  • 如果接口方法开启了 Engine Context的约束(添加了Context原语),优先使用 Engine Context约束;

方案:

  • 为go-mir添加UseRequestContext Option选项开启添加HTTP Request Context到接口方法的功能;

适配进度

  • gin
  • chi
  • echo
  • fiber
  • hertz
  • httprouter
  • iris
  • macaron
  • mux
  • mirc
@alimy alimy self-assigned this Feb 9, 2024
@alimy alimy added the feature label Feb 9, 2024
@alimy alimy added this to the v4.2.0 milestone Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant