Skip to content

Commit

Permalink
feat: SDK name override (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind authored Mar 9, 2022
1 parent 47d0156 commit 15a1229
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Features**:

- Removed the `SENTRY_PERFORMANCE_MONITORING` compile flag requirement to access performance monitoring in the Sentry SDK. Performance monitoring is now available to everybody who has opted into the experimental API.
- Allow overriding the SDK name at build time - set the `SENTRY_SDK_NAME` CMake cache variable.

## 0.4.15

Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,12 @@ if(SENTRY_BACKEND_CRASHPAD AND ANDROID)
message(FATAL_ERROR "The Crashpad backend is not currently supported on Android")
endif()

set(SENTRY_SDK_NAME "" CACHE STRING "The SDK name to report when sending events.")

message(STATUS "SENTRY_TRANSPORT=${SENTRY_TRANSPORT}")
message(STATUS "SENTRY_BACKEND=${SENTRY_BACKEND}")
message(STATUS "SENTRY_LIBRARY_TYPE=${SENTRY_LIBRARY_TYPE}")
message(STATUS "SENTRY_SDK_NAME=${SENTRY_SDK_NAME}")

if(ANDROID)
set(SENTRY_WITH_LIBUNWINDSTACK TRUE)
Expand Down Expand Up @@ -221,6 +224,10 @@ target_sources(sentry PRIVATE "${PROJECT_SOURCE_DIR}/include/sentry.h")
add_library(sentry::sentry ALIAS sentry)
add_subdirectory(src)

if (NOT SENTRY_SDK_NAME STREQUAL "")
target_compile_definitions(sentry PRIVATE SENTRY_SDK_NAME="${SENTRY_SDK_NAME}")
endif()

# we do not need this on android, only linux
if(LINUX)
target_sources(sentry PRIVATE
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,17 @@ Legend:

- `SENTRY_FOLDER` (Default: not defined):
Sets the sentry-native projects folder name for generators which support project hierarchy (like Microsoft Visual Studio).
To use this feature you need to enable hierarchy via [`USE_FOLDERS` property](https://cmake.org/cmake/help/latest/prop_gbl/USE_FOLDERS.html)
To use this feature you need to enable hierarchy via [`USE_FOLDERS` property](https://cmake.org/cmake/help/latest/prop_gbl/USE_FOLDERS.html)

- `CRASHPAD_ENABLE_STACKTRACE` (Default: OFF):
This enables client-side stackwalking when using the crashpad backend. Stack unwinding will happen on the client's machine
and the result will be submitted to Sentry attached to the generated minidump.
Note that this feature is still experimental.

- `SENTRY_SDK_NAME` (Default: sentry.native or sentry.native.android):
Sets the SDK name that should be included in the reported events. If you're overriding this, make sure to also define
the same value using `target_compile_definitions()` on your own targets that include `sentry.h`.

### Build Targets

- `sentry`: This is the main library and the only default build target.
Expand Down
10 changes: 6 additions & 4 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ extern "C" {
#endif

/* SDK Version */
#ifdef __ANDROID__
# define SENTRY_SDK_NAME "sentry.native.android"
#else
# define SENTRY_SDK_NAME "sentry.native"
#ifndef SENTRY_SDK_NAME
# ifdef __ANDROID__
# define SENTRY_SDK_NAME "sentry.native.android"
# else
# define SENTRY_SDK_NAME "sentry.native"
# endif
#endif
#define SENTRY_SDK_VERSION "0.4.15"
#define SENTRY_SDK_USER_AGENT SENTRY_SDK_NAME "/" SENTRY_SDK_VERSION
Expand Down
4 changes: 4 additions & 0 deletions tests/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def assert_meta(
release="test-example-release",
integration=None,
transaction="test-transaction",
sdk_override=None,
):
event = envelope.get_event()

Expand Down Expand Up @@ -94,6 +95,9 @@ def assert_meta(
)
assert event["contexts"]["os"]["build"] is not None

if sdk_override != None:
expected_sdk["name"] = sdk_override

assert_matches(event, expected)
assert_matches(event["sdk"], expected_sdk)
assert_matches(
Expand Down
22 changes: 22 additions & 0 deletions tests/test_integration_stdout.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ def test_capture_stdout(cmake):
assert_event(envelope)


def test_sdk_name_override(cmake):
sdk_name = "cUsToM.SDK"
tmp_path = cmake(
["sentry_example"],
{
"SENTRY_BACKEND": "none",
"SENTRY_TRANSPORT": "none",
"SENTRY_SDK_NAME": sdk_name,
},
)

output = check_output(
tmp_path,
"sentry_example",
["stdout", "capture-event"],
)
envelope = Envelope.deserialize(output)

assert_meta(envelope, sdk_override=sdk_name)
assert_event(envelope)


@pytest.mark.skipif(not has_files, reason="test needs a local filesystem")
def test_multi_process(cmake):
# NOTE: It would have been nice to do *everything* in a unicode-named
Expand Down

0 comments on commit 15a1229

Please sign in to comment.