@@ -37,24 +37,27 @@ using namespace httpd_otel;
37
37
const char kOpenTelemetryKeyNote [] = " OTEL" ;
38
38
const char kOpenTelemetryKeyOutboundNote [] = " OTEL_PROXY" ;
39
39
40
- static nostd::string_view HttpdGetter ( const apr_table_t &hdrs, nostd::string_view trace_type)
40
+ class HttpdCarrier : public opentelemetry ::context::propagation::TextMapCarrier
41
41
{
42
- auto fnd = apr_table_get (&hdrs, std::string (trace_type).c_str ());
43
- return fnd ? fnd : " " ;
44
- }
45
-
46
- static void HttpdSetter (apr_table_t &hdrs,
47
- nostd::string_view trace_type,
48
- nostd::string_view trace_description)
49
- {
50
- apr_table_set (&hdrs, std::string (trace_type).c_str (),
51
- std::string (trace_description).c_str ());
52
- }
42
+ public:
43
+ apr_table_t & hdrs;
44
+ HttpdCarrier (apr_table_t & headers):hdrs(headers){}
45
+ virtual nostd::string_view Get (nostd::string_view key) const noexcept override
46
+ {
47
+ auto fnd = apr_table_get (&hdrs, std::string (key).c_str ());
48
+ return fnd ? fnd : " " ;
49
+ }
50
+ virtual void Set (nostd::string_view key, nostd::string_view value) noexcept override
51
+ {
52
+ apr_table_set (&hdrs, std::string (key).c_str (),
53
+ std::string (value).c_str ());
54
+ }
55
+ };
53
56
54
57
// propagators
55
- opentelemetry::trace::propagation::HttpTraceContext< apr_table_t > PropagatorTraceContext;
56
- opentelemetry::trace::propagation::B3Propagator< apr_table_t > PropagatorB3SingleHeader;
57
- opentelemetry::trace::propagation::B3PropagatorMultiHeader< apr_table_t > PropagatorB3MultiHeader;
58
+ opentelemetry::trace::propagation::HttpTraceContext PropagatorTraceContext;
59
+ opentelemetry::trace::propagation::B3Propagator PropagatorB3SingleHeader;
60
+ opentelemetry::trace::propagation::B3PropagatorMultiHeader PropagatorB3MultiHeader;
58
61
59
62
// from:
60
63
// https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#http-server-semantic-conventions
@@ -123,16 +126,17 @@ static int opentel_handler(request_rec *r, int /* lookup_uri */ )
123
126
124
127
if (!config.ignore_inbound && config.propagation != OtelPropagation::NONE)
125
128
{
129
+ HttpdCarrier car (*req->headers_in );
126
130
opentelemetry::v0::context::Context ctx_new,
127
131
ctx_cur = opentelemetry::context::RuntimeContext::GetCurrent ();
128
132
switch (config.propagation )
129
133
{
130
134
default :
131
- ctx_new = PropagatorTraceContext.Extract (HttpdGetter, *req-> headers_in , ctx_cur);
135
+ ctx_new = PropagatorTraceContext.Extract (car , ctx_cur);
132
136
break ;
133
137
case OtelPropagation::B3_SINGLE_HEADER:
134
138
case OtelPropagation::B3_MULTI_HEADER:
135
- ctx_new = PropagatorB3SingleHeader.Extract (HttpdGetter, *req-> headers_in , ctx_cur);
139
+ ctx_new = PropagatorB3SingleHeader.Extract (car , ctx_cur);
136
140
}
137
141
req_data->token = opentelemetry::context::RuntimeContext::Attach (ctx_new);
138
142
}
@@ -221,16 +225,17 @@ static int proxy_fixup_handler(request_rec *r)
221
225
222
226
// mod_proxy simply copies request headers from client therefore inject is into headers_in
223
227
// instead of headers_out
228
+ HttpdCarrier car (*req->headers_in );
224
229
switch (config.propagation )
225
230
{
226
231
case OtelPropagation::TRACE_CONTEXT:
227
- PropagatorTraceContext.Inject (HttpdSetter, *req-> headers_in , opentelemetry::context::RuntimeContext::GetCurrent ());
232
+ PropagatorTraceContext.Inject (car , opentelemetry::context::RuntimeContext::GetCurrent ());
228
233
break ;
229
234
case OtelPropagation::B3_SINGLE_HEADER:
230
- PropagatorB3SingleHeader.Inject (HttpdSetter, *req-> headers_in , opentelemetry::context::RuntimeContext::GetCurrent ());
235
+ PropagatorB3SingleHeader.Inject (car , opentelemetry::context::RuntimeContext::GetCurrent ());
231
236
break ;
232
237
case OtelPropagation::B3_MULTI_HEADER:
233
- PropagatorB3MultiHeader.Inject (HttpdSetter, *req-> headers_in , opentelemetry::context::RuntimeContext::GetCurrent ());
238
+ PropagatorB3MultiHeader.Inject (car , opentelemetry::context::RuntimeContext::GetCurrent ());
234
239
break ;
235
240
default : // suppress warning
236
241
break ;
0 commit comments