Skip to content

Commit 34fd54e

Browse files
authored
Add trace headers to http subscriptions (#671)
* add trace headers to http subscriptions Signed-off-by: yaron2 <[email protected]> * fix json Signed-off-by: yaron2 <[email protected]> --------- Signed-off-by: yaron2 <[email protected]>
1 parent c97fd6f commit 34fd54e

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

service/common/type.go

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ type TopicEvent struct {
4747
PubsubName string `json:"pubsubname"`
4848
// Metadata is the custom metadata attached to the event.
4949
Metadata map[string]string `json:"metadata,omitempty"`
50+
// TraceID is the tracing header identifier for the incoming event
51+
TraceID string `json:"traceid"`
52+
// TraceParent is name of the parent trace identifier for the incoming event
53+
TraceParent string `json:"traceparent"`
5054
}
5155

5256
func (e *TopicEvent) Struct(target interface{}) error {

service/http/topic.go

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ type topicEventJSON struct {
6969
Topic string `json:"topic"`
7070
// PubsubName is name of the pub/sub this message came from
7171
PubsubName string `json:"pubsubname"`
72+
// TraceID is the tracing header identifier for the incoming event
73+
TraceID string `json:"traceid"`
74+
// TraceParent is name of the parent trace identifier for the incoming event
75+
TraceParent string `json:"traceparent"`
7276
}
7377

7478
func (in topicEventJSON) getData() (data any, rawData []byte) {
@@ -309,6 +313,8 @@ func (s *Server) AddTopicEventSubscriber(sub *common.Subscription, subscriber co
309313
PubsubName: in.PubsubName,
310314
Topic: in.Topic,
311315
Metadata: getCustomMetdataFromHeaders(r),
316+
TraceID: in.TraceID,
317+
TraceParent: in.TraceParent,
312318
}
313319

314320
w.Header().Add("Content-Type", "application/json")

service/http/topic_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ func TestEventHandler(t *testing.T) {
7171
"comexampleextension1" : "value",
7272
"comexampleothervalue" : 5,
7373
"datacontenttype" : "application/json",
74-
"data" : "eyJtZXNzYWdlIjoiaGVsbG8ifQ=="
74+
"data" : "eyJtZXNzYWdlIjoiaGVsbG8ifQ==",
75+
"traceid": "aaa",
76+
"traceparent": "bbb"
7577
}`
7678

7779
s := newServer("", nil)

0 commit comments

Comments
 (0)