From deae4e3c06ef6c1f90096debd5f144ce3540b1c3 Mon Sep 17 00:00:00 2001 From: Tomasz Rojek Date: Tue, 30 Mar 2021 13:41:40 +0200 Subject: [PATCH 01/14] Add codeowners Fixes #9 --- CODEOWNERS | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 000000000..3a3f62a75 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,18 @@ +##################################################### +# +# List of approvers for this repository +# +##################################################### +# +# Learn about membership in OpenTelemetry community: +# https://github.com/open-telemetry/community/blob/main/community-membership.md +# +# Learn about CODEOWNERS file format: +# https://help.github.com/en/articles/about-code-owners + +instrumentation/httpd/ @TomRoSystems +instrumentation/nginx/ @seemk + +* cpp-approvers + +CODEOWNERS cpp-maintainers From d385db853760e300e600825151c1bc4e8bec3ed8 Mon Sep 17 00:00:00 2001 From: Tomasz Rojek Date: Tue, 30 Mar 2021 15:54:37 +0200 Subject: [PATCH 02/14] Fix team names inside codeowners --- CODEOWNERS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index 3a3f62a75..eac737aa7 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -13,6 +13,6 @@ instrumentation/httpd/ @TomRoSystems instrumentation/nginx/ @seemk -* cpp-approvers +* @open-telemetry/cpp-approvers -CODEOWNERS cpp-maintainers +CODEOWNERS @open-telemetry/cpp-maintainers From ea8944c0307fe6300f71e946522c6e30718f23db Mon Sep 17 00:00:00 2001 From: Tomasz Rojek Date: Tue, 20 Apr 2021 12:45:11 +0200 Subject: [PATCH 03/14] Use CODEOWNERS from otel-cpp-contrib --- CODEOWNERS | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS deleted file mode 100644 index eac737aa7..000000000 --- a/CODEOWNERS +++ /dev/null @@ -1,18 +0,0 @@ -##################################################### -# -# List of approvers for this repository -# -##################################################### -# -# Learn about membership in OpenTelemetry community: -# https://github.com/open-telemetry/community/blob/main/community-membership.md -# -# Learn about CODEOWNERS file format: -# https://help.github.com/en/articles/about-code-owners - -instrumentation/httpd/ @TomRoSystems -instrumentation/nginx/ @seemk - -* @open-telemetry/cpp-approvers - -CODEOWNERS @open-telemetry/cpp-maintainers From cede96f380a4e950a52dce48f8364949ac2ade5d Mon Sep 17 00:00:00 2001 From: Tomasz Rojek Date: Tue, 11 May 2021 19:53:20 +0200 Subject: [PATCH 04/14] Update opentelemetry-cpp dependency to revision 5278e8c --- instrumentation/httpd/WORKSPACE | 6 +-- instrumentation/httpd/src/otel/mod_otel.cpp | 45 ++++++++++--------- .../httpd/src/otel/opentelemetry.cpp | 11 ++--- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/instrumentation/httpd/WORKSPACE b/instrumentation/httpd/WORKSPACE index 873ba99a8..5e11dcfce 100644 --- a/instrumentation/httpd/WORKSPACE +++ b/instrumentation/httpd/WORKSPACE @@ -3,10 +3,10 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # Load OpentTelemetry-CPP dependency http_archive( name = "io_opentelemetry_cpp", - sha256 = "2621cb0efd9bae78a1f06866cf8e96417446a6a70568ed6f804a6cb91d916db1", - strip_prefix = "opentelemetry-cpp-bd68a22ff5f2343de68f9d56a68bc53ecd69d567", + sha256 = "9fe9b357a144300c4d388ab5ef4940b43b611cca73a733322dd22b9faa97391a", + strip_prefix = "opentelemetry-cpp-5278e8c03586ee1f690916f3e21eab626914c2e0", urls = [ - "https://github.com/open-telemetry/opentelemetry-cpp/archive/bd68a22ff5f2343de68f9d56a68bc53ecd69d567.tar.gz" + "https://github.com/open-telemetry/opentelemetry-cpp/archive/5278e8c03586ee1f690916f3e21eab626914c2e0.tar.gz" ], ) diff --git a/instrumentation/httpd/src/otel/mod_otel.cpp b/instrumentation/httpd/src/otel/mod_otel.cpp index 5556ff035..2485f336b 100644 --- a/instrumentation/httpd/src/otel/mod_otel.cpp +++ b/instrumentation/httpd/src/otel/mod_otel.cpp @@ -37,24 +37,27 @@ using namespace httpd_otel; const char kOpenTelemetryKeyNote[] = "OTEL"; const char kOpenTelemetryKeyOutboundNote[] = "OTEL_PROXY"; -static nostd::string_view HttpdGetter(const apr_table_t &hdrs, nostd::string_view trace_type) +class HttpdCarrier : public opentelemetry::context::propagation::TextMapCarrier { - auto fnd = apr_table_get(&hdrs, std::string(trace_type).c_str()); - return fnd ? fnd : ""; -} - -static void HttpdSetter(apr_table_t &hdrs, - nostd::string_view trace_type, - nostd::string_view trace_description) -{ - apr_table_set(&hdrs, std::string(trace_type).c_str(), - std::string(trace_description).c_str()); -} +public: + apr_table_t& hdrs; + HttpdCarrier(apr_table_t& headers):hdrs(headers){} + virtual nostd::string_view Get(nostd::string_view key) const noexcept override + { + auto fnd = apr_table_get(&hdrs, std::string(key).c_str()); + return fnd ? fnd : ""; + } + virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + { + apr_table_set(&hdrs, std::string(key).c_str(), + std::string(value).c_str()); + } +}; // propagators -opentelemetry::trace::propagation::HttpTraceContext PropagatorTraceContext; -opentelemetry::trace::propagation::B3Propagator PropagatorB3SingleHeader; -opentelemetry::trace::propagation::B3PropagatorMultiHeader PropagatorB3MultiHeader; +opentelemetry::trace::propagation::HttpTraceContext PropagatorTraceContext; +opentelemetry::trace::propagation::B3Propagator PropagatorB3SingleHeader; +opentelemetry::trace::propagation::B3PropagatorMultiHeader PropagatorB3MultiHeader; // from: // 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 */ ) if (!config.ignore_inbound && config.propagation != OtelPropagation::NONE) { + HttpdCarrier car(*req->headers_in); opentelemetry::v0::context::Context ctx_new, ctx_cur = opentelemetry::context::RuntimeContext::GetCurrent(); switch (config.propagation) { default: - ctx_new = PropagatorTraceContext.Extract(HttpdGetter, *req->headers_in, ctx_cur); + ctx_new = PropagatorTraceContext.Extract(car, ctx_cur); break; case OtelPropagation::B3_SINGLE_HEADER: case OtelPropagation::B3_MULTI_HEADER: - ctx_new = PropagatorB3SingleHeader.Extract(HttpdGetter, *req->headers_in, ctx_cur); + ctx_new = PropagatorB3SingleHeader.Extract(car, ctx_cur); } req_data->token = opentelemetry::context::RuntimeContext::Attach(ctx_new); } @@ -221,16 +225,17 @@ static int proxy_fixup_handler(request_rec *r) // mod_proxy simply copies request headers from client therefore inject is into headers_in // instead of headers_out + HttpdCarrier car(*req->headers_in); switch (config.propagation) { case OtelPropagation::TRACE_CONTEXT: - PropagatorTraceContext.Inject(HttpdSetter, *req->headers_in, opentelemetry::context::RuntimeContext::GetCurrent()); + PropagatorTraceContext.Inject(car, opentelemetry::context::RuntimeContext::GetCurrent()); break; case OtelPropagation::B3_SINGLE_HEADER: - PropagatorB3SingleHeader.Inject(HttpdSetter, *req->headers_in, opentelemetry::context::RuntimeContext::GetCurrent()); + PropagatorB3SingleHeader.Inject(car, opentelemetry::context::RuntimeContext::GetCurrent()); break; case OtelPropagation::B3_MULTI_HEADER: - PropagatorB3MultiHeader.Inject(HttpdSetter, *req->headers_in, opentelemetry::context::RuntimeContext::GetCurrent()); + PropagatorB3MultiHeader.Inject(car, opentelemetry::context::RuntimeContext::GetCurrent()); break; default: // suppress warning break; diff --git a/instrumentation/httpd/src/otel/opentelemetry.cpp b/instrumentation/httpd/src/otel/opentelemetry.cpp index 2aae4a1e8..ec9ca635c 100644 --- a/instrumentation/httpd/src/otel/opentelemetry.cpp +++ b/instrumentation/httpd/src/otel/opentelemetry.cpp @@ -73,16 +73,17 @@ void initTracer() break; } - std::shared_ptr processor; + std::unique_ptr processor; if (config.batch_opts.max_queue_size) { - processor = std::make_shared( - std::move(exporter), config.batch_opts); + processor = std::unique_ptr( + new sdktrace::BatchSpanProcessor(std::move(exporter), config.batch_opts)); } else { - processor = std::make_shared(std::move(exporter)); + processor = std::unique_ptr( + new sdktrace::SimpleSpanProcessor(std::move(exporter))); } // add custom-configured resources @@ -93,7 +94,7 @@ void initTracer() } auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(processor, + new sdktrace::TracerProvider(std::move(processor), opentelemetry::sdk::resource::Resource::Create(resAttrs)) ); From 03acc95f81506d17e5a1537bc322c5040df2d42c Mon Sep 17 00:00:00 2001 From: Tomasz Rojek Date: Wed, 12 May 2021 17:15:36 +0200 Subject: [PATCH 05/14] Fix tests to match how attributes are presented (it was broken by #632 commit 179a7f40) --- instrumentation/httpd/WORKSPACE | 6 ++--- .../httpd/tests/01-create-root-span.sh | 22 +++++-------------- instrumentation/httpd/tests/tools.sh | 9 ++++++++ 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/instrumentation/httpd/WORKSPACE b/instrumentation/httpd/WORKSPACE index 5e11dcfce..56dcf663d 100644 --- a/instrumentation/httpd/WORKSPACE +++ b/instrumentation/httpd/WORKSPACE @@ -3,10 +3,10 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # Load OpentTelemetry-CPP dependency http_archive( name = "io_opentelemetry_cpp", - sha256 = "9fe9b357a144300c4d388ab5ef4940b43b611cca73a733322dd22b9faa97391a", - strip_prefix = "opentelemetry-cpp-5278e8c03586ee1f690916f3e21eab626914c2e0", + sha256 = "59e16eab4f534907144882fe70a1ca4514cf720f7b8b6e2a2d999a1b1a9265c8", + strip_prefix = "opentelemetry-cpp-b4584adeaae259df89b33af884c641e70a60a7cf", urls = [ - "https://github.com/open-telemetry/opentelemetry-cpp/archive/5278e8c03586ee1f690916f3e21eab626914c2e0.tar.gz" + "https://github.com/open-telemetry/opentelemetry-cpp/archive/b4584adeaae259df89b33af884c641e70a60a7cf.tar.gz" ], ) diff --git a/instrumentation/httpd/tests/01-create-root-span.sh b/instrumentation/httpd/tests/01-create-root-span.sh index c67cb1524..2d4d0c8a3 100755 --- a/instrumentation/httpd/tests/01-create-root-span.sh +++ b/instrumentation/httpd/tests/01-create-root-span.sh @@ -28,22 +28,12 @@ check_results() { [ "`getSpanField span_id`" != "`getSpanField parent_span_id`" ] || fail "Bad span: span.id same as parent span.id" echo Checking span attributes - declare -A SPAN_ATTRS - # transforms "http.method: GET, http.flavor: http, ..." into SPAN_ATTRS[http.method] = GET - IFS=',' read -ra my_array <<< "`getSpanField attributes`" - for i in "${my_array[@]}"; do - TMP_KEY=${i%%:*} - TMP_KEY=${TMP_KEY# } - TMP_VAL=${i##*:} - TMP_VAL=${TMP_VAL:1} - SPAN_ATTRS[${TMP_KEY}]="${TMP_VAL}" - done - - [[ "${SPAN_ATTRS[http.method]}" == "GET" ]] || fail "Bad span attribiute http.method ${SPAN_ATTRS[http.method]}" - [[ "${SPAN_ATTRS[http.target]}" == "/" ]] || fail "Bad span attribiute http.target ${SPAN_ATTRS[http.target]}" - [[ "${SPAN_ATTRS[http.status_code]}" == "200" ]] || fail "Bad span attribiute http.status_code ${SPAN_ATTRS[http.status_code]}" - [[ "${SPAN_ATTRS[http.flavor]}" == "1.1" ]] || fail "Bad span attribiute http.flavor ${SPAN_ATTRS[http.flavor]}" - [[ "${SPAN_ATTRS[http.scheme]}" == "http" ]] || fail "Bad span attribiute http.scheme ${SPAN_ATTRS[http.scheme]}" + + [[ "`getSpanAttr 'http.method'`" == "GET" ]] || fail "Bad span attribiute http.method ${SPAN_ATTRS[http.method]}" + [[ "`getSpanAttr 'http.target'`" == "/" ]] || fail "Bad span attribiute http.target ${SPAN_ATTRS[http.target]}" + [[ "`getSpanAttr 'http.status_code'`" == "200" ]] || fail "Bad span attribiute http.status_code ${SPAN_ATTRS[http.status_code]}" + [[ "`getSpanAttr 'http.flavor'`" == "1.1" ]] || fail "Bad span attribiute http.flavor ${SPAN_ATTRS[http.flavor]}" + [[ "`getSpanAttr 'http.scheme'`" == "http" ]] || fail "Bad span attribiute http.scheme ${SPAN_ATTRS[http.scheme]}" } run $@ diff --git a/instrumentation/httpd/tests/tools.sh b/instrumentation/httpd/tests/tools.sh index 77e95f4a0..6e2800686 100755 --- a/instrumentation/httpd/tests/tools.sh +++ b/instrumentation/httpd/tests/tools.sh @@ -45,6 +45,15 @@ count() { echo OK Found $TOTAL occurence\(s\) of "$1" } +# returns span attribute +getSpanAttr() { +# grep "attributes :" ${OUTPUT_SPANS} -A 20 + LINE=`grep "attributes :" ${OUTPUT_SPANS} -A 20 | grep " $1" ` + VALUE=`echo $LINE | cut -d ':' -f 2-` + VALUE="${VALUE## }" + echo $VALUE +} + # returns one span field getSpanField() { WHICHONE=${2-1} From d546aed8f6e7a30e4afc2e728769ec5f8d0382b4 Mon Sep 17 00:00:00 2001 From: Tomasz Rojek Date: Wed, 12 May 2021 17:51:48 +0200 Subject: [PATCH 06/14] Remove commented code --- instrumentation/httpd/tests/tools.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/instrumentation/httpd/tests/tools.sh b/instrumentation/httpd/tests/tools.sh index 6e2800686..39a715e9e 100755 --- a/instrumentation/httpd/tests/tools.sh +++ b/instrumentation/httpd/tests/tools.sh @@ -45,9 +45,8 @@ count() { echo OK Found $TOTAL occurence\(s\) of "$1" } -# returns span attribute +# returns one span attribute getSpanAttr() { -# grep "attributes :" ${OUTPUT_SPANS} -A 20 LINE=`grep "attributes :" ${OUTPUT_SPANS} -A 20 | grep " $1" ` VALUE=`echo $LINE | cut -d ':' -f 2-` VALUE="${VALUE## }" From ea9b377801a5de09a95bcbcb348101b483c7c87e Mon Sep 17 00:00:00 2001 From: Tomasz Rojek Date: Tue, 1 Jun 2021 16:58:56 +0200 Subject: [PATCH 07/14] Add support for CMake build alongside with Bazel --- instrumentation/httpd/CMakeLists.txt | 38 ++++++ instrumentation/httpd/Dockerfile.cmake | 124 ++++++++++++++++++ instrumentation/httpd/Makefile | 31 +++-- instrumentation/httpd/src/otel/mod_otel.cpp | 4 +- .../httpd/src/otel/opentelemetry.cpp | 26 ++-- .../httpd/src/otel/opentelemetry.h | 13 +- 6 files changed, 207 insertions(+), 29 deletions(-) create mode 100644 instrumentation/httpd/CMakeLists.txt create mode 100644 instrumentation/httpd/Dockerfile.cmake diff --git a/instrumentation/httpd/CMakeLists.txt b/instrumentation/httpd/CMakeLists.txt new file mode 100644 index 000000000..74763dd97 --- /dev/null +++ b/instrumentation/httpd/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.12) + +project(opentelemetry-httpd) + +find_package(opentelemetry-cpp REQUIRED) +find_package(Threads REQUIRED) +find_package(protobuf REQUIRED) +find_package(gRPC REQUIRED) +find_package(CURL REQUIRED) + +add_library(otel_httpd_module SHARED + src/otel/mod_otel.cpp + src/otel/opentelemetry.cpp +) + +target_compile_options(otel_httpd_module + PRIVATE -Wall -Wextra -fpermissive +) + +install(TARGETS otel_httpd_module DESTINATION ".") + +set_target_properties(otel_httpd_module PROPERTIES + PREFIX "" +) + +target_include_directories(otel_httpd_module + PRIVATE + ${OPENTELEMETRY_CPP_INCLUDE_DIRS} + "/usr/include/apache2" + "/usr/include/apr-1.0" +) + +target_link_libraries(otel_httpd_module + PRIVATE + ${OPENTELEMETRY_CPP_LIBRARIES} + gRPC::grpc++ +# Thrift::thrift +) diff --git a/instrumentation/httpd/Dockerfile.cmake b/instrumentation/httpd/Dockerfile.cmake new file mode 100644 index 000000000..d7e6b56cf --- /dev/null +++ b/instrumentation/httpd/Dockerfile.cmake @@ -0,0 +1,124 @@ +FROM ubuntu:18.04 + +######################################### +# copy setup stuff from opentelemetry-cpp +######################################### + +WORKDIR /setup-ci + +ADD setup-buildtools.sh /setup-ci/setup-buildtools.sh + +RUN /setup-ci/setup-buildtools.sh + +######################################### +# compile Apache thrift +######################################### + +# WORKDIR /root +# COPY install-thrift.sh . +# RUN ./install-thrift.sh + +######################### +# now build plugin itself +######################### + +ADD setup-environment.sh /setup/setup-environment.sh + +RUN /setup/setup-environment.sh + +COPY src /root/src +COPY .clang-format /root +COPY tools /root/tools + +WORKDIR /root +COPY create-otel-load.sh /root +# COPY build.sh /root +COPY opentelemetry.conf /root +COPY httpd_install_otel.sh /root +# RUN /root/build.sh + +# TODO: check apache configuration (apachectl configtest) + +# TODO: run tests? + + +RUN apt-get update \ +&& DEBIAN_FRONTEND=noninteractive TZ="Europe/London" \ + apt-get install --no-install-recommends --no-install-suggests -y \ + build-essential autoconf libtool pkg-config ca-certificates gcc g++ git libcurl4-openssl-dev libpcre3-dev gnupg2 lsb-release curl apt-transport-https software-properties-common zlib1g-dev +RUN curl -o /etc/apt/trusted.gpg.d/kitware.asc https://apt.kitware.com/keys/kitware-archive-latest.asc \ + && apt-add-repository "deb https://apt.kitware.com/ubuntu/ `lsb_release -cs` main" +RUN curl -o /etc/apt/trusted.gpg.d/nginx_signing.asc https://nginx.org/keys/nginx_signing.key \ + && apt-add-repository "deb http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \ + && /bin/bash -c 'echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900"' | tee /etc/apt/preferences.d/99nginx +RUN apt-get update \ +&& DEBIAN_FRONTEND=noninteractive TZ="Europe/London" \ + apt-get install --no-install-recommends --no-install-suggests -y \ + cmake libboost-all-dev +RUN git clone --shallow-submodules --depth 1 --recurse-submodules -b v1.36.4 \ + https://github.com/grpc/grpc \ + && cd grpc \ + && mkdir -p cmake/build \ + && cd cmake/build \ + && cmake \ + -DgRPC_INSTALL=ON \ + -DgRPC_BUILD_TESTS=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF \ + ../.. \ + && make -j2 \ + && make install + +RUN wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz \ + && tar zxf libevent-2.1.12-stable.tar.gz \ + && cd libevent-2.1.12-stable \ + && mkdir -p build \ + && cd build \ + && cmake .. \ + && make -j2 \ + && make install + +RUN git clone --shallow-submodules --depth 1 --recurse-submodules -b v0.14.0 \ + https://github.com/apache/thrift.git \ + && cd thrift \ + && mkdir -p cmake-build \ + && cd cmake-build \ + && cmake -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_TESTING=OFF \ + -DBUILD_COMPILER=OFF \ + -DBUILD_C_GLIB=OFF \ + -DBUILD_JAVA=OFF \ + -DBUILD_JAVASCRIPT=OFF \ + -DBUILD_NODEJS=OFF \ + -DBUILD_PYTHON=OFF \ + .. \ + && make -j2 \ + && make install + +# RUN git clone --shallow-submodules --depth 1 --recurse-submodules -b v0.7.0 + RUN git clone --shallow-submodules --depth 1 --recurse-submodules \ + https://github.com/open-telemetry/opentelemetry-cpp.git \ + && cd opentelemetry-cpp \ + && mkdir build \ + && cd build \ + && cmake -DCMAKE_BUILD_TYPE=Release \ + -DWITH_OTLP=ON \ + -DWITH_JAEGER=ON \ + -DBUILD_TESTING=OFF \ + -DWITH_EXAMPLES=OFF \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + .. \ + && make -j2 \ + && make install + +# now just build module itself +COPY CMakeLists.txt . +RUN mkdir -p build \ + && cd build \ + && cmake .. \ + && make -j2 diff --git a/instrumentation/httpd/Makefile b/instrumentation/httpd/Makefile index d5407a615..d909123b6 100644 --- a/instrumentation/httpd/Makefile +++ b/instrumentation/httpd/Makefile @@ -1,7 +1,9 @@ -BUILD_IMAGE=opentelemetry-httpd-mod-dev +BUILD_IMAGE_BZL=opentelemetry-httpd-mod-dev +BUILD_IMAGE_CMAKE=opentelemetry-httpd-mod-dev-cmake CONTAINER_NAME=otel-httpd +CONTAINER_NAME_CMAKE=otel-httpd-cmake .PHONY: help build clean devsh rmcnt rming start stop @@ -11,22 +13,28 @@ help: @echo Possible targets are: @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' -build: ## build docker image with development tools - docker build -t $(BUILD_IMAGE) . +build-bazel: ## build docker image with development tools + docker build -t $(BUILD_IMAGE_BZL) . -start: build ## start new docker container - docker run -v "$(PWD)/src":/mnt/host --network host --privileged --name "$(CONTAINER_NAME)" -it $(BUILD_IMAGE) /bin/bash -l +build-cmake: ## build docker image with development tools (cmake version) + docker build -t $(BUILD_IMAGE_CMAKE) -f Dockerfile.cmake . -startifnotrunning: +start-bazel: build-bazel ## start new docker container + docker run -v "$(PWD)/src":/mnt/host --network host --privileged --name "$(CONTAINER_NAME)" -it $(BUILD_IMAGE_BZL) /bin/bash -l +start-cmake: build-cmake ## start new docker container (cmake version) + docker run -v "$(PWD)/src":/mnt/host --network host --privileged --name "$(CONTAINER_NAME_CMAKE)" -it $(BUILD_IMAGE_CMAKE) /bin/bash -l -# stop: ## stop docker image +start: start-bazel rmcnt: ## remove docker container docker container rm $(CONTAINER_NAME) || true +rmcnt-cmake: ## remove docker container (cmake version) + docker container rm $(CONTAINER_NAME_CMAKE) || true + rmimg: ## remove docker image - docker image rm $(BUILD_IMAGE) + docker image rm $(BUILD_IMAGE_BZL) clean: rmcnt rmimg ## clean both docker container and image @@ -36,3 +44,10 @@ devsh: ## attach to existing container with shell (developer shell) else \ $(MAKE) start; \ fi; + +devsh-cmake: ## attach to existing container with shell (developer shell, cmake) + if [ "docker container inspect (CONTAINER_NAME_CMAKE)" ]; then \ + docker exec -it $(CONTAINER_NAME_CMAKE) bash; \ + else \ + $(MAKE) start; \ + fi; diff --git a/instrumentation/httpd/src/otel/mod_otel.cpp b/instrumentation/httpd/src/otel/mod_otel.cpp index 2485f336b..b1c5586b9 100644 --- a/instrumentation/httpd/src/otel/mod_otel.cpp +++ b/instrumentation/httpd/src/otel/mod_otel.cpp @@ -42,12 +42,12 @@ class HttpdCarrier : public opentelemetry::context::propagation::TextMapCarrier public: apr_table_t& hdrs; HttpdCarrier(apr_table_t& headers):hdrs(headers){} - virtual nostd::string_view Get(nostd::string_view key) const noexcept override + virtual opentelemetry::v0::nostd::string_view Get(opentelemetry::v0::nostd::string_view key) const noexcept override { auto fnd = apr_table_get(&hdrs, std::string(key).c_str()); return fnd ? fnd : ""; } - virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + virtual void Set(opentelemetry::v0::nostd::string_view key, opentelemetry::v0::nostd::string_view value) noexcept override { apr_table_set(&hdrs, std::string(key).c_str(), std::string(value).c_str()); diff --git a/instrumentation/httpd/src/otel/opentelemetry.cpp b/instrumentation/httpd/src/otel/opentelemetry.cpp index ec9ca635c..6f2257dbd 100644 --- a/instrumentation/httpd/src/otel/opentelemetry.cpp +++ b/instrumentation/httpd/src/otel/opentelemetry.cpp @@ -30,17 +30,17 @@ namespace httpd_otel { // TODO: use semantic conventions https://github.com/open-telemetry/opentelemetry-cpp/issues/566 -const nostd::string_view kAttrHTTPServerName = "http.server_name"; -const nostd::string_view kAttrHTTPMethod = "http.method"; -const nostd::string_view kAttrHTTPScheme = "http.scheme"; -const nostd::string_view kAttrHTTPHost = "http.host"; -const nostd::string_view kAttrHTTPTarget = "http.target"; -const nostd::string_view kAttrHTTPUrl = "http.url"; -const nostd::string_view kAttrHTTPFlavor = "http.flavor"; -const nostd::string_view kAttrHTTPClientIP = "http.client_ip"; -const nostd::string_view kAttrNETPeerIP = "net.peer.ip"; -const nostd::string_view kAttrHTTPStatusCode = "http.status_code"; -const nostd::string_view kAttrHTTPResponseContentLen = "http.response_content_length"; +const opentelemetry::v0::nostd::string_view kAttrHTTPServerName = "http.server_name"; +const opentelemetry::v0::nostd::string_view kAttrHTTPMethod = "http.method"; +const opentelemetry::v0::nostd::string_view kAttrHTTPScheme = "http.scheme"; +const opentelemetry::v0::nostd::string_view kAttrHTTPHost = "http.host"; +const opentelemetry::v0::nostd::string_view kAttrHTTPTarget = "http.target"; +const opentelemetry::v0::nostd::string_view kAttrHTTPUrl = "http.url"; +const opentelemetry::v0::nostd::string_view kAttrHTTPFlavor = "http.flavor"; +const opentelemetry::v0::nostd::string_view kAttrHTTPClientIP = "http.client_ip"; +const opentelemetry::v0::nostd::string_view kAttrNETPeerIP = "net.peer.ip"; +const opentelemetry::v0::nostd::string_view kAttrHTTPStatusCode = "http.status_code"; +const opentelemetry::v0::nostd::string_view kAttrHTTPResponseContentLen = "http.response_content_length"; OtelConfig config; @@ -93,7 +93,7 @@ void initTracer() resAttrs[it.first] = it.second; } - auto provider = nostd::shared_ptr( + auto provider = opentelemetry::v0::nostd::shared_ptr( new sdktrace::TracerProvider(std::move(processor), opentelemetry::sdk::resource::Resource::Create(resAttrs)) ); @@ -102,7 +102,7 @@ void initTracer() opentelemetry::trace::Provider::SetTracerProvider(provider); } -nostd::shared_ptr get_tracer() +opentelemetry::v0::nostd::shared_ptr get_tracer() { auto provider = opentelemetry::trace::Provider::GetTracerProvider(); return provider->GetTracer(KHTTPDOTelTracerName); diff --git a/instrumentation/httpd/src/otel/opentelemetry.h b/instrumentation/httpd/src/otel/opentelemetry.h index 8b5c59b59..f9f933992 100644 --- a/instrumentation/httpd/src/otel/opentelemetry.h +++ b/instrumentation/httpd/src/otel/opentelemetry.h @@ -20,14 +20,15 @@ #include #include -#include "opentelemetry/exporters/ostream/span_exporter.h" -#include "opentelemetry/sdk/trace/batch_span_processor.h" +#include #include "opentelemetry/trace/provider.h" +#include +#include namespace httpd_otel { -const nostd::string_view KHTTPDOTelTracerName = "httpd"; +const opentelemetry::nostd::string_view KHTTPDOTelTracerName = "httpd"; enum class OtelExporterType { @@ -85,8 +86,8 @@ struct HttpdEndSpanAttributes // to be called explictly inside Destruct method struct ExtraRequestData { // context which we pass - nostd::unique_ptr token; - nostd::shared_ptr span; + opentelemetry::v0::nostd::unique_ptr token; + opentelemetry::v0::nostd::shared_ptr span; HttpdStartSpanAttributes startAttrs; HttpdEndSpanAttributes endAttrs; // Sets attributes for HTTP request. @@ -113,7 +114,7 @@ struct ExtraRequestData // Initializes OpenTelemetry module. void initTracer(); // Returns default (global) tracer. -nostd::shared_ptr get_tracer(); +opentelemetry::v0::nostd::shared_ptr get_tracer(); } // namespace httpd_otel From a11b82db9c6f048ea3d02d372c291a5e6910f256 Mon Sep 17 00:00:00 2001 From: Tomasz Rojek Date: Tue, 1 Jun 2021 21:22:09 +0200 Subject: [PATCH 08/14] Fix style and add CI for CMake --- .github/workflows/httpd.yml | 23 ++++ instrumentation/httpd/CMakeLists.txt | 1 + instrumentation/httpd/Dockerfile.cmake | 109 ++---------------- instrumentation/httpd/setup-cmake.sh | 75 ++++++++++++ .../httpd/src/otel/opentelemetry.h | 4 +- 5 files changed, 112 insertions(+), 100 deletions(-) create mode 100755 instrumentation/httpd/setup-cmake.sh diff --git a/.github/workflows/httpd.yml b/.github/workflows/httpd.yml index d446c10d9..dc6deb4a3 100644 --- a/.github/workflows/httpd.yml +++ b/.github/workflows/httpd.yml @@ -37,6 +37,29 @@ jobs: name: ${{ matrix.os }}_mod-otel.so path: /tmp/mod-otel.so + build_cmake: + name: Build module with CMake + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-18.04, ubuntu-20.04] + steps: + - name: Checkout Repo + uses: actions/checkout@v2 + - name: Setup buildtools + run: | + sudo ./instrumentation/httpd/setup-buildtools.sh + sudo ./instrumentation/httpd/setup-environment.sh + - name: Compile prerequisites + run: | + cd instrumentation/httpd && ./setup-cmake.sh + run: | + cd instrumentation/httpd + mkdir -p build + cd build + cmake .. + clang_format: name: Check code formatting runs-on: ubuntu-latest diff --git a/instrumentation/httpd/CMakeLists.txt b/instrumentation/httpd/CMakeLists.txt index 74763dd97..dfb92c7d4 100644 --- a/instrumentation/httpd/CMakeLists.txt +++ b/instrumentation/httpd/CMakeLists.txt @@ -7,6 +7,7 @@ find_package(Threads REQUIRED) find_package(protobuf REQUIRED) find_package(gRPC REQUIRED) find_package(CURL REQUIRED) +find_package(Thrift REQUIRED) add_library(otel_httpd_module SHARED src/otel/mod_otel.cpp diff --git a/instrumentation/httpd/Dockerfile.cmake b/instrumentation/httpd/Dockerfile.cmake index d7e6b56cf..fc5a9d80a 100644 --- a/instrumentation/httpd/Dockerfile.cmake +++ b/instrumentation/httpd/Dockerfile.cmake @@ -10,115 +10,28 @@ ADD setup-buildtools.sh /setup-ci/setup-buildtools.sh RUN /setup-ci/setup-buildtools.sh -######################################### -# compile Apache thrift -######################################### - -# WORKDIR /root -# COPY install-thrift.sh . -# RUN ./install-thrift.sh - -######################### -# now build plugin itself -######################### - ADD setup-environment.sh /setup/setup-environment.sh RUN /setup/setup-environment.sh -COPY src /root/src COPY .clang-format /root -COPY tools /root/tools WORKDIR /root -COPY create-otel-load.sh /root -# COPY build.sh /root -COPY opentelemetry.conf /root -COPY httpd_install_otel.sh /root -# RUN /root/build.sh - -# TODO: check apache configuration (apachectl configtest) -# TODO: run tests? +# build with CMake +COPY setup-cmake.sh . +# RUN ls +RUN /root/setup-cmake.sh +COPY CMakeLists.txt /root +COPY src /root/src -RUN apt-get update \ -&& DEBIAN_FRONTEND=noninteractive TZ="Europe/London" \ - apt-get install --no-install-recommends --no-install-suggests -y \ - build-essential autoconf libtool pkg-config ca-certificates gcc g++ git libcurl4-openssl-dev libpcre3-dev gnupg2 lsb-release curl apt-transport-https software-properties-common zlib1g-dev -RUN curl -o /etc/apt/trusted.gpg.d/kitware.asc https://apt.kitware.com/keys/kitware-archive-latest.asc \ - && apt-add-repository "deb https://apt.kitware.com/ubuntu/ `lsb_release -cs` main" -RUN curl -o /etc/apt/trusted.gpg.d/nginx_signing.asc https://nginx.org/keys/nginx_signing.key \ - && apt-add-repository "deb http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \ - && /bin/bash -c 'echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900"' | tee /etc/apt/preferences.d/99nginx -RUN apt-get update \ -&& DEBIAN_FRONTEND=noninteractive TZ="Europe/London" \ - apt-get install --no-install-recommends --no-install-suggests -y \ - cmake libboost-all-dev -RUN git clone --shallow-submodules --depth 1 --recurse-submodules -b v1.36.4 \ - https://github.com/grpc/grpc \ - && cd grpc \ - && mkdir -p cmake/build \ - && cd cmake/build \ - && cmake \ - -DgRPC_INSTALL=ON \ - -DgRPC_BUILD_TESTS=OFF \ - -DCMAKE_BUILD_TYPE=Release \ - -DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF \ - -DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF \ - -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \ - -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \ - -DgRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF \ - -DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF \ - ../.. \ - && make -j2 \ - && make install - -RUN wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz \ - && tar zxf libevent-2.1.12-stable.tar.gz \ - && cd libevent-2.1.12-stable \ - && mkdir -p build \ - && cd build \ - && cmake .. \ - && make -j2 \ - && make install - -RUN git clone --shallow-submodules --depth 1 --recurse-submodules -b v0.14.0 \ - https://github.com/apache/thrift.git \ - && cd thrift \ - && mkdir -p cmake-build \ - && cd cmake-build \ - && cmake -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_TESTING=OFF \ - -DBUILD_COMPILER=OFF \ - -DBUILD_C_GLIB=OFF \ - -DBUILD_JAVA=OFF \ - -DBUILD_JAVASCRIPT=OFF \ - -DBUILD_NODEJS=OFF \ - -DBUILD_PYTHON=OFF \ - .. \ - && make -j2 \ - && make install - -# RUN git clone --shallow-submodules --depth 1 --recurse-submodules -b v0.7.0 - RUN git clone --shallow-submodules --depth 1 --recurse-submodules \ - https://github.com/open-telemetry/opentelemetry-cpp.git \ - && cd opentelemetry-cpp \ - && mkdir build \ - && cd build \ - && cmake -DCMAKE_BUILD_TYPE=Release \ - -DWITH_OTLP=ON \ - -DWITH_JAEGER=ON \ - -DBUILD_TESTING=OFF \ - -DWITH_EXAMPLES=OFF \ - -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ - .. \ - && make -j2 \ - && make install - -# now just build module itself -COPY CMakeLists.txt . RUN mkdir -p build \ && cd build \ && cmake .. \ && make -j2 + +COPY tools /root/tools +COPY create-otel-load.sh /root +COPY opentelemetry.conf /root +COPY httpd_install_otel.sh /root diff --git a/instrumentation/httpd/setup-cmake.sh b/instrumentation/httpd/setup-cmake.sh new file mode 100755 index 000000000..1389aff93 --- /dev/null +++ b/instrumentation/httpd/setup-cmake.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +set -euxo pipefail + +export DEBIAN_FRONTEND=noninteractive + +apt-get update + +apt-get install --no-install-recommends --no-install-suggests -y \ + build-essential autoconf libtool pkg-config ca-certificates gcc g++ git libcurl4-openssl-dev libpcre3-dev gnupg2 lsb-release curl apt-transport-https software-properties-common zlib1g-dev +curl -o /etc/apt/trusted.gpg.d/kitware.asc https://apt.kitware.com/keys/kitware-archive-latest.asc \ + && apt-add-repository "deb https://apt.kitware.com/ubuntu/ `lsb_release -cs` main" + +apt-get install --no-install-recommends --no-install-suggests -y \ +cmake libboost-all-dev + +git clone --shallow-submodules --depth 1 --recurse-submodules -b v1.36.4 \ + https://github.com/grpc/grpc \ + && cd grpc \ + && mkdir -p cmake/build \ + && cd cmake/build \ + && cmake \ + -DgRPC_INSTALL=ON \ + -DgRPC_BUILD_TESTS=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF \ + ../.. \ + && make -j2 \ + && make install + +wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz \ + && tar zxf libevent-2.1.12-stable.tar.gz \ + && cd libevent-2.1.12-stable \ + && mkdir -p build \ + && cd build \ + && cmake .. \ + && make -j2 \ + && make install + +git clone --shallow-submodules --depth 1 --recurse-submodules -b v0.14.0 \ + https://github.com/apache/thrift.git \ + && cd thrift \ + && mkdir -p cmake-build \ + && cd cmake-build \ + && cmake -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_TESTING=OFF \ + -DBUILD_COMPILER=OFF \ + -DBUILD_C_GLIB=OFF \ + -DBUILD_JAVA=OFF \ + -DBUILD_JAVASCRIPT=OFF \ + -DBUILD_NODEJS=OFF \ + -DBUILD_PYTHON=OFF \ + .. \ + && make -j2 \ + && make install + +git clone --shallow-submodules --depth 1 --recurse-submodules \ + https://github.com/open-telemetry/opentelemetry-cpp.git \ + && cd opentelemetry-cpp \ + && mkdir build \ + && cd build \ + && cmake -DCMAKE_BUILD_TYPE=Release \ + -DWITH_OTLP=ON \ + -DWITH_JAEGER=ON \ + -DBUILD_TESTING=OFF \ + -DWITH_EXAMPLES=OFF \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + .. \ + && make -j2 \ + && make install diff --git a/instrumentation/httpd/src/otel/opentelemetry.h b/instrumentation/httpd/src/otel/opentelemetry.h index f9f933992..f8d87f17f 100644 --- a/instrumentation/httpd/src/otel/opentelemetry.h +++ b/instrumentation/httpd/src/otel/opentelemetry.h @@ -20,10 +20,10 @@ #include #include +#include +#include #include #include "opentelemetry/trace/provider.h" -#include -#include namespace httpd_otel { From adac5409cd7f5810e73e1fe417ea20588897de56 Mon Sep 17 00:00:00 2001 From: Tomasz Rojek Date: Tue, 1 Jun 2021 21:24:25 +0200 Subject: [PATCH 09/14] Add missing name to CI --- .github/workflows/httpd.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/httpd.yml b/.github/workflows/httpd.yml index dc6deb4a3..dc8a9e6be 100644 --- a/.github/workflows/httpd.yml +++ b/.github/workflows/httpd.yml @@ -54,6 +54,7 @@ jobs: - name: Compile prerequisites run: | cd instrumentation/httpd && ./setup-cmake.sh + - name: Compile run: | cd instrumentation/httpd mkdir -p build From 2170af8972acdf8f27d4cac3722b5f05bf82313e Mon Sep 17 00:00:00 2001 From: Tomasz Rojek Date: Tue, 1 Jun 2021 21:29:58 +0200 Subject: [PATCH 10/14] Fix CI --- .github/workflows/httpd.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/httpd.yml b/.github/workflows/httpd.yml index dc8a9e6be..f0536ea64 100644 --- a/.github/workflows/httpd.yml +++ b/.github/workflows/httpd.yml @@ -53,13 +53,15 @@ jobs: sudo ./instrumentation/httpd/setup-environment.sh - name: Compile prerequisites run: | - cd instrumentation/httpd && ./setup-cmake.sh + cd instrumentation/httpd + sudo ./setup-cmake.sh - name: Compile run: | cd instrumentation/httpd mkdir -p build cd build cmake .. + make -j2 clang_format: name: Check code formatting From cc98cb91026eb7b3d9d6097ad6e5409abcbb6975 Mon Sep 17 00:00:00 2001 From: Tomasz Rojek Date: Thu, 10 Jun 2021 13:13:21 +0200 Subject: [PATCH 11/14] Get rid of -fpermissive and remove some compilation warnings --- instrumentation/httpd/CMakeLists.txt | 2 +- instrumentation/httpd/src/otel/BUILD | 1 - instrumentation/httpd/src/otel/mod_otel.cpp | 32 +++++++++---------- .../httpd/src/otel/opentelemetry.cpp | 22 ++++++------- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/instrumentation/httpd/CMakeLists.txt b/instrumentation/httpd/CMakeLists.txt index dfb92c7d4..ededdb915 100644 --- a/instrumentation/httpd/CMakeLists.txt +++ b/instrumentation/httpd/CMakeLists.txt @@ -15,7 +15,7 @@ add_library(otel_httpd_module SHARED ) target_compile_options(otel_httpd_module - PRIVATE -Wall -Wextra -fpermissive + PRIVATE -Wall -Wextra ) install(TARGETS otel_httpd_module DESTINATION ".") diff --git a/instrumentation/httpd/src/otel/BUILD b/instrumentation/httpd/src/otel/BUILD index 8251b73d9..044cb1745 100644 --- a/instrumentation/httpd/src/otel/BUILD +++ b/instrumentation/httpd/src/otel/BUILD @@ -9,7 +9,6 @@ cc_library( copts = [ "-I/usr/include/apache2", "-I/usr/include/apr-1.0", - "-fpermissive", ], deps = [ "@io_opentelemetry_cpp//api", diff --git a/instrumentation/httpd/src/otel/mod_otel.cpp b/instrumentation/httpd/src/otel/mod_otel.cpp index b1c5586b9..829b51664 100644 --- a/instrumentation/httpd/src/otel/mod_otel.cpp +++ b/instrumentation/httpd/src/otel/mod_otel.cpp @@ -94,7 +94,7 @@ HttpdStartSpanAttributes GetAttrsFromRequest(request_rec *r) // main function // TODO: fix this for scenarios where apache configuration is just updated (apachectl -k graceful) -static void opentel_child_created(apr_pool_t *p, server_rec *s) +static void opentel_child_created(apr_pool_t*, server_rec*) { initTracer(); } @@ -277,7 +277,7 @@ static int proxy_end_handler(int *status, request_rec *r) // PARSING CONFIGURATION OPTIONS ///////////////////////////////////////////////// -static const char *otel_set_exporter(cmd_parms *cmd, void *cfg, const char *arg) +const char *otel_set_exporter(cmd_parms */* cmd */, void */* cfg */, const char *arg) { if (!strcasecmp(arg, "file")) config.type = OtelExporterType::OSTREAM; @@ -289,7 +289,7 @@ static const char *otel_set_exporter(cmd_parms *cmd, void *cfg, const char *arg) return NULL; } -const char *otel_set_propagator(cmd_parms *cmd, void *cfg, const char *arg) +const char *otel_set_propagator(cmd_parms* /* cmd */, void* /* cfg */, const char *arg) { if (!strcasecmp(arg, "trace-context")) config.propagation = OtelPropagation::TRACE_CONTEXT; @@ -303,31 +303,31 @@ const char *otel_set_propagator(cmd_parms *cmd, void *cfg, const char *arg) return NULL; } -const char *otel_set_ignoreInbound(cmd_parms *cmd, void *cfg, int flag) +const char *otel_set_ignoreInbound(cmd_parms* /* cmd */, void* /* cfg */, int flag) { config.ignore_inbound = flag; return NULL; } -const char *otel_set_path(cmd_parms *cmd, void *cfg, const char *arg) +const char *otel_set_path(cmd_parms* /* cmd */, void* /* cfg */, const char *arg) { config.fname = arg; return NULL; } -const char *otel_set_endpoint(cmd_parms *cmd, void *cfg, const char *arg) +const char *otel_set_endpoint(cmd_parms* /* cmd */, void* /* cfg */, const char *arg) { config.endpoint = arg; return NULL; } -const char *otel_set_attribute(cmd_parms *cmd, void *cfg, const char *attrName, const char *attrValue) +const char *otel_set_attribute(cmd_parms *cmd, void* /* cfg */, const char *attrName, const char *attrValue) { config.attributes[attrName] = attrValue; return NULL; } -const char *otel_set_resource(cmd_parms *cmd, void *cfg, const char *attrName, const char *attrValue) +const char *otel_set_resource(cmd_parms *cmd, void* /* cfg */, const char *attrName, const char *attrValue) { config.resources[attrName] = attrValue; return NULL; @@ -364,38 +364,38 @@ static void opentel_register_hooks(apr_pool_t *p) static const command_rec opentel_directives[] = { AP_INIT_TAKE1("OpenTelemetryExporter", - otel_set_exporter, + reinterpret_cast(otel_set_exporter), NULL, RSRC_CONF, "Set specific exporter type"), - AP_INIT_TAKE1("OpenTelemetryPath", otel_set_path, NULL, RSRC_CONF, "Set path for exporter"), + AP_INIT_TAKE1("OpenTelemetryPath", reinterpret_cast(otel_set_path), NULL, RSRC_CONF, "Set path for exporter"), AP_INIT_TAKE1("OpenTelemetryEndpoint", - otel_set_endpoint, + reinterpret_cast(otel_set_endpoint), NULL, RSRC_CONF, "Set endpoint for exporter"), AP_INIT_TAKE2("OpenTelemetrySetAttribute", - otel_set_attribute, + reinterpret_cast(otel_set_attribute), NULL, RSRC_CONF, "Set additional attribute for each span"), AP_INIT_TAKE2("OpenTelemetrySetResource", - otel_set_resource, + reinterpret_cast(otel_set_resource), NULL, RSRC_CONF, "Set resource"), AP_INIT_TAKE3("OpenTelemetryBatch", - otel_cfg_batch, + reinterpret_cast(otel_cfg_batch), NULL, RSRC_CONF, "Configure batch processing"), AP_INIT_FLAG("OpenTelemetryIgnoreInbound", - otel_set_ignoreInbound, + reinterpret_cast(otel_set_ignoreInbound), NULL, RSRC_CONF, "Enable or disable context propagation from incoming requests."), AP_INIT_TAKE1("OpenTelemetryPropagators", - otel_set_propagator, + reinterpret_cast(otel_set_propagator), NULL, RSRC_CONF, "Configure propagators"), diff --git a/instrumentation/httpd/src/otel/opentelemetry.cpp b/instrumentation/httpd/src/otel/opentelemetry.cpp index 6f2257dbd..0f98bd2c4 100644 --- a/instrumentation/httpd/src/otel/opentelemetry.cpp +++ b/instrumentation/httpd/src/otel/opentelemetry.cpp @@ -30,17 +30,17 @@ namespace httpd_otel { // TODO: use semantic conventions https://github.com/open-telemetry/opentelemetry-cpp/issues/566 -const opentelemetry::v0::nostd::string_view kAttrHTTPServerName = "http.server_name"; -const opentelemetry::v0::nostd::string_view kAttrHTTPMethod = "http.method"; -const opentelemetry::v0::nostd::string_view kAttrHTTPScheme = "http.scheme"; -const opentelemetry::v0::nostd::string_view kAttrHTTPHost = "http.host"; -const opentelemetry::v0::nostd::string_view kAttrHTTPTarget = "http.target"; -const opentelemetry::v0::nostd::string_view kAttrHTTPUrl = "http.url"; -const opentelemetry::v0::nostd::string_view kAttrHTTPFlavor = "http.flavor"; -const opentelemetry::v0::nostd::string_view kAttrHTTPClientIP = "http.client_ip"; -const opentelemetry::v0::nostd::string_view kAttrNETPeerIP = "net.peer.ip"; -const opentelemetry::v0::nostd::string_view kAttrHTTPStatusCode = "http.status_code"; -const opentelemetry::v0::nostd::string_view kAttrHTTPResponseContentLen = "http.response_content_length"; +const nostd::string_view kAttrHTTPServerName = "http.server_name"; +const nostd::string_view kAttrHTTPMethod = "http.method"; +const nostd::string_view kAttrHTTPScheme = "http.scheme"; +const nostd::string_view kAttrHTTPHost = "http.host"; +const nostd::string_view kAttrHTTPTarget = "http.target"; +const nostd::string_view kAttrHTTPUrl = "http.url"; +const nostd::string_view kAttrHTTPFlavor = "http.flavor"; +const nostd::string_view kAttrHTTPClientIP = "http.client_ip"; +const nostd::string_view kAttrNETPeerIP = "net.peer.ip"; +const nostd::string_view kAttrHTTPStatusCode = "http.status_code"; +const nostd::string_view kAttrHTTPResponseContentLen = "http.response_content_length"; OtelConfig config; From 582ae4f476dfe964f58cfdd4f78aba8a9addf060 Mon Sep 17 00:00:00 2001 From: Tomasz Rojek Date: Thu, 10 Jun 2021 16:56:11 +0200 Subject: [PATCH 12/14] Use specific version of opentelemetry for CMake build --- instrumentation/httpd/setup-cmake.sh | 2 +- instrumentation/httpd/src/otel/mod_otel.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/instrumentation/httpd/setup-cmake.sh b/instrumentation/httpd/setup-cmake.sh index 1389aff93..21dee6dea 100755 --- a/instrumentation/httpd/setup-cmake.sh +++ b/instrumentation/httpd/setup-cmake.sh @@ -59,7 +59,7 @@ git clone --shallow-submodules --depth 1 --recurse-submodules -b v0.14.0 \ && make -j2 \ && make install -git clone --shallow-submodules --depth 1 --recurse-submodules \ +git clone --shallow-submodules --depth 1 --recurse-submodules -b "v1.0.0-rc1" \ https://github.com/open-telemetry/opentelemetry-cpp.git \ && cd opentelemetry-cpp \ && mkdir build \ diff --git a/instrumentation/httpd/src/otel/mod_otel.cpp b/instrumentation/httpd/src/otel/mod_otel.cpp index 829b51664..a8c85f0bd 100644 --- a/instrumentation/httpd/src/otel/mod_otel.cpp +++ b/instrumentation/httpd/src/otel/mod_otel.cpp @@ -277,7 +277,7 @@ static int proxy_end_handler(int *status, request_rec *r) // PARSING CONFIGURATION OPTIONS ///////////////////////////////////////////////// -const char *otel_set_exporter(cmd_parms */* cmd */, void */* cfg */, const char *arg) +const char *otel_set_exporter(cmd_parms* /* cmd */, void */* cfg */, const char *arg) { if (!strcasecmp(arg, "file")) config.type = OtelExporterType::OSTREAM; @@ -321,20 +321,20 @@ const char *otel_set_endpoint(cmd_parms* /* cmd */, void* /* cfg */, const char return NULL; } -const char *otel_set_attribute(cmd_parms *cmd, void* /* cfg */, const char *attrName, const char *attrValue) +const char *otel_set_attribute(cmd_parms* /* cmd */, void* /* cfg */, const char *attrName, const char *attrValue) { config.attributes[attrName] = attrValue; return NULL; } -const char *otel_set_resource(cmd_parms *cmd, void* /* cfg */, const char *attrName, const char *attrValue) +const char *otel_set_resource(cmd_parms* /* cmd */, void* /* cfg */, const char *attrName, const char *attrValue) { config.resources[attrName] = attrValue; return NULL; } -const char *otel_cfg_batch(cmd_parms *cmd, - void *cfg, +const char *otel_cfg_batch(cmd_parms* /* cmd */, + void* /* cfg */, const char *max_queue_size, const char *schedule_delay_millis, const char *max_export_batch_size) @@ -349,7 +349,7 @@ const char *otel_cfg_batch(cmd_parms *cmd, extern "C" { -static void opentel_register_hooks(apr_pool_t *p) +static void opentel_register_hooks(apr_pool_t* /* p */) { ap_hook_child_init(opentel_child_created, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_quick_handler(opentel_handler, NULL, NULL, APR_HOOK_FIRST); From 28dc06f0d71603c7f883e189cbc440c1ee3e6b73 Mon Sep 17 00:00:00 2001 From: Tomasz Rojek Date: Fri, 11 Jun 2021 11:37:59 +0200 Subject: [PATCH 13/14] Search for Apache Runtible Library and Apache Httpd include paths in CMake --- instrumentation/httpd/CMakeLists.txt | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/instrumentation/httpd/CMakeLists.txt b/instrumentation/httpd/CMakeLists.txt index ededdb915..d16be741e 100644 --- a/instrumentation/httpd/CMakeLists.txt +++ b/instrumentation/httpd/CMakeLists.txt @@ -9,6 +9,30 @@ find_package(gRPC REQUIRED) find_package(CURL REQUIRED) find_package(Thrift REQUIRED) +find_path(APR_INCLUDE_DIR + NAMES apr.h + PATHS /opt/homebrew/opt/apr/include/apr-1 + /usr/local/include/apr-1 + /usr/local/include/apr-1.0 + /usr/include/apr-1 + /usr/include/apr-1.0 + /usr/local/apr/include/apr-1 +) + +IF(NOT EXISTS "${APR_INCLUDE_DIR}/apr.h") + MESSAGE(FATAL_ERROR "APR include directory ${APR_INCLUDE_DIR} is not correct.") +ENDIF() + +find_path(APACHE_INCLUDE_DIR + NAMES httpd.h + PATHS /usr/include/apache2 + /usr/local/include/apache2 +) + +IF(NOT EXISTS "${APACHE_INCLUDE_DIR}/httpd.h") + MESSAGE(FATAL_ERROR "APACHE_INCLUDE_DIR include directory ${APACHE_INCLUDE_DIR} is not correct.") +ENDIF() + add_library(otel_httpd_module SHARED src/otel/mod_otel.cpp src/otel/opentelemetry.cpp @@ -27,8 +51,8 @@ set_target_properties(otel_httpd_module PROPERTIES target_include_directories(otel_httpd_module PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS} - "/usr/include/apache2" - "/usr/include/apr-1.0" + ${APACHE_INCLUDE_DIR} + ${APR_INCLUDE_DIR} ) target_link_libraries(otel_httpd_module From 33d7d4091c3ab0449f79b4e10ae49f6a53db2a36 Mon Sep 17 00:00:00 2001 From: Tomasz Rojek Date: Wed, 16 Jun 2021 13:41:48 +0200 Subject: [PATCH 14/14] Remove ::v0:: prefix --- instrumentation/httpd/src/otel/opentelemetry.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/instrumentation/httpd/src/otel/opentelemetry.h b/instrumentation/httpd/src/otel/opentelemetry.h index f8d87f17f..7282150b4 100644 --- a/instrumentation/httpd/src/otel/opentelemetry.h +++ b/instrumentation/httpd/src/otel/opentelemetry.h @@ -20,9 +20,9 @@ #include #include -#include -#include -#include +#include "opentelemetry/context/context.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/trace/batch_span_processor.h" #include "opentelemetry/trace/provider.h" namespace httpd_otel @@ -86,8 +86,8 @@ struct HttpdEndSpanAttributes // to be called explictly inside Destruct method struct ExtraRequestData { // context which we pass - opentelemetry::v0::nostd::unique_ptr token; - opentelemetry::v0::nostd::shared_ptr span; + opentelemetry::nostd::unique_ptr token; + opentelemetry::nostd::shared_ptr span; HttpdStartSpanAttributes startAttrs; HttpdEndSpanAttributes endAttrs; // Sets attributes for HTTP request. @@ -114,7 +114,7 @@ struct ExtraRequestData // Initializes OpenTelemetry module. void initTracer(); // Returns default (global) tracer. -opentelemetry::v0::nostd::shared_ptr get_tracer(); +opentelemetry::nostd::shared_ptr get_tracer(); } // namespace httpd_otel