I added a tiny wrapper around this library to participate in distributed tracing, works like a charm with nodejs services (communicating with swift services through rabbitmq.)
Ideally, this can come out of the box. We'd either need some sort of config for it or maybe a middleware system?
Here is what I use:
struct AMQPHeaderPropagation: Extractor, Injector {
typealias Carrier = Table?
func extract(key: String, from carrier: Carrier) -> String? { carrier?[key]?.asString }
func inject(_ value: String, forKey key: String, into carrier: inout Carrier) {
carrier = carrier ?? Table()
carrier![key] = .longString(value)
}
}
private extension Field {
var asString: String? {
switch self {
case let .longString(s): return s
// NOTE: maybe support more data types
default: return nil
}
}
}
extension ServiceContext {
var asAqmpHeaders: Table? {
var headers: Table?
InstrumentationSystem.instrument.inject(self, into: &headers, using: AMQPHeaderPropagation())
return headers
}
}
extension AMQPResponse.Channel.Message.Delivery {
var serviceContext: ServiceContext {
var context = ServiceContext.topLevel
InstrumentationSystem.instrument.extract(properties.headers, into: &context, using: AMQPHeaderPropagation())
return context
}
}
I added a tiny wrapper around this library to participate in distributed tracing, works like a charm with nodejs services (communicating with swift services through rabbitmq.)
Ideally, this can come out of the box. We'd either need some sort of config for it or maybe a middleware system?
Here is what I use: