-
-
Notifications
You must be signed in to change notification settings - Fork 215
feat(internal): add platform integration hook #2005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jpnurmi
wants to merge
6
commits into
master
Choose a base branch
from
jpnurmi/feat/platform-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6388904
feat(native): add platform integration hook
jpnurmi 818f6be
fix llvm-cov
jpnurmi 3d4f3b3
SENTRY_INTEGRATION_PLATFORM
jpnurmi bdd77ec
test: allow "initial" observers injected by platform integrations
jpnurmi 0892a09
add TODO comment
jpnurmi 1019c1f
reorder platform integration first
jpnurmi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; | ||
|
jpnurmi marked this conversation as resolved.
|
||
| 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); | ||
|
jpnurmi marked this conversation as resolved.
|
||
| 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(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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": "ON", | ||
| }, | ||
| ) | ||
|
|
||
| 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"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.