Skip to content

Commit

Permalink
✨ add event sampling #22 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann authored Aug 15, 2018
1 parent dca4b97 commit 234c2be
Show file tree
Hide file tree
Showing 22 changed files with 541 additions and 298 deletions.
52 changes: 31 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-4.9', 'ninja-build']
packages: ['g++-4.9', 'ninja-build', 'nodejs']
before_script:
- pip install --user cpp-coveralls
after_success:
Expand All @@ -35,8 +35,8 @@ matrix:

# OSX / Clang

- os: osx
osx_image: xcode6.4
#- os: osx
# osx_image: xcode6.4

- os: osx
osx_image: xcode7.3
Expand Down Expand Up @@ -78,7 +78,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-4.9', 'ninja-build']
packages: ['g++-4.9', 'ninja-build', 'nodejs']

- os: linux
compiler: gcc
Expand All @@ -88,7 +88,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5', 'ninja-build']
packages: ['g++-5', 'ninja-build', 'nodejs']

- os: linux
compiler: gcc
Expand All @@ -98,7 +98,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-6', 'ninja-build']
packages: ['g++-6', 'ninja-build', 'nodejs']

- os: linux
compiler: gcc
Expand All @@ -108,7 +108,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-7', 'ninja-build']
packages: ['g++-7', 'ninja-build', 'nodejs']

- os: linux
compiler: gcc
Expand All @@ -118,7 +118,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-8', 'ninja-build']
packages: ['g++-8', 'ninja-build', 'nodejs']

- os: linux
compiler: gcc
Expand All @@ -129,7 +129,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-8', 'ninja-build']
packages: ['g++-8', 'ninja-build', 'nodejs']

# Linux / Clang

Expand All @@ -141,7 +141,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5']
packages: ['g++-6', 'clang-3.5', 'ninja-build']
packages: ['g++-6', 'clang-3.5', 'ninja-build', 'nodejs']

- os: linux
compiler: clang
Expand All @@ -151,7 +151,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6']
packages: ['g++-6', 'clang-3.6', 'ninja-build']
packages: ['g++-6', 'clang-3.6', 'ninja-build', 'nodejs']

- os: linux
compiler: clang
Expand All @@ -161,7 +161,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7']
packages: ['g++-6', 'clang-3.7', 'ninja-build']
packages: ['g++-6', 'clang-3.7', 'ninja-build', 'nodejs']

- os: linux
compiler: clang
Expand All @@ -171,7 +171,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-6', 'clang-3.8', 'ninja-build']
packages: ['g++-6', 'clang-3.8', 'ninja-build', 'nodejs']

- os: linux
compiler: clang
Expand All @@ -181,7 +181,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-6', 'clang-3.9', 'ninja-build']
packages: ['g++-6', 'clang-3.9', 'ninja-build', 'nodejs']

- os: linux
compiler: clang
Expand All @@ -191,7 +191,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0']
packages: ['g++-6', 'clang-4.0', 'ninja-build']
packages: ['g++-6', 'clang-4.0', 'ninja-build', 'nodejs']

- os: linux
compiler: clang
Expand All @@ -201,7 +201,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
packages: ['g++-6', 'clang-5.0', 'ninja-build']
packages: ['g++-6', 'clang-5.0', 'ninja-build', 'nodejs']

- os: linux
compiler: clang
Expand All @@ -211,7 +211,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-6.0']
packages: ['g++-6', 'clang-6.0', 'ninja-build']
packages: ['g++-6', 'clang-6.0', 'ninja-build', 'nodejs']

- os: linux
compiler: clang
Expand All @@ -222,19 +222,19 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-6.0']
packages: ['g++-6', 'clang-6.0', 'ninja-build']
packages: ['g++-6', 'clang-6.0', 'ninja-build', 'nodejs']

################
# build script #
################

script:
install:
# get CMake and Ninja (only for systems with brew - macOS)
- |
if [[ (-x $(which brew)) ]]; then
brew update
brew install cmake ninja
brew upgrade cmake
brew install cmake ninja node
brew upgrade cmake node
cmake --version
else
wget -O cmake.sh https://cmake.org/files/v3.10/cmake-3.10.0-rc1-Linux-x86_64.sh
Expand All @@ -243,6 +243,11 @@ script:
export PATH=/tmp/cmake/bin:$PATH
fi
# install node forever module
- npm install -g forever
# start test server
- forever start tests/server/server.js

# make sure CXX is correctly set
- if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; export CC=${CCOMPILER}; fi

Expand All @@ -251,8 +256,13 @@ script:
- $CC --version
- $CXX --version

script:
# compile and execute unit tests
- mkdir -p build && cd build
- cmake .. ${CMAKE_OPTIONS} -DCROW_BUILD_LOG4CPLUS=ON -GNinja && cmake --build . --config Release
- ctest -C Release -V -j
- cd ..

after_script:
# shut down test server
- forever stop tests/server/server.js
33 changes: 19 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)
cmake_policy(SET CMP0048 NEW)
project(crow VERSION 0.0.4)
project(crow VERSION 0.0.5)

##############################
# check for required headers #
Expand Down Expand Up @@ -103,7 +103,7 @@ find_package(Threads)
# library #
###########

add_library(crow src/crow.cpp src/crow_utilities.cpp)
add_library(crow src/crow.cpp src/crow_utilities.cpp src/crow_utilities.hpp)
set_target_properties(crow PROPERTIES CXX_STANDARD 11)
target_include_directories(crow PUBLIC include PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CURL_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS})
target_link_libraries(crow ${CURL_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES})
Expand Down Expand Up @@ -136,19 +136,25 @@ option(CROW_BUILD_LOG4CPLUS "build log4cplus example" OFF)
if(CROW_BUILD_TESTING AND (BUILD_TESTING OR CROW_EXTERNAL_CURL_PROJECT))
enable_testing()

get_target_property(CROW_SOURCES crow SOURCES)
add_executable(tests tests/unittests.cpp ${CROW_SOURCES})
set_target_properties(tests PROPERTIES CXX_STANDARD 11)
target_include_directories(tests PUBLIC tests include ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(tests ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
add_executable(unittests tests/unittests.cpp)
set_target_properties(unittests PROPERTIES CXX_STANDARD 11)
target_include_directories(unittests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} tests)
target_link_libraries(unittests crow)
add_test(NAME unittests COMMAND unittests)

# std::current_exception is broken with MSVC (https://developercommunity.visualstudio.com/content/problem/135332/stdcurrent-exception-returns-null-in-a-stdterminat.html)
if (NOT MSVC)
add_executable(uncaught_exception tests/uncaught_exception.cpp)
set_target_properties(uncaught_exception PROPERTIES CXX_STANDARD 11)
target_link_libraries(uncaught_exception crow)
add_test(NAME uncaught_exception COMMAND uncaught_exception)
endif()

add_executable(livetest tests/livetest.cpp)
set_target_properties(livetest PROPERTIES CXX_STANDARD 11)
target_include_directories(livetest PUBLIC include ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(livetest PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(livetest crow)

add_test(tests tests)
add_test(livetest livetest)
add_test(NAME livetest COMMAND livetest)

if(CROW_BUILD_LOG4CPLUS)
include(ExternalProject)
Expand All @@ -163,12 +169,11 @@ if(CROW_BUILD_TESTING AND (BUILD_TESTING OR CROW_EXTERNAL_CURL_PROJECT))
set_target_properties(log4cplus PROPERTIES IMPORTED_LOCATION ${install_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}log4cplus${CMAKE_STATIC_LIBRARY_SUFFIX})
add_dependencies(log4cplus log4cplus_project)

add_executable(log4cplus_example examples/log4cplus/example.cpp)
add_executable(log4cplus_example examples/log4cplus/example.cpp include/crow/integrations/loggers.hpp include/crow/integrations/log4cplus.hpp)
set_target_properties(log4cplus_example PROPERTIES CXX_STANDARD 11)
target_include_directories(log4cplus_example PUBLIC include ${install_dir}/include)
target_link_libraries(log4cplus_example log4cplus crow)

add_test(log4cplus_example log4cplus_example)
add_test(NAME log4cplus_example COMMAND log4cplus_example)
endif()
endif()

Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

### Setup

- `nlohmann::crow::crow(dsn, context={}, install_handlers=true)` to create a client
- `nlohmann::crow::crow(dsn, context={}, sample_rate=1.0, install_handlers=true)` to create a client
- `nlohmann::crow::install_handler()` to later install termination handler

### Reporting
Expand Down Expand Up @@ -54,13 +54,20 @@ The following items from [the SDK implementation guidelines](https://docs.sentry
- [x] Non-blocking event submission
- [ ] Basic data sanitization (e.g. filtering out values that look like passwords)
- [x] Context data helpers (e.g. setting the current user, recording breadcrumbs)
- [ ] Event sampling
- [x] Event sampling
- [ ] Honor Sentry’s HTTP 429 Retry-After header
- [ ] Pre and Post event send hooks
- [ ] Local variable values in stacktrace (on platforms where this is possible)

## Change Log

### Version 0.0.5

- :sparkles: added event sampling
- :white_check_mark: added testing server to mock Sentry
- :memo: added example code
- :hammer: overworked threading

### Version 0.0.4

- :sparkles: added Log4cplus integration
Expand Down
10 changes: 9 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ install:
- if "%COMPILER%"=="mingw" set PATH=C:\projects\deps\ninja;%PATH%
- if "%COMPILER%"=="mingw" set PATH=C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin;%PATH%
- if "%COMPILER%"=="mingw" g++ --version
- ps: Install-Product node 6
- npm install -g forever

before_build:
- curl https://curl.haxx.se/download/curl-7.61.0.zip -O
Expand All @@ -59,5 +61,11 @@ before_build:
build_script:
- cmake --build . --config Release

before_test:
- forever start tests/server/server.js

test_script:
- ctest -C Release -V -j --output-on-failure --verbose
- ctest -C Release -V --output-on-failure --verbose

on_finish:
- forever stop tests/server/server.js
4 changes: 2 additions & 2 deletions doc/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = NO
SHOW_FILES = NO
SHOW_NAMESPACES = NO
SHOW_NAMESPACES = YES
FILE_VERSION_FILTER =
LAYOUT_FILE =
CITE_BIB_FILES =
Expand All @@ -115,7 +115,7 @@ WARN_LOGFILE =
#---------------------------------------------------------------------------
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/include/crow @CMAKE_CURRENT_SOURCE_DIR@/src \
@CMAKE_CURRENT_SOURCE_DIR@/examples \
@CMAKE_CURRENT_BINARY_DIR@/include/crow @CMAKE_CURRENT_SOURCE_DIR@/README.md
@CMAKE_CURRENT_BINARY_DIR@/src @CMAKE_CURRENT_SOURCE_DIR@/README.md
INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.c \
*.cc \
Expand Down
19 changes: 19 additions & 0 deletions examples/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.10)

project(crow_example)

include(ExternalProject)
ExternalProject_Add(crow_project
GIT_REPOSITORY https://github.com/nlohmann/crow
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/crow
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/crow -DCROW_BUILD_TESTING=OFF
BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/log4cplus/lib/${CMAKE_SHARED_LIBRARY_PREFIX}crow${CMAKE_SHARED_LIBRARY_SUFFIX}
)
ExternalProject_Get_Property(crow_project install_dir)
add_library(crow SHARED IMPORTED)
set_target_properties(crow PROPERTIES IMPORTED_LOCATION ${install_dir}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}crow${CMAKE_SHARED_LIBRARY_SUFFIX})
add_dependencies(crow crow_project)

add_executable(example example.cpp)
target_link_libraries(example crow)
set_target_properties(example PROPERTIES CXX_STANDARD 11)
11 changes: 11 additions & 0 deletions examples/integration/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <crow/crow.hpp>

using nlohmann::crow;

int main()
{
crow client("http://abc:[email protected]/42");

client.add_breadcrumb("this is a breadcrumb");
client.capture_message("this is a message");
}
Loading

0 comments on commit 234c2be

Please sign in to comment.