Skip to content

Commit 72cbdce

Browse files
rhcarvalhokamilogorekMimiDumpling
committed
Revise Shutdown and Draining section
Co-Authored-By: Kamil Ogórek <[email protected]> Co-Authored-By: Tien "Mimi" Nguyen <[email protected]>
1 parent 6827c29 commit 72cbdce

File tree

6 files changed

+41
-25
lines changed

6 files changed

+41
-25
lines changed
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
The client provides a `Flush` method that takes the time in `time.Duration` for how long it waits and will return a boolean that indicates whether everything was flushed or the timeout kicked in.
1+
To avoid unintentionally dropping events when the program terminates, arrange
2+
for `sentry.Flush` to be called, typically using `defer`.
3+
4+
If you use multiple clients, arrange for each of them to be flushed as
5+
appropriate.
6+
7+
`Flush` waits until any buffered events are sent to the Sentry server, blocking
8+
for at most the given timeout. It returns `false` if the timeout was reached. In
9+
that case, some events may not have been sent.
210

311
```go
4-
sentry.CaptureMessage("my message")
12+
func main() {
13+
// err := sentry.Init(...)
14+
defer sentry.Flush(2 * time.Second)
515

6-
if sentry.Flush(time.Second * 2) {
7-
fmt.Println("All queued events delivered!")
8-
} else {
9-
fmt.Println("Flush timeout reached")
16+
sentry.CaptureMessage("my message")
1017
}
1118
```
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
The client provides a close method that optionally takes the time in milliseconds for how long it
2-
waits and will return a promise that resolves when everything was flushed or the timeout kicked
1+
The `close` method optionally takes a timeout in milliseconds and returns a
2+
promise that resolves when all pending events are flushed, or the timeout kicks
33
in.
44

55
```javascript
6-
const client = Sentry.getCurrentHub().getClient();
7-
if (client) {
8-
client.close(2000).then(function() {
9-
process.exit();
10-
});
11-
}
6+
Sentry.close(2000).then(function() {
7+
process.exit();
8+
});
129
```
10+
11+
After a call to `close`, the current client cannot be used anymore. It's
12+
important to only call `close` immediately before shutting down the application.
13+
14+
Alternatively, the `flush` method drains the event queue while keeping the
15+
client enabled for continued use.

src/collections/_documentation/error-reporting/configuration/drain-example/native.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ sentry_shutdown();
66

77
Calling `sentry_shutdown()` before exiting the application is critical to avoid
88
data loss.
9+
10+
After shutdown, the client cannot be used anymore. It's important to only call
11+
`sentry_shutdown()` immediately before shutting down the application.

src/collections/_documentation/error-reporting/configuration/drain-example/python.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ client = Hub.current.client
88
if client is not None:
99
client.close(timeout=2.0)
1010
```
11+
12+
After a call to `close`, the client cannot be used anymore. It's important to
13+
only call `close` immediately before shutting down the application.
14+
15+
Alternatively, the `flush` method drains the event queue while keeping the
16+
client enabled for continued use.

src/collections/_documentation/error-reporting/configuration/drain-example/rust.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ When the Rust SDK initializes a guard is returned from the `init` function. The
22
will automatically wait `shutdown_timeout` seconds. This means you just need to hold on to
33
the guard and make sure it disposes on shutdown. Alternatively the client can be closed:
44

5-
```javascript
5+
```rust
66
use std::time::Duration;
77
use sentry::Hub;
88

99
if let Some(client) = Hub.current().client() {
1010
client.close(Some(Duration::from_secs(2)));
1111
}
1212
```
13+
14+
After a call to `close`, the client cannot be used anymore. It's important to
15+
only call `close` immediately before shutting down the application.

src/collections/_documentation/error-reporting/configuration/draining.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@ title: 'Shutdown and Draining'
33
sidebar_order: 1
44
---
55

6-
Most SDKs use a background queue to send out events. Because the queue sends asynchronously in the background
7-
it means that some events might be lost if the application shuts down unexpectedly. To prevent this all SDKs
8-
provide mechanisms to cope with this.
9-
10-
Typically SDKs provide two ways to shut down: a controlled shutdown where the system will wait up to about two
11-
seconds to flush out events (configurable) and an uncontrolled shutdown (also referred to as "killing" the
12-
client).
6+
The default behavior of most SDKs is to send out events over the network
7+
asynchronously in the background. This means that some events might be lost if
8+
the application shuts down unexpectedly. The SDKs provide mechanisms to cope
9+
with this.
1310

1411
{% include components/platform_content.html content_dir='drain-example' %}
15-
16-
After shutdown the client cannot be used any more so make sure to only do that right before you shut down
17-
the application.

0 commit comments

Comments
 (0)