Skip to content

Commit 234c2be

Browse files
authored
✨ add event sampling #22 (#28)
1 parent dca4b97 commit 234c2be

File tree

22 files changed

+541
-298
lines changed

22 files changed

+541
-298
lines changed

.travis.yml

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ matrix:
2323
addons:
2424
apt:
2525
sources: ['ubuntu-toolchain-r-test']
26-
packages: ['g++-4.9', 'ninja-build']
26+
packages: ['g++-4.9', 'ninja-build', 'nodejs']
2727
before_script:
2828
- pip install --user cpp-coveralls
2929
after_success:
@@ -35,8 +35,8 @@ matrix:
3535

3636
# OSX / Clang
3737

38-
- os: osx
39-
osx_image: xcode6.4
38+
#- os: osx
39+
# osx_image: xcode6.4
4040

4141
- os: osx
4242
osx_image: xcode7.3
@@ -78,7 +78,7 @@ matrix:
7878
addons:
7979
apt:
8080
sources: ['ubuntu-toolchain-r-test']
81-
packages: ['g++-4.9', 'ninja-build']
81+
packages: ['g++-4.9', 'ninja-build', 'nodejs']
8282

8383
- os: linux
8484
compiler: gcc
@@ -88,7 +88,7 @@ matrix:
8888
addons:
8989
apt:
9090
sources: ['ubuntu-toolchain-r-test']
91-
packages: ['g++-5', 'ninja-build']
91+
packages: ['g++-5', 'ninja-build', 'nodejs']
9292

9393
- os: linux
9494
compiler: gcc
@@ -98,7 +98,7 @@ matrix:
9898
addons:
9999
apt:
100100
sources: ['ubuntu-toolchain-r-test']
101-
packages: ['g++-6', 'ninja-build']
101+
packages: ['g++-6', 'ninja-build', 'nodejs']
102102

103103
- os: linux
104104
compiler: gcc
@@ -108,7 +108,7 @@ matrix:
108108
addons:
109109
apt:
110110
sources: ['ubuntu-toolchain-r-test']
111-
packages: ['g++-7', 'ninja-build']
111+
packages: ['g++-7', 'ninja-build', 'nodejs']
112112

113113
- os: linux
114114
compiler: gcc
@@ -118,7 +118,7 @@ matrix:
118118
addons:
119119
apt:
120120
sources: ['ubuntu-toolchain-r-test']
121-
packages: ['g++-8', 'ninja-build']
121+
packages: ['g++-8', 'ninja-build', 'nodejs']
122122

123123
- os: linux
124124
compiler: gcc
@@ -129,7 +129,7 @@ matrix:
129129
addons:
130130
apt:
131131
sources: ['ubuntu-toolchain-r-test']
132-
packages: ['g++-8', 'ninja-build']
132+
packages: ['g++-8', 'ninja-build', 'nodejs']
133133

134134
# Linux / Clang
135135

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

146146
- os: linux
147147
compiler: clang
@@ -151,7 +151,7 @@ matrix:
151151
addons:
152152
apt:
153153
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6']
154-
packages: ['g++-6', 'clang-3.6', 'ninja-build']
154+
packages: ['g++-6', 'clang-3.6', 'ninja-build', 'nodejs']
155155

156156
- os: linux
157157
compiler: clang
@@ -161,7 +161,7 @@ matrix:
161161
addons:
162162
apt:
163163
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7']
164-
packages: ['g++-6', 'clang-3.7', 'ninja-build']
164+
packages: ['g++-6', 'clang-3.7', 'ninja-build', 'nodejs']
165165

166166
- os: linux
167167
compiler: clang
@@ -171,7 +171,7 @@ matrix:
171171
addons:
172172
apt:
173173
sources: ['ubuntu-toolchain-r-test']
174-
packages: ['g++-6', 'clang-3.8', 'ninja-build']
174+
packages: ['g++-6', 'clang-3.8', 'ninja-build', 'nodejs']
175175

176176
- os: linux
177177
compiler: clang
@@ -181,7 +181,7 @@ matrix:
181181
addons:
182182
apt:
183183
sources: ['ubuntu-toolchain-r-test']
184-
packages: ['g++-6', 'clang-3.9', 'ninja-build']
184+
packages: ['g++-6', 'clang-3.9', 'ninja-build', 'nodejs']
185185

186186
- os: linux
187187
compiler: clang
@@ -191,7 +191,7 @@ matrix:
191191
addons:
192192
apt:
193193
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0']
194-
packages: ['g++-6', 'clang-4.0', 'ninja-build']
194+
packages: ['g++-6', 'clang-4.0', 'ninja-build', 'nodejs']
195195

196196
- os: linux
197197
compiler: clang
@@ -201,7 +201,7 @@ matrix:
201201
addons:
202202
apt:
203203
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
204-
packages: ['g++-6', 'clang-5.0', 'ninja-build']
204+
packages: ['g++-6', 'clang-5.0', 'ninja-build', 'nodejs']
205205

206206
- os: linux
207207
compiler: clang
@@ -211,7 +211,7 @@ matrix:
211211
addons:
212212
apt:
213213
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-6.0']
214-
packages: ['g++-6', 'clang-6.0', 'ninja-build']
214+
packages: ['g++-6', 'clang-6.0', 'ninja-build', 'nodejs']
215215

216216
- os: linux
217217
compiler: clang
@@ -222,19 +222,19 @@ matrix:
222222
addons:
223223
apt:
224224
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-6.0']
225-
packages: ['g++-6', 'clang-6.0', 'ninja-build']
225+
packages: ['g++-6', 'clang-6.0', 'ninja-build', 'nodejs']
226226

227227
################
228228
# build script #
229229
################
230230

231-
script:
231+
install:
232232
# get CMake and Ninja (only for systems with brew - macOS)
233233
- |
234234
if [[ (-x $(which brew)) ]]; then
235235
brew update
236-
brew install cmake ninja
237-
brew upgrade cmake
236+
brew install cmake ninja node
237+
brew upgrade cmake node
238238
cmake --version
239239
else
240240
wget -O cmake.sh https://cmake.org/files/v3.10/cmake-3.10.0-rc1-Linux-x86_64.sh
@@ -243,6 +243,11 @@ script:
243243
export PATH=/tmp/cmake/bin:$PATH
244244
fi
245245
246+
# install node forever module
247+
- npm install -g forever
248+
# start test server
249+
- forever start tests/server/server.js
250+
246251
# make sure CXX is correctly set
247252
- if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; export CC=${CCOMPILER}; fi
248253

@@ -251,8 +256,13 @@ script:
251256
- $CC --version
252257
- $CXX --version
253258

259+
script:
254260
# compile and execute unit tests
255261
- mkdir -p build && cd build
256262
- cmake .. ${CMAKE_OPTIONS} -DCROW_BUILD_LOG4CPLUS=ON -GNinja && cmake --build . --config Release
257263
- ctest -C Release -V -j
258264
- cd ..
265+
266+
after_script:
267+
# shut down test server
268+
- forever stop tests/server/server.js

CMakeLists.txt

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.10)
22
cmake_policy(SET CMP0048 NEW)
3-
project(crow VERSION 0.0.4)
3+
project(crow VERSION 0.0.5)
44

55
##############################
66
# check for required headers #
@@ -103,7 +103,7 @@ find_package(Threads)
103103
# library #
104104
###########
105105

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

139-
get_target_property(CROW_SOURCES crow SOURCES)
140-
add_executable(tests tests/unittests.cpp ${CROW_SOURCES})
141-
set_target_properties(tests PROPERTIES CXX_STANDARD 11)
142-
target_include_directories(tests PUBLIC tests include ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
143-
target_link_libraries(tests ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
139+
add_executable(unittests tests/unittests.cpp)
140+
set_target_properties(unittests PROPERTIES CXX_STANDARD 11)
141+
target_include_directories(unittests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} tests)
142+
target_link_libraries(unittests crow)
143+
add_test(NAME unittests COMMAND unittests)
144+
145+
# std::current_exception is broken with MSVC (https://developercommunity.visualstudio.com/content/problem/135332/stdcurrent-exception-returns-null-in-a-stdterminat.html)
146+
if (NOT MSVC)
147+
add_executable(uncaught_exception tests/uncaught_exception.cpp)
148+
set_target_properties(uncaught_exception PROPERTIES CXX_STANDARD 11)
149+
target_link_libraries(uncaught_exception crow)
150+
add_test(NAME uncaught_exception COMMAND uncaught_exception)
151+
endif()
144152

145153
add_executable(livetest tests/livetest.cpp)
146154
set_target_properties(livetest PROPERTIES CXX_STANDARD 11)
147-
target_include_directories(livetest PUBLIC include ${CMAKE_CURRENT_BINARY_DIR})
155+
target_include_directories(livetest PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
148156
target_link_libraries(livetest crow)
149-
150-
add_test(tests tests)
151-
add_test(livetest livetest)
157+
add_test(NAME livetest COMMAND livetest)
152158

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

166-
add_executable(log4cplus_example examples/log4cplus/example.cpp)
172+
add_executable(log4cplus_example examples/log4cplus/example.cpp include/crow/integrations/loggers.hpp include/crow/integrations/log4cplus.hpp)
167173
set_target_properties(log4cplus_example PROPERTIES CXX_STANDARD 11)
168174
target_include_directories(log4cplus_example PUBLIC include ${install_dir}/include)
169175
target_link_libraries(log4cplus_example log4cplus crow)
170-
171-
add_test(log4cplus_example log4cplus_example)
176+
add_test(NAME log4cplus_example COMMAND log4cplus_example)
172177
endif()
173178
endif()
174179

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
### Setup
1616

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

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

6262
## Change Log
6363

64+
### Version 0.0.5
65+
66+
- :sparkles: added event sampling
67+
- :white_check_mark: added testing server to mock Sentry
68+
- :memo: added example code
69+
- :hammer: overworked threading
70+
6471
### Version 0.0.4
6572

6673
- :sparkles: added Log4cplus integration

appveyor.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ install:
4848
- if "%COMPILER%"=="mingw" set PATH=C:\projects\deps\ninja;%PATH%
4949
- if "%COMPILER%"=="mingw" set PATH=C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin;%PATH%
5050
- if "%COMPILER%"=="mingw" g++ --version
51+
- ps: Install-Product node 6
52+
- npm install -g forever
5153

5254
before_build:
5355
- curl https://curl.haxx.se/download/curl-7.61.0.zip -O
@@ -59,5 +61,11 @@ before_build:
5961
build_script:
6062
- cmake --build . --config Release
6163

64+
before_test:
65+
- forever start tests/server/server.js
66+
6267
test_script:
63-
- ctest -C Release -V -j --output-on-failure --verbose
68+
- ctest -C Release -V --output-on-failure --verbose
69+
70+
on_finish:
71+
- forever stop tests/server/server.js

doc/Doxyfile.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ ENABLED_SECTIONS =
9595
MAX_INITIALIZER_LINES = 30
9696
SHOW_USED_FILES = NO
9797
SHOW_FILES = NO
98-
SHOW_NAMESPACES = NO
98+
SHOW_NAMESPACES = YES
9999
FILE_VERSION_FILTER =
100100
LAYOUT_FILE =
101101
CITE_BIB_FILES =
@@ -115,7 +115,7 @@ WARN_LOGFILE =
115115
#---------------------------------------------------------------------------
116116
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/include/crow @CMAKE_CURRENT_SOURCE_DIR@/src \
117117
@CMAKE_CURRENT_SOURCE_DIR@/examples \
118-
@CMAKE_CURRENT_BINARY_DIR@/include/crow @CMAKE_CURRENT_SOURCE_DIR@/README.md
118+
@CMAKE_CURRENT_BINARY_DIR@/src @CMAKE_CURRENT_SOURCE_DIR@/README.md
119119
INPUT_ENCODING = UTF-8
120120
FILE_PATTERNS = *.c \
121121
*.cc \
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
project(crow_example)
4+
5+
include(ExternalProject)
6+
ExternalProject_Add(crow_project
7+
GIT_REPOSITORY https://github.com/nlohmann/crow
8+
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/crow
9+
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/crow -DCROW_BUILD_TESTING=OFF
10+
BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/log4cplus/lib/${CMAKE_SHARED_LIBRARY_PREFIX}crow${CMAKE_SHARED_LIBRARY_SUFFIX}
11+
)
12+
ExternalProject_Get_Property(crow_project install_dir)
13+
add_library(crow SHARED IMPORTED)
14+
set_target_properties(crow PROPERTIES IMPORTED_LOCATION ${install_dir}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}crow${CMAKE_SHARED_LIBRARY_SUFFIX})
15+
add_dependencies(crow crow_project)
16+
17+
add_executable(example example.cpp)
18+
target_link_libraries(example crow)
19+
set_target_properties(example PROPERTIES CXX_STANDARD 11)

examples/integration/example.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <crow/crow.hpp>
2+
3+
using nlohmann::crow;
4+
5+
int main()
6+
{
7+
crow client("http://abc:[email protected]/42");
8+
9+
client.add_breadcrumb("this is a breadcrumb");
10+
client.capture_message("this is a message");
11+
}

0 commit comments

Comments
 (0)