Skip to content

Commit

Permalink
Add trace headers to http subscriptions (#671)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
yaron2 authored Jan 13, 2025
1 parent c97fd6f commit 34fd54e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions service/common/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type TopicEvent struct {
PubsubName string `json:"pubsubname"`
// Metadata is the custom metadata attached to the event.
Metadata map[string]string `json:"metadata,omitempty"`
// TraceID is the tracing header identifier for the incoming event
TraceID string `json:"traceid"`
// TraceParent is name of the parent trace identifier for the incoming event
TraceParent string `json:"traceparent"`
}

func (e *TopicEvent) Struct(target interface{}) error {
Expand Down
6 changes: 6 additions & 0 deletions service/http/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ type topicEventJSON struct {
Topic string `json:"topic"`
// PubsubName is name of the pub/sub this message came from
PubsubName string `json:"pubsubname"`
// TraceID is the tracing header identifier for the incoming event
TraceID string `json:"traceid"`
// TraceParent is name of the parent trace identifier for the incoming event
TraceParent string `json:"traceparent"`
}

func (in topicEventJSON) getData() (data any, rawData []byte) {
Expand Down Expand Up @@ -309,6 +313,8 @@ func (s *Server) AddTopicEventSubscriber(sub *common.Subscription, subscriber co
PubsubName: in.PubsubName,
Topic: in.Topic,
Metadata: getCustomMetdataFromHeaders(r),
TraceID: in.TraceID,
TraceParent: in.TraceParent,
}

w.Header().Add("Content-Type", "application/json")
Expand Down
4 changes: 3 additions & 1 deletion service/http/topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func TestEventHandler(t *testing.T) {
"comexampleextension1" : "value",
"comexampleothervalue" : 5,
"datacontenttype" : "application/json",
"data" : "eyJtZXNzYWdlIjoiaGVsbG8ifQ=="
"data" : "eyJtZXNzYWdlIjoiaGVsbG8ifQ==",
"traceid": "aaa",
"traceparent": "bbb"
}`

s := newServer("", nil)
Expand Down

0 comments on commit 34fd54e

Please sign in to comment.