-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(apple): Using Sentry within an SDK #14973
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8abf3e1
feat(apple):Using Sentry withing an SDK
philipphofmann 743ec28
Update docs/platforms/apple/common/configuration/shared-environments.mdx
philipphofmann f05dd5a
Update docs/platforms/apple/common/configuration/shared-environments.mdx
philipphofmann f0d0d66
Merge branch 'master' into feat/apple-sentry-within-sdk
philipphofmann 70f2e7f
phils input
philipphofmann 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
45 changes: 45 additions & 0 deletions
45
docs/platforms/apple/common/configuration/shared-environments.mdx
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,45 @@ | ||
--- | ||
title: Using Sentry within an SDK | ||
description: "Learn how to use the Sentry SDK within a shared environment, e.g. another SDK." | ||
philipphofmann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
sidebar_order: 2000 | ||
--- | ||
|
||
<Alert> | ||
|
||
Using the Sentry SDK within another SDK is [discouraged](/platforms/). This can lead to unexpected behaviour and potential data leakage. If you need to use Sentry within another SDK, please follow the best practices outlined below. | ||
philipphofmann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
</Alert> | ||
|
||
<Alert> | ||
|
||
When setting up Sentry inside a library, the consuming app could use the Sentry SDK as well, thus you should **not use `SentrySDK.start()`**, as this will pollute the global state. | ||
|
||
</Alert> | ||
|
||
In order to not conflict with other Sentry instances, you should use the `Hub` API to create a new instance of Sentry. The Hub API works the similarly as the global Sentry instance, but it is not global and can be used within your component. | ||
|
||
```swift | ||
import Sentry | ||
|
||
let options = Options() | ||
options.dsn = "___PUBLIC_DSN___" | ||
|
||
let client = SentryClient(options: options) | ||
|
||
// You don't need to pass a scope. The hub will create a new scope for you automatically. | ||
// Furthermore, the SDK enriches it with some contexts automatically, such as app, OS and | ||
// device context. | ||
let hub = SentryHub(client: client, andScope: nil) | ||
|
||
philipphofmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
hub.capture(message: "Hello from your SDK!") | ||
``` | ||
|
||
If your SDK can be opened and closed multiple times, you should also close the `Hub` when you are done: | ||
|
||
```swift | ||
hub.close() | ||
``` | ||
|
||
Capturing crashes, watchdog terminations or app hangs aren't supported by the `Hub` API, because they depend on the global Sentry instance. | ||
|
||
To symbolicate stacktraces of your events, Sentry requires dSYMs (debug information files). Depending on your setup, you might not be able to get these, but if you can, visit <PlatformLink to="/dsym/">Uploading Debug Symbols</PlatformLink> for more information on how to upload them. |
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.