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
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ option(SENTRY_BUILD_TESTS "Build sentry-native tests" "${SENTRY_MAIN_PROJECT}")
option(SENTRY_BUILD_EXAMPLES "Build sentry-native example(s)" "${SENTRY_MAIN_PROJECT}")
option(SENTRY_BUILD_BENCHMARKS "Build sentry-native benchmarks" OFF)

set(SENTRY_INTEGRATION_PLATFORM "" CACHE STRING
"Downstream-provided platform integration to create automatically")
if(NOT SENTRY_INTEGRATION_PLATFORM STREQUAL ""
AND NOT SENTRY_INTEGRATION_PLATFORM MATCHES "^[A-Za-z_][A-Za-z0-9_]*$")
message(FATAL_ERROR
"SENTRY_INTEGRATION_PLATFORM must be empty or a valid C identifier")
endif()

# Platform version embedding options
option(SENTRY_EMBED_INFO "Embed version information in binary" OFF)
set(SENTRY_BUILD_PLATFORM "${CMAKE_SYSTEM_NAME}" CACHE STRING "Platform name for embedded version (e.g., switch, playstation, xbox)")
Expand Down Expand Up @@ -298,6 +306,7 @@ 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}")
message(STATUS "SENTRY_INTEGRATION_PLATFORM=${SENTRY_INTEGRATION_PLATFORM}")
message(STATUS "SENTRY_HANDLER_STACK_SIZE=${SENTRY_HANDLER_STACK_SIZE}")
message(STATUS "SENTRY_BATCHER_BUFFER_COUNT=${SENTRY_BATCHER_BUFFER_COUNT}")
if (WIN32)
Expand Down Expand Up @@ -419,6 +428,10 @@ endif()

add_subdirectory(src)

if(NOT SENTRY_INTEGRATION_PLATFORM STREQUAL "")
target_compile_definitions(sentry PRIVATE SENTRY_INTEGRATION_PLATFORM)
endif()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Platform define stays private

Medium Severity

SENTRY_INTEGRATION_PLATFORM is added as a PRIVATE compile definition on sentry, so downstream translation units never see it. The extern "C" declaration of sentry_integration_platform_new in sentry_integration.h is therefore hidden from C++ platform SDKs, which will emit a mangled symbol the C library cannot resolve. Consumers also still see sentry__native_init in sentry_core.h even though the library now exports sentry_init.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 958c654. Configure here.


target_compile_definitions(sentry PRIVATE SENTRY_HANDLER_STACK_SIZE=${SENTRY_HANDLER_STACK_SIZE})
target_compile_definitions(sentry PRIVATE SENTRY_BATCHER_BUFFER_COUNT=${SENTRY_BATCHER_BUFFER_COUNT})
if(WIN32)
Expand Down Expand Up @@ -1030,6 +1043,9 @@ if(SENTRY_BUILD_TESTS)
add_subdirectory(tests/unit)
add_subdirectory(tests/fixtures/crash_reporter)
add_subdirectory(tests/fixtures/early_init)
if(SENTRY_INTEGRATION_PLATFORM STREQUAL "test")
add_subdirectory(tests/fixtures/test_platform)
endif()
add_subdirectory(tests/fixtures/screenshot)
if(WIN32 AND NOT XBOX)
add_subdirectory(tests/fixtures/appx)
Expand Down
5 changes: 3 additions & 2 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ unregister_integrations(sentry_scope_t *scope, const sentry_options_t *options)
}
}

#if defined(SENTRY_PLATFORM_NX) || defined(SENTRY_PLATFORM_PS) \
|| defined(SENTRY_PLATFORM_XBOX)
#if (defined(SENTRY_PLATFORM_NX) || defined(SENTRY_PLATFORM_PS) \
|| defined(SENTRY_PLATFORM_XBOX)) \
&& !defined(SENTRY_INTEGRATION_PLATFORM)
int
sentry__native_init(sentry_options_t *options)
#else
Expand Down
5 changes: 3 additions & 2 deletions src/sentry_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ bool sentry__should_send_transaction(
sentry_value_t tx_ctx, sentry_sampling_context_t *sampling_ctx);
#endif

#if defined(SENTRY_PLATFORM_NX) || defined(SENTRY_PLATFORM_PS) \
|| defined(SENTRY_PLATFORM_XBOX)
#if (defined(SENTRY_PLATFORM_NX) || defined(SENTRY_PLATFORM_PS) \
|| defined(SENTRY_PLATFORM_XBOX)) \
&& !defined(SENTRY_INTEGRATION_PLATFORM)
int sentry__native_init(sentry_options_t *options);
#endif

Expand Down
12 changes: 12 additions & 0 deletions src/sentry_integration.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ typedef struct sentry_integration_s {
void (*free_func)(void *data);
} sentry_integration_t;

#ifdef SENTRY_INTEGRATION_PLATFORM
# ifdef __cplusplus
extern "C" {
# endif

sentry_integration_t *sentry_integration_platform_new(void);

# ifdef __cplusplus
}
# endif
#endif

#endif
14 changes: 11 additions & 3 deletions src/sentry_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ sentry_options_new(void)
#ifdef SENTRY_INTEGRATION_WER
sentry__options_add_integration(opts, sentry_integration_wer_new());
#endif
#ifdef SENTRY_INTEGRATION_PLATFORM
if (!sentry__options_add_integration(
opts, sentry_integration_platform_new())) {
sentry_options_free(opts);
return NULL;
}
#endif

return opts;
}
Expand Down Expand Up @@ -980,20 +987,20 @@ sentry_options_set_backend(sentry_options_t *opts, sentry_backend_t *backend)
opts->backend = backend;
}

void
bool
sentry__options_add_integration(
sentry_options_t *opts, sentry_integration_t *integration)
{
if (!integration) {
return;
return false;
}

size_t new_count = opts->num_integrations + 1;
sentry_integration_t **integrations
= sentry__calloc(new_count, sizeof(sentry_integration_t *));
if (!integrations) {
free_integration(integration);
return;
return false;
}

for (size_t i = 0; i < opts->num_integrations; i++) {
Expand All @@ -1003,6 +1010,7 @@ sentry__options_add_integration(
sentry_free(opts->integrations);
opts->integrations = integrations;
opts->num_integrations = new_count;
return true;
}

bool
Expand Down
4 changes: 3 additions & 1 deletion src/sentry_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ const char *sentry__options_get_org_id(const sentry_options_t *options);
*
* Takes ownership of `integration`. If the integration owns `data`, it must
* provide `free_func`.
*
* Returns true if the integration was added.
*/
void sentry__options_add_integration(
bool sentry__options_add_integration(
sentry_options_t *opts, sentry_integration_t *integration);

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/fixtures/test_platform/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.10)
project(sentry_test_platform LANGUAGES C)

target_compile_definitions(sentry PRIVATE
SENTRY_SDK_NAME="sentry.native.test")

add_executable(sentry_test_platform test_platform.c)
target_include_directories(sentry_test_platform PRIVATE ${SENTRY_SOURCE_DIR}/src)
target_link_libraries(sentry_test_platform PRIVATE sentry)
46 changes: 46 additions & 0 deletions tests/fixtures/test_platform/test_platform.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "sentry_alloc.h"
#include "sentry_integration.h"
#include "sentry_scope.h"

static void
register_platform(
void *data, sentry_scope_t *scope, const sentry_options_t *options)
{
(void)data;
(void)options;

sentry_value_t device = sentry_value_new_object();
sentry_value_set_by_key(device, "name", sentry_value_new_string("Test"));
sentry_value_set_by_key(
device, "model", sentry_value_new_string("test-model"));
sentry_value_set_by_key(
device, "arch", sentry_value_new_string("test-arch"));
sentry_scope_set_context(scope, "device", device);
}

sentry_integration_t *
sentry_integration_platform_new(void)
{
sentry_integration_t *integration = SENTRY_MAKE(sentry_integration_t);
integration->name = "test";
integration->register_func = register_platform;
return integration;
}

int
main(void)
{
sentry_options_t *options = sentry_options_new();
sentry_options_set_auto_session_tracking(options, 0);
sentry_options_set_debug(options, true);
sentry_init(options);

sentry_set_tag("my-tag", "my-value");
sentry_set_user(sentry_value_new_user("123", "my-user", NULL, NULL));

sentry_value_t event = sentry_value_new_message_event(
SENTRY_LEVEL_INFO, "my-logger", "Hello World!");
sentry_capture_event(event);

sentry_close();
}
63 changes: 63 additions & 0 deletions tests/test_integration_platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import os

import pytest

from . import Envelope, SENTRY_VERSION, make_dsn, run
from .conditions import has_http

pytestmark = pytest.mark.skipif(not has_http, reason="tests need http transport")


def test_platform_integration(cmake, httpserver):
cwd = cmake(
["sentry_test_platform"],
{
"SENTRY_BACKEND": "none",
"SENTRY_BUILD_SHARED_LIBS": "OFF",
"SENTRY_INTEGRATION_PLATFORM": "test",
},
)

httpserver.expect_oneshot_request("/api/123456/envelope/").respond_with_data("OK")

run(
cwd,
"sentry_test_platform",
[],
env=dict(os.environ, SENTRY_DSN=make_dsn(httpserver)),
)

assert len(httpserver.log) == 1
envelope = Envelope.deserialize(httpserver.log[0][0].get_data())

(item,) = envelope.items
assert item.headers["type"] == "event"
event = item.payload.json

# SDK
assert event["platform"] == "native"
assert event["environment"] == "production"
assert event["event_id"]
assert event["contexts"]["os"]["name"]
assert len(event["contexts"]["trace"]["trace_id"]) == 32
assert len(event["contexts"]["trace"]["span_id"]) == 16
assert event["sdk"]["version"] == SENTRY_VERSION
assert event["sdk"]["packages"] == [
{
"name": "github:getsentry/sentry-native",
"version": SENTRY_VERSION,
}
]

# platform integration
assert event["contexts"]["device"] == {
"name": "Test",
"model": "test-model",
"arch": "test-arch",
}
assert event["sdk"]["name"] == "sentry.native.test"
assert event["sdk"]["integrations"].count("test") == 1

# app
assert event["tags"] == {"my-tag": "my-value"}
assert event["user"] == {"id": "123", "username": "my-user"}
2 changes: 1 addition & 1 deletion tests/unit/test_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ SENTRY_TEST(client_sdk_integrations)
sentry_integration_t *integration = SENTRY_MAKE(sentry_integration_t);
TEST_ASSERT(!!integration);
integration->name = "custom";
sentry__options_add_integration(options, integration);
TEST_ASSERT(sentry__options_add_integration(options, integration));

sentry_init(options);

Expand Down
Loading