Skip to content

Commit a50e7cf

Browse files
authored
Bump otel-cpp dependency to 0.6.0 for Apache (#22)
* Add codeowners Fixes #9 * Fix team names inside codeowners * Use CODEOWNERS from otel-cpp-contrib * Update opentelemetry-cpp dependency to revision 5278e8c * Fix tests to match how attributes are presented (it was broken by #632 commit 179a7f4) * Remove commented code
1 parent 6bf2a8c commit a50e7cf

File tree

5 files changed

+48
-44
lines changed

5 files changed

+48
-44
lines changed

instrumentation/httpd/WORKSPACE

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
33
# Load OpentTelemetry-CPP dependency
44
http_archive(
55
name = "io_opentelemetry_cpp",
6-
sha256 = "2621cb0efd9bae78a1f06866cf8e96417446a6a70568ed6f804a6cb91d916db1",
7-
strip_prefix = "opentelemetry-cpp-bd68a22ff5f2343de68f9d56a68bc53ecd69d567",
6+
sha256 = "59e16eab4f534907144882fe70a1ca4514cf720f7b8b6e2a2d999a1b1a9265c8",
7+
strip_prefix = "opentelemetry-cpp-b4584adeaae259df89b33af884c641e70a60a7cf",
88
urls = [
9-
"https://github.com/open-telemetry/opentelemetry-cpp/archive/bd68a22ff5f2343de68f9d56a68bc53ecd69d567.tar.gz"
9+
"https://github.com/open-telemetry/opentelemetry-cpp/archive/b4584adeaae259df89b33af884c641e70a60a7cf.tar.gz"
1010
],
1111
)
1212

instrumentation/httpd/src/otel/mod_otel.cpp

+25-20
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,27 @@ using namespace httpd_otel;
3737
const char kOpenTelemetryKeyNote[] = "OTEL";
3838
const char kOpenTelemetryKeyOutboundNote[] = "OTEL_PROXY";
3939

40-
static nostd::string_view HttpdGetter(const apr_table_t &hdrs, nostd::string_view trace_type)
40+
class HttpdCarrier : public opentelemetry::context::propagation::TextMapCarrier
4141
{
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+
};
5356

5457
// 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;
5861

5962
// from:
6063
// 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 */ )
123126

124127
if (!config.ignore_inbound && config.propagation != OtelPropagation::NONE)
125128
{
129+
HttpdCarrier car(*req->headers_in);
126130
opentelemetry::v0::context::Context ctx_new,
127131
ctx_cur = opentelemetry::context::RuntimeContext::GetCurrent();
128132
switch (config.propagation)
129133
{
130134
default:
131-
ctx_new = PropagatorTraceContext.Extract(HttpdGetter, *req->headers_in, ctx_cur);
135+
ctx_new = PropagatorTraceContext.Extract(car, ctx_cur);
132136
break;
133137
case OtelPropagation::B3_SINGLE_HEADER:
134138
case OtelPropagation::B3_MULTI_HEADER:
135-
ctx_new = PropagatorB3SingleHeader.Extract(HttpdGetter, *req->headers_in, ctx_cur);
139+
ctx_new = PropagatorB3SingleHeader.Extract(car, ctx_cur);
136140
}
137141
req_data->token = opentelemetry::context::RuntimeContext::Attach(ctx_new);
138142
}
@@ -221,16 +225,17 @@ static int proxy_fixup_handler(request_rec *r)
221225

222226
// mod_proxy simply copies request headers from client therefore inject is into headers_in
223227
// instead of headers_out
228+
HttpdCarrier car(*req->headers_in);
224229
switch (config.propagation)
225230
{
226231
case OtelPropagation::TRACE_CONTEXT:
227-
PropagatorTraceContext.Inject(HttpdSetter, *req->headers_in, opentelemetry::context::RuntimeContext::GetCurrent());
232+
PropagatorTraceContext.Inject(car, opentelemetry::context::RuntimeContext::GetCurrent());
228233
break;
229234
case OtelPropagation::B3_SINGLE_HEADER:
230-
PropagatorB3SingleHeader.Inject(HttpdSetter, *req->headers_in, opentelemetry::context::RuntimeContext::GetCurrent());
235+
PropagatorB3SingleHeader.Inject(car, opentelemetry::context::RuntimeContext::GetCurrent());
231236
break;
232237
case OtelPropagation::B3_MULTI_HEADER:
233-
PropagatorB3MultiHeader.Inject(HttpdSetter, *req->headers_in, opentelemetry::context::RuntimeContext::GetCurrent());
238+
PropagatorB3MultiHeader.Inject(car, opentelemetry::context::RuntimeContext::GetCurrent());
234239
break;
235240
default: // suppress warning
236241
break;

instrumentation/httpd/src/otel/opentelemetry.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,17 @@ void initTracer()
7373
break;
7474
}
7575

76-
std::shared_ptr<sdktrace::SpanProcessor> processor;
76+
std::unique_ptr<sdktrace::SpanProcessor> processor;
7777

7878
if (config.batch_opts.max_queue_size)
7979
{
80-
processor = std::make_shared<sdktrace::BatchSpanProcessor>(
81-
std::move(exporter), config.batch_opts);
80+
processor = std::unique_ptr<sdktrace::SpanProcessor>(
81+
new sdktrace::BatchSpanProcessor(std::move(exporter), config.batch_opts));
8282
}
8383
else
8484
{
85-
processor = std::make_shared<sdktrace::SimpleSpanProcessor>(std::move(exporter));
85+
processor = std::unique_ptr<sdktrace::SpanProcessor>(
86+
new sdktrace::SimpleSpanProcessor(std::move(exporter)));
8687
}
8788

8889
// add custom-configured resources
@@ -93,7 +94,7 @@ void initTracer()
9394
}
9495

9596
auto provider = nostd::shared_ptr<opentelemetry::trace::TracerProvider>(
96-
new sdktrace::TracerProvider(processor,
97+
new sdktrace::TracerProvider(std::move(processor),
9798
opentelemetry::sdk::resource::Resource::Create(resAttrs))
9899
);
99100

instrumentation/httpd/tests/01-create-root-span.sh

+6-16
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,12 @@ check_results() {
2828
[ "`getSpanField span_id`" != "`getSpanField parent_span_id`" ] || fail "Bad span: span.id same as parent span.id"
2929

3030
echo Checking span attributes
31-
declare -A SPAN_ATTRS
32-
# transforms "http.method: GET, http.flavor: http, ..." into SPAN_ATTRS[http.method] = GET
33-
IFS=',' read -ra my_array <<< "`getSpanField attributes`"
34-
for i in "${my_array[@]}"; do
35-
TMP_KEY=${i%%:*}
36-
TMP_KEY=${TMP_KEY# }
37-
TMP_VAL=${i##*:}
38-
TMP_VAL=${TMP_VAL:1}
39-
SPAN_ATTRS[${TMP_KEY}]="${TMP_VAL}"
40-
done
41-
42-
[[ "${SPAN_ATTRS[http.method]}" == "GET" ]] || fail "Bad span attribiute http.method ${SPAN_ATTRS[http.method]}"
43-
[[ "${SPAN_ATTRS[http.target]}" == "/" ]] || fail "Bad span attribiute http.target ${SPAN_ATTRS[http.target]}"
44-
[[ "${SPAN_ATTRS[http.status_code]}" == "200" ]] || fail "Bad span attribiute http.status_code ${SPAN_ATTRS[http.status_code]}"
45-
[[ "${SPAN_ATTRS[http.flavor]}" == "1.1" ]] || fail "Bad span attribiute http.flavor ${SPAN_ATTRS[http.flavor]}"
46-
[[ "${SPAN_ATTRS[http.scheme]}" == "http" ]] || fail "Bad span attribiute http.scheme ${SPAN_ATTRS[http.scheme]}"
31+
32+
[[ "`getSpanAttr 'http.method'`" == "GET" ]] || fail "Bad span attribiute http.method ${SPAN_ATTRS[http.method]}"
33+
[[ "`getSpanAttr 'http.target'`" == "/" ]] || fail "Bad span attribiute http.target ${SPAN_ATTRS[http.target]}"
34+
[[ "`getSpanAttr 'http.status_code'`" == "200" ]] || fail "Bad span attribiute http.status_code ${SPAN_ATTRS[http.status_code]}"
35+
[[ "`getSpanAttr 'http.flavor'`" == "1.1" ]] || fail "Bad span attribiute http.flavor ${SPAN_ATTRS[http.flavor]}"
36+
[[ "`getSpanAttr 'http.scheme'`" == "http" ]] || fail "Bad span attribiute http.scheme ${SPAN_ATTRS[http.scheme]}"
4737
}
4838

4939
run $@

instrumentation/httpd/tests/tools.sh

+8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ count() {
4545
echo OK Found $TOTAL occurence\(s\) of "$1"
4646
}
4747

48+
# returns one span attribute
49+
getSpanAttr() {
50+
LINE=`grep "attributes :" ${OUTPUT_SPANS} -A 20 | grep " $1" `
51+
VALUE=`echo $LINE | cut -d ':' -f 2-`
52+
VALUE="${VALUE## }"
53+
echo $VALUE
54+
}
55+
4856
# returns one span field
4957
getSpanField() {
5058
WHICHONE=${2-1}

0 commit comments

Comments
 (0)