Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions instrumentation/otel-webserver-module/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@
*.exe
*.out
*.app

# Gradle
.gradle/

# Build output
build/
42 changes: 42 additions & 0 deletions instrumentation/otel-webserver-module/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.16)

file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/version.properties" _version_props)
foreach(_line IN LISTS _version_props)
if(_line MATCHES "^server-module-version=(.+)$")
set(_module_version "${CMAKE_MATCH_1}")
endif()
endforeach()

project(otel-webserver-module VERSION ${_module_version} LANGUAGES CXX)

option(OTEL_WEBSERVER_BUILD_APACHE "Build the Apache httpd modules" ON)
option(OTEL_WEBSERVER_BUILD_TESTS "Build the unit tests" ON)
option(OTEL_ENABLE_COVERAGE "Instrument for gcov/lcov" OFF)

# Pinned deliberately.
# TODO: bump version following otel-cpp
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set(OTEL_ARCH_FLAG "-m64" CACHE STRING "Target architecture flag")

find_package(Threads REQUIRED)
include(cmake/otel-webserver-deps.cmake)

if(OTEL_ENABLE_COVERAGE)
add_compile_options(-g -fprofile-arcs -ftest-coverage)
add_link_options(--coverage)
endif()

add_subdirectory(src)

if(OTEL_WEBSERVER_BUILD_APACHE)
add_subdirectory(src/apache)
endif()

if(OTEL_WEBSERVER_BUILD_TESTS)
enable_testing()
add_subdirectory(test/unit)
endif()
178 changes: 47 additions & 131 deletions instrumentation/otel-webserver-module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ project.ext {
debug = true;
}

ansdkOsName = osName
ansdkArch = (osArch == 'x86' ? 'i686' : osArch)
gccArchFlag = (osArch == 'x86' ? '-m32' : '-m64')
headSHA1 = "<dev>"

Expand All @@ -44,8 +42,7 @@ project.ext {
buildType = "Release Build"
fullVersion = "${moduleName} ${moduleVersion} ${moduleRelease} ${headSHA1}: ${buildType}"

gypPath = "$projectDir/scripts/gyp/r1919/gyp"
gypType = 'make'
cmakeBuildDir = "${platBuildDir}/cmake"

scriptExt = 'sh'
sharedLibraryExt = 'so'
Expand All @@ -62,19 +59,14 @@ project.ext {
apacheStageDir = "${libraryStageDir}/WebServerModule/Apache"
nginxStageDir = "${libraryStageDir}/WebServerModule/Nginx"

coverageCompilerFlags = '-g -fprofile-arcs -ftest-coverage'
coverageLinkerFlags = '-lgcov --coverage'
libraryFlags = '-lrt -lpthread -ldl -lz -lcrypt'

COVERAGE_DIR = "${platBuildDir}/coverage"
LCOV_RAW_INFO = "${COVERAGE_DIR}/lcov-raw.info"
LCOV_INFO = "${COVERAGE_DIR}/lcov.info"

BOOST_INCLUDE = "${modDepDir}/boost/1.75.0/include"
BOOST_LIB = "${modDepDir}/boost/1.75.0/lib/libboost_filesystem.a ${modDepDir}/boost/1.75.0/lib/libboost_system.a"
}

task extractANSDK(type: Copy) {
task extractDependencies(type: Copy) {
from "dependencies"
into modDepDir
}
Expand Down Expand Up @@ -131,53 +123,55 @@ task generateSources {
//delete 'scripts/VERSION.txt'
// }

task gypLibrary(type: Exec) {
group = 'SDK Library'
description = 'Run gyp to generate the platform-specific build scripts'

dependsOn extractANSDK, generateSources
task cmakeConfigure(type: Exec) {
group = 'CMake'
description = 'Configure the CMake build tree'

inputs.file "src/build.gyp"
dependsOn extractDependencies, generateSources
dependsOn 'configureApache22', 'configureApache24'

outputs.file "${platBuildDir}/Makefile"
inputs.file 'CMakeLists.txt'
inputs.dir 'cmake'
outputs.file "${cmakeBuildDir}/CMakeCache.txt"

ext.libraryBuildEnvironment = [
ARCH_FLAG: gccArchFlag,
ANSDK_DIR: modDepDir,
COMPILER_FLAGS: (coverageEnabled) ? coverageCompilerFlags : '',
LINKER_FLAGS: (coverageEnabled) ? coverageLinkerFlags : '',
BOOST_LIB: BOOST_LIB,
BOOST_INCLUDE: BOOST_INCLUDE,
LIBRARY_FLAGS: libraryFlags,
CPP_SDK_VERSION: cppSDKVersion,
]

environment libraryBuildEnvironment
workingDir 'src'
commandLine gypPath, "--generator-output=${platBuildDir}", '--toplevel-dir=.', '--depth=./', '-f', gypType, 'build.gyp'
commandLine 'cmake',
'-S', projectDir,
'-B', cmakeBuildDir,
"-DOTEL_DEPS_DIR=${modDepDir}",
"-DOTEL_CPP_SDK_VERSION=${cppSDKVersion}",
"-DOTEL_GTEST_VERSION=${gtestVersion}",
"-DOTEL_ARCH_FLAG=${gccArchFlag}",
"-DOTEL_APACHE22_INCLUDE_DIR=${platBuildDir}/httpd-${apache22Version}/include",
"-DOTEL_APACHE24_INCLUDE_DIR=${platBuildDir}/httpd-${apache24Version}/include",
"-DOTEL_ENABLE_COVERAGE=${coverageEnabled ? 'ON' : 'OFF'}",
"-DCMAKE_BUILD_TYPE=${debug ? 'Debug' : 'Release'}"
}

task buildLibrary(type: Exec) {
group = 'SDK Library'
description = 'Compile the SDK library'
task cmakeBuild(type: Exec) {
group = 'CMake'
description = 'Build all targets via CMake'

dependsOn gypLibrary
inputs.property "buildType", buildType
inputs.dir 'src/util'
dependsOn cmakeConfigure

outputs.file "${platBuildDir}/out/Default/lib.target/libopentelemetry_webserver_sdk.so"
inputs.dir 'src'
inputs.dir 'include'
inputs.dir 'test/unit'

args = ['make', 'V=1', '-j', Runtime.runtime.availableProcessors()]
outputs.file "${cmakeBuildDir}/lib/libopentelemetry_webserver_sdk.${sharedLibraryExt}"
outputs.file "${cmakeBuildDir}/apache/libmod_apache_otel.${sharedLibraryExt}"
outputs.file "${cmakeBuildDir}/apache/libmod_apache_otel22.${sharedLibraryExt}"
outputs.file "${cmakeBuildDir}/test/unit_test"

environment gypLibrary.libraryBuildEnvironment
workingDir "${platBuildDir}"
commandLine args
commandLine 'cmake', '--build', cmakeBuildDir,
'--parallel', Runtime.runtime.availableProcessors()
}

task stageLibrary(type: Copy) {
group = 'SDK Library'
description = 'Stage the SDK library distribution'

dependsOn cmakeBuild

doLast {
def logDir = file("${libraryStageDir}/logs")
logDir.mkdirs()
Expand All @@ -186,7 +180,7 @@ task stageLibrary(type: Copy) {

from("dist/runSDKProxy.sh") { it.fileMode 0770 }

from(buildLibrary) { it.into "sdk_lib/lib" }
from("${cmakeBuildDir}/lib/libopentelemetry_webserver_sdk.${sharedLibraryExt}") { it.into "sdk_lib/lib" }
from("${modDepDir}/opentelemetry/${cppSDKVersion}/lib/libopentelemetry_common.so") { it.into "sdk_lib/lib" }
from("${modDepDir}/opentelemetry/${cppSDKVersion}/lib/libopentelemetry_resources.so") { it.into "sdk_lib/lib" }
from("${modDepDir}/opentelemetry/${cppSDKVersion}/lib/libopentelemetry_trace.so") { it.into "sdk_lib/lib" }
Expand Down Expand Up @@ -284,59 +278,14 @@ task configureApache24(type: Exec) {
commandLine './configure', '--with-included-apr'
}

task gypApacheModule(type: Exec) {
group = 'Apache Web Server Module'
description = 'Run gyp to generate the build files for Apache Web Server Module'

dependsOn stageLibrary
dependsOn configureApache22
dependsOn configureApache24

inputs.file "src/apache/apache.gyp"
outputs.file "${platBuildDir}/apache/Makefile"

ext.apacheBuildEnvironment = [
ARCH_FLAG: gccArchFlag,
APACHE22_INCLUDE_DIR: "${platBuildDir}/httpd-${apache22Version}/include",
APACHE24_INCLUDE_DIR: "${platBuildDir}/httpd-${apache24Version}/include",
OTEL_SDK_LIB_DIR: "${libraryStageDir}/sdk_lib",
ANSDK_DIR: modDepDir,
COMPILER_FLAGS: (coverageEnabled) ? coverageCompilerFlags : '',
LINKER_FLAGS: (coverageEnabled) ? coverageLinkerFlags : '',
LIBRARY_FLAGS: libraryFlags,
]

environment apacheBuildEnvironment
workingDir 'src/apache'
commandLine gypPath, "--generator-output=${platBuildDir}/apache", '--toplevel-dir=.', '--depth=./', '-f', gypType, 'apache.gyp'
}

task buildApacheModule(type: Exec) {
group = 'Apache Web Server Module'
description = 'Build the Apache Web Server Module'

dependsOn gypApacheModule
inputs.dir 'src/util'
inputs.dir 'src/apache'
inputs.dir 'src/core'

outputs.file "${platBuildDir}/apache/out/Default/lib.target/libmod_apache_otel.so"
outputs.file "${platBuildDir}/apache/out/Default/lib.target/libmod_apache_otel22.so"

args = ['make', 'V=1', '-j', Runtime.runtime.availableProcessors()]

environment gypApacheModule.apacheBuildEnvironment
workingDir "${platBuildDir}/apache"
commandLine args
}

task stageApacheModule(type: Copy) {
group = 'Apache Web Server Module'
description = 'Stage the Apache Web Server Module distribution directory'

dependsOn stageLibrary
dependsOn stageLibrary, cmakeBuild

from buildApacheModule
from "${cmakeBuildDir}/apache/libmod_apache_otel.${sharedLibraryExt}"
from "${cmakeBuildDir}/apache/libmod_apache_otel22.${sharedLibraryExt}"
into apacheStageDir
}

Expand Down Expand Up @@ -492,48 +441,15 @@ task assembleWebServerModule(type: Tar) {

// Tests

task gypUnitTest(type: Exec) {
dependsOn stageLibrary

inputs.file 'test/unit/unit_test.gyp'
outputs.file "${platBuildDir}/unit_test/Makefile"

ext.testBuildEnvironment = [
OTEL_SDK_LIB_DIR: "${libraryStageDir}/sdk_lib",
ANSDK_DIR: modDepDir,
BOOST_LIB: BOOST_LIB,
BOOST_INCLUDE: BOOST_INCLUDE,
GTEST_INCLUDE_DIR: "${modDepDir}/googletest/${gtestVersion}/include",
GTEST_LIB_DIR: target_system == "ubuntu" ?
"${modDepDir}/googletest/${gtestVersion}/lib" : "${modDepDir}/googletest/${gtestVersion}/lib64",
LIBRARY_FLAGS: libraryFlags,
CPP_SDK_VERSION: cppSDKVersion,
]

environment testBuildEnvironment
workingDir 'test/unit'
commandLine gypPath, "--generator-output=${platBuildDir}/unit_test", '--toplevel-dir=.', '--depth=./', '-f', gypType, 'unit_test.gyp'
}

task makeUnitTest(type: Exec) {
dependsOn gypUnitTest

inputs.dir 'test/unit'

outputs.file "${platBuildDir}/unit_test/out/Default/unit_test"

environment gypUnitTest.testBuildEnvironment
workingDir "${platBuildDir}/unit_test"
commandLine 'make', 'V=1'
}

task runUnitTest(type: Exec) {
dependsOn makeUnitTest
environment gypUnitTest.testBuildEnvironment
group = 'verification'
description = 'Run the unit tests'

dependsOn cmakeBuild, stageLibrary

environment "LD_LIBRARY_PATH", "${libraryStageDir}/sdk_lib/lib/"
environment 'LD_LIBRARY_PATH', "${libraryStageDir}/sdk_lib/lib"

workingDir "${platBuildDir}/unit_test/out/Default"
workingDir "${cmakeBuildDir}/test"
commandLine './unit_test'
}

Expand Down Expand Up @@ -579,7 +495,7 @@ task lcovCapture(type: Exec) {
executable 'lcov'
args '--output-file', tracefile, // resulting tracefile
'--capture', // capture counts for a user space program
'--directory', "${platBuildDir}" // location where the program was compiled
'--directory', "${cmakeBuildDir}" // location where the program was compiled
'--no-external' // ignore data for external files
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
set(OTEL_DEPS_DIR "" CACHE PATH "Prebuilt dependency tree")

if(NOT OTEL_DEPS_DIR)
message(FATAL_ERROR
"OTEL_DEPS_DIR is not set. Point it at the prebuilt dependency tree\n")
endif()

if(NOT IS_DIRECTORY "${OTEL_DEPS_DIR}")
message(FATAL_ERROR "OTEL_DEPS_DIR does not exist: ${OTEL_DEPS_DIR}")
endif()

set(OTEL_APR_VERSION "1.7.0" CACHE STRING "apr version in the deps tree")
set(OTEL_APRUTIL_VERSION "1.6.1" CACHE STRING "apr-util version in the deps tree")
set(OTEL_EXPAT_VERSION "2.3.0" CACHE STRING "expat version in the deps tree")
set(OTEL_LOG4CXX_VERSION "0.11.0" CACHE STRING "log4cxx version in the deps tree")
set(OTEL_CPP_SDK_VERSION "1.2.0" CACHE STRING "opentelemetry-cpp version in the deps tree")

set(OTEL_APR_ROOT "${OTEL_DEPS_DIR}/apr/${OTEL_APR_VERSION}")
set(OTEL_APRUTIL_ROOT "${OTEL_DEPS_DIR}/apr-util/${OTEL_APRUTIL_VERSION}")
set(OTEL_EXPAT_ROOT "${OTEL_DEPS_DIR}/expat/${OTEL_EXPAT_VERSION}")
set(OTEL_LOG4CXX_ROOT "${OTEL_DEPS_DIR}/apache-log4cxx/${OTEL_LOG4CXX_VERSION}")
set(OTEL_CPP_SDK_ROOT "${OTEL_DEPS_DIR}/opentelemetry/${OTEL_CPP_SDK_VERSION}")

# Declares an IMPORTED library target for one prebuilt dependency.
#
# otel_declare_prebuilt(<target> <kind> <root> <libname>)
#
# target - name to create, e.g. otel::deps::apr
# kind - STATIC or SHARED
# root - install prefix, e.g. ${OTEL_APR_ROOT}
# libname - base name passed to find_library, e.g. apr-1
function(otel_declare_prebuilt target kind root libname)
if(NOT kind MATCHES "^(STATIC|SHARED)$")
message(FATAL_ERROR "otel_declare_prebuilt(${target}): kind must be STATIC or SHARED, got '${kind}'")
endif()

string(MAKE_C_IDENTIFIER "OTEL_PREBUILT_${target}" _cache_var)

find_library(${_cache_var}
NAMES ${libname}
PATHS "${root}"
PATH_SUFFIXES lib lib64
NO_DEFAULT_PATH)

if(NOT ${_cache_var})
message(FATAL_ERROR
"${target}: no lib${libname} under ${root}/{lib,lib64}.\n"
"Check OTEL_DEPS_DIR and the OTEL_*_VERSION cache variables.")
endif()

add_library(${target} ${kind} IMPORTED GLOBAL)
set_target_properties(${target} PROPERTIES IMPORTED_LOCATION "${${_cache_var}}")

if(IS_DIRECTORY "${root}/include")
set_target_properties(${target} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${root}/include")
endif()
endfunction()

otel_declare_prebuilt(otel::deps::apr STATIC "${OTEL_APR_ROOT}" apr-1)
otel_declare_prebuilt(otel::deps::aprutil STATIC "${OTEL_APRUTIL_ROOT}" aprutil-1)
otel_declare_prebuilt(otel::deps::expat STATIC "${OTEL_EXPAT_ROOT}" expat)
otel_declare_prebuilt(otel::deps::log4cxx STATIC "${OTEL_LOG4CXX_ROOT}" log4cxx)

set(OTEL_CPP_SDK_LIBS
opentelemetry_common
opentelemetry_resources
opentelemetry_trace
opentelemetry_otlp_recordable
opentelemetry_exporter_ostream_span
opentelemetry_exporter_otlp_grpc)

foreach(_lib IN LISTS OTEL_CPP_SDK_LIBS)
otel_declare_prebuilt(otel::deps::${_lib} SHARED "${OTEL_CPP_SDK_ROOT}" ${_lib})
endforeach()

# Must match BOOST_VERSION in the docker/*/Dockerfile images and codeql-env.sh.
set(OTEL_BOOST_VERSION "1.75.0" CACHE STRING "boost version in the deps tree")
set(OTEL_BOOST_ROOT "${OTEL_DEPS_DIR}/boost/${OTEL_BOOST_VERSION}")

otel_declare_prebuilt(otel::deps::boost_filesystem STATIC "${OTEL_BOOST_ROOT}" boost_filesystem)
otel_declare_prebuilt(otel::deps::boost_system STATIC "${OTEL_BOOST_ROOT}" boost_system)
Loading
Loading