uptime-tracker-sdk 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,46 +1,139 @@
|
|
|
1
|
-
# UpTimeTracker Node.js
|
|
1
|
+
# UpTimeTracker SDK for Node.js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Send application errors from Node.js and TypeScript services to the
|
|
4
|
+
UpTimeTracker API. The SDK uses Node.js's built-in `fetch` and includes
|
|
5
|
+
TypeScript declarations.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Node.js 18 or newer
|
|
10
|
+
- An UpTimeTracker API deployment reachable from your application
|
|
11
|
+
- An UpTimeTracker project ID
|
|
12
|
+
- An API key with the `sdk:write` scope
|
|
13
|
+
|
|
14
|
+
## Install
|
|
4
15
|
|
|
5
16
|
```sh
|
|
6
17
|
npm install uptime-tracker-sdk
|
|
7
18
|
```
|
|
8
19
|
|
|
9
|
-
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
Keep the API key in your server's environment or secret manager. Do not expose
|
|
23
|
+
it in browser code or commit it to source control.
|
|
10
24
|
|
|
11
25
|
```js
|
|
12
26
|
import { UptimeTrackerClient } from "uptime-tracker-sdk";
|
|
13
27
|
|
|
28
|
+
const apiKey = process.env.UPTIME_TRACKER_API_KEY;
|
|
29
|
+
const projectId = process.env.UPTIME_TRACKER_PROJECT_ID;
|
|
30
|
+
const baseUrl = process.env.UPTIME_TRACKER_URL;
|
|
31
|
+
|
|
32
|
+
if (!apiKey || !projectId || !baseUrl) {
|
|
33
|
+
throw new Error("UpTimeTracker configuration is missing");
|
|
34
|
+
}
|
|
35
|
+
|
|
14
36
|
const uptimeTracker = new UptimeTrackerClient({
|
|
15
|
-
apiKey
|
|
16
|
-
projectId
|
|
17
|
-
baseUrl
|
|
37
|
+
apiKey,
|
|
38
|
+
projectId,
|
|
39
|
+
baseUrl, // API origin only, for example https://uptime.example.com
|
|
18
40
|
environment: process.env.NODE_ENV ?? "production",
|
|
41
|
+
appVersion: process.env.APP_VERSION,
|
|
19
42
|
});
|
|
20
43
|
|
|
21
44
|
try {
|
|
22
45
|
await runApplicationTask();
|
|
23
46
|
} catch (error) {
|
|
24
|
-
|
|
47
|
+
try {
|
|
48
|
+
const result = await uptimeTracker.captureException(error, {
|
|
49
|
+
feature: "background-task",
|
|
50
|
+
context: { task: "daily-reconciliation" },
|
|
51
|
+
});
|
|
52
|
+
console.info("UpTimeTracker incident result:", result.action);
|
|
53
|
+
} catch (reportingError) {
|
|
54
|
+
// Keep an SDK/network failure from hiding the original application error.
|
|
55
|
+
console.error("Could not report the error to UpTimeTracker:", reportingError);
|
|
56
|
+
}
|
|
57
|
+
|
|
25
58
|
throw error;
|
|
26
59
|
}
|
|
27
60
|
```
|
|
28
61
|
|
|
29
|
-
`
|
|
30
|
-
|
|
31
|
-
|
|
62
|
+
`captureException` accepts an `Error` or another thrown value. It sends the
|
|
63
|
+
exception message, type, stack trace, feature, context, environment, and app
|
|
64
|
+
version to the SDK events endpoint. The call is asynchronous; await it when you
|
|
65
|
+
need to know whether the API accepted the report.
|
|
32
66
|
|
|
33
|
-
##
|
|
67
|
+
## Configuration
|
|
34
68
|
|
|
35
|
-
|
|
69
|
+
| Option | Required | Description |
|
|
70
|
+
| --- | --- | --- |
|
|
71
|
+
| `apiKey` | Yes | API key with the `sdk:write` scope. |
|
|
72
|
+
| `projectId` | Yes | UUID of the project that should receive incidents. |
|
|
73
|
+
| `baseUrl` | Recommended | API origin, without `/v1`. Defaults to `http://localhost:8000`. |
|
|
74
|
+
| `environment` | No | Environment label, such as `production` or `staging`. Defaults to `production`. |
|
|
75
|
+
| `appVersion` | No | Version of the application sending events. |
|
|
36
76
|
|
|
37
|
-
|
|
38
|
-
|
|
77
|
+
Set `baseUrl` to your deployed API in production. The localhost default is
|
|
78
|
+
intended for local development.
|
|
79
|
+
|
|
80
|
+
## Send custom events
|
|
81
|
+
|
|
82
|
+
Use `sendEvent` for one event or `sendEvents` for a batch of up to 100:
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
await uptimeTracker.sendEvent({
|
|
86
|
+
eventType: "error",
|
|
87
|
+
level: "error",
|
|
88
|
+
message: "Payment provider request failed",
|
|
89
|
+
exceptionType: "PaymentProviderError",
|
|
90
|
+
feature: "checkout",
|
|
91
|
+
context: { provider: "example-payments" },
|
|
92
|
+
});
|
|
39
93
|
```
|
|
40
94
|
|
|
41
|
-
|
|
95
|
+
Events support `eventType` values `error`, `exception`, `critical`, `resolved`,
|
|
96
|
+
and `warning`; levels are `error`, `critical`, `warning`, and `info`. Timestamps
|
|
97
|
+
can be supplied as a `Date` or an ISO-8601 string. The API accepts batches of
|
|
98
|
+
up to 100 events.
|
|
99
|
+
|
|
100
|
+
## Incident behavior
|
|
101
|
+
|
|
102
|
+
The API opens a project-level incident for `error`, `exception`, or `critical`
|
|
103
|
+
events with an `error` or `critical` level. A `resolved` event resolves the
|
|
104
|
+
currently open SDK incident for that project. The methods return a result with
|
|
105
|
+
an `action` (`opened`, `resolved`, or `none`), an `incidentId`, and a message.
|
|
106
|
+
Repeated qualifying errors while an incident is open do not open additional
|
|
107
|
+
incidents.
|
|
108
|
+
|
|
109
|
+
**Current backend limitation:** the API uses the event message and feature to
|
|
110
|
+
create the incident, but does not currently retain or display the submitted
|
|
111
|
+
stack trace or context in incident details. This SDK is therefore for incident
|
|
112
|
+
reporting, not a searchable, long-term application log store.
|
|
113
|
+
|
|
114
|
+
## Errors and privacy
|
|
115
|
+
|
|
116
|
+
HTTP failures reject with `UptimeTrackerError`, which includes `statusCode` for
|
|
117
|
+
HTTP responses. Network failures also reject. Handle reporting errors so they
|
|
118
|
+
do not mask the application error being reported.
|
|
119
|
+
|
|
120
|
+
Error messages, stack traces, and context may contain sensitive data. Remove
|
|
121
|
+
passwords, tokens, personal data, and request payloads before sending events.
|
|
122
|
+
Use only server-side code to keep the API key private.
|
|
123
|
+
|
|
124
|
+
## Troubleshooting
|
|
125
|
+
|
|
126
|
+
- **401 / 403:** check that the key is active and includes the `sdk:write` scope.
|
|
127
|
+
- **404:** check that the project exists and belongs to the API key's
|
|
128
|
+
organization.
|
|
129
|
+
- **Connection error:** verify `baseUrl`, network access, and that the API is
|
|
130
|
+
running.
|
|
131
|
+
- **No incident opened:** check that the event type is `error`, `exception`, or
|
|
132
|
+
`critical` and the level is `error` or `critical`.
|
|
133
|
+
|
|
134
|
+
## Development
|
|
42
135
|
|
|
43
|
-
From this directory:
|
|
136
|
+
From this directory, install development dependencies and run the test suite:
|
|
44
137
|
|
|
45
138
|
```sh
|
|
46
139
|
npm install
|