Skip to content

Commit 4e8de82

Browse files
authored
Merge pull request #55 from logdash-io/feat/node-sdk
feat: queue, retry, flushing, exponential backoff
2 parents 176fc90 + eaf5061 commit 4e8de82

27 files changed

Lines changed: 1718 additions & 1012 deletions

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [18, 20, 22]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Install pnpm
21+
uses: pnpm/action-setup@v4
22+
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
cache: 'pnpm'
28+
29+
- name: Install dependencies
30+
run: pnpm install
31+
32+
- name: Build
33+
run: pnpm build
34+
35+
- name: Test
36+
run: pnpm test

README.md

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# logdash - JS SDK
1+
# @logdash/node
22

3-
Logdash is a zero-config observability platform. This package serves an javascript interface to use it.
3+
Logdash is a zero-config observability platform. This package serves a Node.js/Bun/Deno/Browser interface to use it.
44

55
## Pre-requisites
66

@@ -9,39 +9,48 @@ Setup your free project in less than 2 minutes at [logdash.io](https://logdash.i
99
## Installation
1010

1111
```
12-
npm install @logdash/js-sdk
12+
npm install @logdash/node
1313
```
1414

1515
## Logging
1616

1717
```typescript
18-
import { createLogDash } from '@logdash/js-sdk';
18+
import { Logdash } from '@logdash/node';
1919

20-
const { logger } = createLogDash({
21-
// optional, but recommended to see your logs in the dashboard
22-
apiKey: '<your-api-key>',
23-
});
20+
const logdash = new Logdash('<your-api-key>');
2421

25-
logger.info('Application started successfully');
26-
logger.error('An unexpected error occurred');
27-
logger.warn('Low disk space warning');
22+
logdash.info('Application started successfully');
23+
logdash.error('An unexpected error occurred');
24+
logdash.warn('Low disk space warning');
25+
```
26+
27+
## Namespaced Logging
28+
29+
```typescript
30+
const authLogdash = logdash.withNamespace('auth');
31+
authLogdash.info('User logged in');
32+
authLogdash.error('Authentication failed');
2833
```
2934

3035
## Metrics
3136

3237
```typescript
33-
import { createLogDash } from '@logdash/js-sdk';
38+
import { Logdash } from '@logdash/node';
3439

35-
const { metrics } = createLogDash({
36-
// optional, but recommended as metrics are only hosted remotely
37-
apiKey: '<your-api-key>',
38-
});
40+
const logdash = new Logdash('<your-api-key>');
3941

4042
// to set absolute value
41-
metrics.set('users', 0);
43+
logdash.setMetric('users', 0);
4244

4345
// to modify existing metric
44-
metrics.mutate('users', 1);
46+
logdash.mutateMetric('users', 1);
47+
```
48+
49+
## Graceful Shutdown
50+
51+
```typescript
52+
// Ensure all logs and metrics are sent before exiting
53+
await logdash.flush();
4554
```
4655

4756
## View
@@ -53,20 +62,20 @@ To see the logs or metrics, go to your project dashboard
5362

5463
## Configuration
5564

56-
| Parameter | Required | Default | Description |
57-
| --------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------ |
58-
| `apiKey` | no | - | Api key used to authorize against logdash servers. If you don't provide one, logs will be logged into local console only |
59-
| `host` | no | - | Custom API host, useful with self-hosted instances |
60-
| `verbose` | no | - | Useful for debugging purposes |
65+
```typescript
66+
new Logdash(apiKey?, options?)
67+
```
68+
69+
| Parameter | Required | Default | Description |
70+
| ----------------- | -------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------ |
71+
| `apiKey` | no | - | Api key used to authorize against logdash servers. If you don't provide one, logs will be logged into local console only |
72+
| `options.host` | no | `https://api.logdash.io` | Custom API host, useful with self-hosted instances |
73+
| `options.verbose` | no | `false` | Useful for debugging purposes |
6174

6275
## License
6376

6477
This project is licensed under the MIT License.
6578

66-
## Contributing
67-
68-
Contributions are welcome! Feel free to open issues or submit pull requests.
69-
7079
## Support
7180

7281
If you encounter any issues, please open an issue on GitHub or let us know at [contact@logdash.io](mailto:contact@logdash.io).

package.json

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
11
{
2-
"name": "@logdash/js-sdk",
3-
"version": "1.0.9",
4-
"private": false,
5-
"description": "Modern observability platform.",
6-
"scripts": {
7-
"build": "tsc -p tsconfig.lib.json",
8-
"release": "pnpm build && changeset publish",
9-
"changeset": "changeset",
10-
"version-packages": "changeset version"
11-
},
12-
"author": "Simon Gracki <dev.sgracki@gmail.com>",
13-
"license": "MIT",
14-
"repository": {
15-
"type": "git",
16-
"url": "git+https://github.com/logdash-io/js-sdk.git"
17-
},
18-
"homepage": "https://github.com/logdash-io/js-sdk",
19-
"devDependencies": {
20-
"@changesets/cli": "^2.28.1",
21-
"@swc/core": "^1.10.18",
22-
"@types/node": "^22.13.5",
23-
"prettier": "^3.5.2",
24-
"typescript": "5.7.3",
25-
"vitest": "^3.0.6"
26-
},
27-
"bugs": {
28-
"url": "https://github.com/logdash-io/js-sdk/issues"
29-
},
30-
"packageManager": "pnpm@9.0.0",
31-
"engines": {
32-
"node": ">=18"
33-
},
34-
"main": "./dist/index.js",
35-
"module": "./dist/index.js",
36-
"types": "./dist/index.d.ts",
37-
"keywords": [
38-
"observability",
39-
"monitoring",
40-
"logging",
41-
"tracing",
42-
"metrics"
43-
],
44-
"dependencies": {
45-
"chalk": "^4.1.2"
46-
}
2+
"name": "@logdash/node",
3+
"version": "1.0.0",
4+
"private": false,
5+
"description": "How solo founders keep their SaaS apps healthy.",
6+
"scripts": {
7+
"build": "tsc -p tsconfig.lib.json",
8+
"test": "vitest run",
9+
"test:watch": "vitest",
10+
"release": "pnpm build && changeset publish",
11+
"changeset": "changeset",
12+
"version-packages": "changeset version"
13+
},
14+
"author": "Logdash Team <logdash.contact@gmail.com>",
15+
"license": "MIT",
16+
"repository": {
17+
"type": "git",
18+
"url": "git+https://github.com/logdash-io/node-sdk.git"
19+
},
20+
"homepage": "https://github.com/logdash-io/node-sdk",
21+
"devDependencies": {
22+
"@changesets/cli": "^2.29.8",
23+
"@swc/core": "^1.15.6",
24+
"@types/node": "^25.0.3",
25+
"prettier": "^3.7.4",
26+
"typescript": "5.9.3",
27+
"vitest": "^4.0.16"
28+
},
29+
"bugs": {
30+
"url": "https://github.com/logdash-io/node-sdk/issues"
31+
},
32+
"packageManager": "pnpm@9.0.0",
33+
"engines": {
34+
"node": ">=18"
35+
},
36+
"type": "module",
37+
"main": "./dist/index.js",
38+
"module": "./dist/index.js",
39+
"types": "./dist/index.d.ts",
40+
"keywords": [
41+
"observability",
42+
"monitoring",
43+
"logging",
44+
"tracing",
45+
"metrics"
46+
],
47+
"dependencies": {
48+
"chalk": "^5.6.2"
49+
}
4750
}

0 commit comments

Comments
 (0)