Skip to content

Commit

Permalink
Sentry sink docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Nov 26, 2024
1 parent f65a414 commit 327c947
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 5 deletions.
Binary file modified docs/bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions docs/manual/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ JavaScript runtimes and package managers:
:::code-group

~~~~ sh [Deno]
deno add @logtape/logtape
deno add jsr:@logtape/logtape
~~~~

~~~~ sh [npm]
Expand Down Expand Up @@ -61,8 +61,8 @@ bun add @logtape/logtape@dev
> to specify the specific version number of the unstable release:
>
> ~~~~ sh
> deno add @logtape/[email protected] # Replace 1.2.3-dev.4 with the actual version number
> deno add jsr:@logtape/[email protected] # Replace 1.2.3-dev.4 with the actual version number
> ~~~~
[JSR]: https://jsr.io/@logtape/logtape
[npm]: https://www.npmjs.com/package/@logtape/logtape
[npm]: https://www.npmjs.com/package/@logtape/logtape
85 changes: 84 additions & 1 deletion docs/manual/sinks.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ sink to send log messages to the collector using [@logtape/otel] package:
::: code-group

~~~~ sh [Deno]
deno add @logtape/otel
deno add jsr:@logtape/otel
~~~~

~~~~ sh [npm]
Expand Down Expand Up @@ -304,6 +304,89 @@ For more details, see the documentation of [@logtape/otel].
[`getOpenTelemetrySink()`]: https://jsr.io/@logtape/otel/doc/~/getOpenTelemetrySink


Sentry sink
-----------

If you are using [Sentry] for error monitoring, you can use the Sentry sink to
send log messages to Sentry using [@logtape/sentry] package:

::: code-group

~~~~ sh [Deno]
deno add jsr:@logtape/sentry
~~~~

~~~~ sh [npm]
npm add @logtape/sentry
~~~~

~~~~ sh [pnpm]
pnpm add @logtape/sentry
~~~~

~~~~ sh [Yarn]
yarn add @logtape/sentry
~~~~

~~~~ sh [Bun]
bun add @logtape/sentry
~~~~

:::

The quickest way to get started is to use the [`getSentrySink()`] function
without any arguments:

~~~~ typescript twoslash
import { configure } from "@logtape/logtape";
import { getSentrySink } from "@logtape/sentry";

await configure({
sinks: {
sentry: getSentrySink(),
},
filters: {},
loggers: [
{ category: [], sinks: ["sentry"], level: "debug" },
],
});
~~~~

The log records will show up in the breadcrumbs of the Sentry issues:

![LogTape records show up in the breadcrumbs of a Sentry issue.](https://raw.githubusercontent.com/dahlia/logtape-sentry/refs/heads/main/screenshot.png)

If you want to explicitly configure the Sentry client, you can pass
the [`Client`] instance to the [`getSentrySink()`] function:

~~~~ typescript twoslash
import { configure } from "@logtape/logtape";
import { getSentrySink } from "@logtape/sentry";
import { init } from "@sentry/node";

const client = init({
dsn: process.env.SENTRY_DSN,
});

await configure({
sinks: {
sentry: getSentrySink(client),
},
filters: {},
loggers: [
{ category: [], sinks: ["sentry"], level: "debug" },
],
});
~~~~

For more details, see the documentation of [@logtape/sentry].

[Sentry]: https://sentry.io/
[@logtape/sentry]: https://github.com/dahlia/logtape-sentry
[`getSentrySink()`]: https://jsr.io/@logtape/sentry/doc/~/getSentrySink
[`Client`]: https://getsentry.github.io/sentry-javascript/interfaces/_sentry_types.Client.html


Disposable sink
---------------

Expand Down
5 changes: 4 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"dependencies": {},
"dependencies": {
"@logtape/sentry": "^0.1.0",
"@sentry/node": "^8.40.0"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@cloudflare/workers-types": "^4.20240909.0",
Expand Down

0 comments on commit 327c947

Please sign in to comment.