Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

Can I add tags to messaging spans based on message header values using Spring Cloud Sleuth?

I am using Spring Cloud Sleuth to send spans to zipkin when a Spring Boot application sends a message (to RabbitMQ).

I would like to customize the information sent to zipkin to include some extra tags that are populated from certain headers of the outgoing Message e.g. the myCustomTag below.

"traceId": "9fc1f35070446800",
"parentId": "033b24f12d5fe4e8",
"id": "fea24862c3e1f374",
"kind": "PRODUCER",
"name": "send",
"timestamp": 1609943208647127,
"duration": 1407,
"localEndpoint": {
  "serviceName": "foo-service",
  "ipv4": "10.204.71.17"
},
"remoteEndpoint": {
  "serviceName": "broker"
},
"tags": {
  "channel": "fooEventsChannel",
  "myCustomTag": <some value extracted from the "Bar" header of the outgoing message>
}

Is it possible to do this using Sleuth/brave? It feels like a messaging equivalent of registering (e.g.) a bean of type brave.http.HttpRequestParser but I couldn't see an obvious way forward.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use a TagValueResolver or a MessageSpanCustomizer, see the docs for the details.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...