11package notify
22
33import (
4+ "context"
45 "errors"
56 "github.com/parnurzeal/gorequest"
7+ "go.opentelemetry.io/otel"
8+ "go.opentelemetry.io/otel/propagation"
69 "sync"
710)
811
@@ -53,6 +56,7 @@ type SendResult struct {
5356}
5457
5558type Template struct {
59+ ctx context.Context
5660 StaffID []string `json:"StaffID"`
5761 WeChat * WeChatNoticeBody `json:"template,omitempty"`
5862 DingTalk * DingTalkNoticeBody `json:"dingtalk,omitempty"`
@@ -63,6 +67,11 @@ func New() *Template {
6367 return & Template {}
6468}
6569
70+ func (t * Template ) WithContext (ctx context.Context ) * Template {
71+ t .ctx = ctx
72+ return t
73+ }
74+
6675func (t * Template ) Receiver (staffId ... string ) * Template {
6776 t .StaffID = append (t .StaffID , staffId ... )
6877 return t
@@ -95,8 +104,12 @@ func (t *Template) Send() error {
95104
96105 notifier := notifierPool .Get ().(* gorequest.SuperAgent )
97106 defer notifierPool .Put (notifier )
98- _ , _ , errs := notifier .Send (t ).EndStruct (result )
99107
108+ // Add tracing information to the request header.
109+ propagator := otel .GetTextMapPropagator ()
110+ propagator .Inject (t .ctx , propagation .HeaderCarrier (notifier .Header ))
111+
112+ _ , _ , errs := notifier .Send (t ).EndStruct (result )
100113 if errs != nil || result .Msg != "success" || result .Data .Failed != 0 {
101114 return errors .New ("send notify failed" )
102115 }
0 commit comments