Skip to content

Commit 07f464c

Browse files
committed
feat: add typescript, other improvements
Release-As: 0.1.0
1 parent ef0aa2b commit 07f464c

File tree

11 files changed

+613
-229
lines changed

11 files changed

+613
-229
lines changed

.github/release-please-config.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
}
1010
},
1111
"changelog-sections": [
12-
{ "type": "build", "section": "Maintenance" },
13-
{ "type": "chore", "section": "Maintenance" },
14-
{ "type": "ci", "section": "Maintenance" },
15-
{ "type": "deps", "section": "Dependency updates" },
16-
{ "type": "docs", "section": "Documentation" },
17-
{ "type": "style", "section": "Styles" },
18-
{ "type": "refactor", "section": "Refactors" },
19-
{ "type": "test", "section": "Tests", "hidden": true }
12+
{ "section": "Features", "type": "feat" },
13+
{ "section": "Dependency updates", "type": "deps" },
14+
{ "section": "Documentation", "type": "docs" },
15+
{ "section": "Maintenance", "type": "build" },
16+
{ "section": "Maintenance", "type": "chore" },
17+
{ "section": "Maintenance", "type": "ci" },
18+
{ "section": "Refactors", "type": "refactor" },
19+
{ "section": "Styles", "type": "style" },
20+
{ "section": "Tests", "type": "test", "hidden": true }
2021
]
2122
}

.github/workflows/release-please.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131

3232
- if: ${{ steps.release.outputs.release_created }}
3333
run: |
34+
npm ci &&
35+
npm run build &&
3436
npm publish --provenance --access public
3537
env:
3638
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
dist
2+
node_modules

README.md

Lines changed: 73 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# Sentry log4js appender
1+
# log4js appender - Sentry
22

33
Sends logging events to Sentry. This appender integrates
44
[@sentry/node][sentry_javascript].
55

6+
[sentry_javascript]: https://github.com/getsentry/sentry-javascript
7+
68
## Installation
79

810
**npm registry**
@@ -11,63 +13,92 @@ Sends logging events to Sentry. This appender integrates
1113
npm install log4js-appender-sentry
1214
```
1315

14-
## Options
16+
## Configuration
1517

16-
The [`SentryAppender`][internal_types] interface extends the `NodeClientOptions`
17-
interface and provides additional options specific to the Node Sentry appender
18-
SDK.
18+
### TypeScript
19+
20+
If you're using TypeScript, importing this library as a side effect will
21+
automatically merge the log4js interface `Appenders`. This merging enables
22+
autocomplete for the appenders configuration, providing convenient access to its
23+
properties.
24+
25+
```ts
26+
import "log4js-appender-sentry";
27+
```
28+
29+
### Example
30+
31+
```ts
32+
import log4js from "log4js";
33+
34+
import "log4js-appender-cloudwatch";
35+
36+
log4js.configure({
37+
appenders: {
38+
sentry: {
39+
type: "log4js-appender-sentry",
40+
dsn: "<config>",
41+
user: {
42+
// ...
43+
},
44+
},
45+
},
46+
categories: {
47+
default: {
48+
level: "debug",
49+
appenders: [
50+
"sentry",
51+
],
52+
},
53+
},
54+
});
55+
56+
const log = log4js.getLogger();
57+
// ...
58+
```
59+
60+
## Options
1961

2062
Sentry is mainly used to report application errors so the default log level is
2163
`WARN` and above, other log levels will be ignored.
2264

23-
**`type`**
65+
### type
2466

25-
The type of the appender, must be set to `log4js-appender-sentry`.
67+
_Required_\
68+
Type: log4js-appender-sentry
2669

27-
**`dsn`**
70+
The type of the appender. Must be set to `log4js-appender-sentry`.
2871

29-
A DSN tells a Sentry SDK where to send events so the events are associated with
30-
the correct project. See [documentation][sentry_dsn].
72+
### dsn
3173

32-
**`user`**
74+
_Required_\
75+
Type: `string`
3376

34-
User data for scope configuration. See [documentation][sentry_user].
77+
A DSN (Data Source Name) specifies where the Sentry SDK should send events,
78+
ensuring they are associated with the correct project. Refer to the Sentry
79+
[documentation][sentry_dsn] for more details on DSN.
3580

36-
## Configuration
81+
[sentry_dsn]: https://docs.sentry.io/product/sentry-basics/dsn-explainer/
3782

38-
**TypeScript**
83+
### user
3984

40-
If you're using TypeScript, importing this library as a side effect will
41-
automatically merge the log4js interface `Appenders`. This merging enables
42-
autocomplete for the appenders configuration, providing convenient access to its
43-
properties.
85+
_Optional_\
86+
Type: `User`
4487

4588
```ts
46-
import "log4js-appender-sentry"
47-
```
48-
49-
**example**
50-
51-
```json {3-6, 12}
52-
{
53-
"appenders": {
54-
"sentry": {
55-
"type": "log4js-appender-sentry",
56-
"dsn": "..."
57-
}
58-
},
59-
"categories": {
60-
"default": {
61-
"level": "debug",
62-
"appenders": [
63-
"sentry"
64-
]
65-
}
66-
}
89+
// import { User } from "@sentry/node/types";
90+
91+
interface User {
92+
[key: string]: any;
93+
id?: string;
94+
ip_address?: string;
95+
email?: string;
96+
username?: string;
97+
segment?: string;
6798
}
6899
```
69100

70-
[internal_types]: ./index.d.ts
71-
[sentry_javascript]: https://github.com/getsentry/sentry-javascript
101+
User data used for scope configuration. For additional information, see the
102+
Sentry user [documentation][sentry_user].
103+
72104
[sentry_user]: https://docs.sentry.io/platforms/javascript/enriching-events/identify-user/
73-
[sentry_dsn]: https://docs.sentry.io/product/sentry-basics/dsn-explainer/

dprint.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
{
22
"lineWidth": 100,
33
"useTabs": true,
4+
"includes": [
5+
"**/*.{ts,mts,js,json,md,yml,yaml}"
6+
],
47
"excludes": [
58
"**/node_modules",
6-
"**/*-lock.json"
9+
"**/*-lock.json",
10+
"tsconfig.json",
11+
"CHANGELOG.md"
712
],
813
"plugins": [
9-
"https://plugins.dprint.dev/typescript-0.88.7.wasm",
10-
"https://plugins.dprint.dev/json-0.19.1.wasm"
14+
"https://plugins.dprint.dev/typescript-0.89.3.wasm",
15+
"https://plugins.dprint.dev/json-0.19.2.wasm",
16+
"https://plugins.dprint.dev/markdown-0.16.4.wasm"
1117
]
1218
}

index.js

Lines changed: 0 additions & 102 deletions
This file was deleted.

index.test.mts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import assert from "node:assert";
2+
import { describe, test } from "node:test";
3+
4+
import { dummyLayout } from "log4js/lib/layouts";
5+
import Level from "log4js/lib/levels";
6+
7+
import type { LoggingEvent } from "log4js";
8+
9+
import { sentry } from "./dist";
10+
11+
function makeLogEvent(): LoggingEvent {
12+
return {
13+
categoryName: "default",
14+
startTime: new Date(),
15+
data: ["test"],
16+
pid: 0,
17+
fileName: "",
18+
lineNumber: 0,
19+
columnNumber: 0,
20+
callStack: "",
21+
functionName: "",
22+
context: null,
23+
serialise: () => "",
24+
level: new Level(40000, "ERROR", "red"),
25+
};
26+
}
27+
28+
/**
29+
* TODO: fetch events from sentry to validate integration
30+
* TODO: validate if dsn is valid
31+
* TODO: shutdown test
32+
*/
33+
describe("Sentry integration", () => {
34+
const appender = sentry(
35+
{
36+
dsn: "<your_token>",
37+
},
38+
Level,
39+
dummyLayout,
40+
);
41+
42+
test("append log", async () => {
43+
const logEvent = makeLogEvent();
44+
45+
assert.doesNotThrow(() => {
46+
appender(logEvent);
47+
});
48+
});
49+
50+
test("shutdown", () => {
51+
assert.doesNotThrow(() => {
52+
// @ts-ignore
53+
appender.shutdown();
54+
});
55+
});
56+
});

0 commit comments

Comments
 (0)