@orbitai/orbitrace 1.1.6 → 1.1.10
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 +20 -140
- package/dist/index.js +9 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @orbitai/orbitrace
|
|
2
2
|
|
|
3
|
-
Error tracking and monitoring for Node.js
|
|
3
|
+
Error tracking and monitoring for backend Node.js applications.
|
|
4
|
+
|
|
5
|
+
Orbitrace is server-side only. Do not initialize this package in browser or frontend code, because the Orbitrace API key is a backend secret and must not be exposed in public bundles.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
@@ -17,8 +19,6 @@ npm install @orbitai/orbitrace
|
|
|
17
19
|
const Orbitrace = require("@orbitai/orbitrace");
|
|
18
20
|
|
|
19
21
|
function getOrbitraceInstance({ service }) {
|
|
20
|
-
console.log("Initializing Orbitrace for service:", service);
|
|
21
|
-
|
|
22
22
|
Orbitrace.getInstance({
|
|
23
23
|
apiKey: process.env.ORBITRACE_API_KEY,
|
|
24
24
|
orgId: process.env.ORBITRACE_ORG_ID,
|
|
@@ -27,6 +27,7 @@ function getOrbitraceInstance({ service }) {
|
|
|
27
27
|
environment: process.env.APP_ENV,
|
|
28
28
|
service,
|
|
29
29
|
version: process.env.APP_VERSION,
|
|
30
|
+
disabled: process.env.ORBITRACE_DISABLED === "true",
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
return Orbitrace;
|
|
@@ -37,166 +38,45 @@ module.exports = {
|
|
|
37
38
|
};
|
|
38
39
|
```
|
|
39
40
|
|
|
40
|
-
### 2.
|
|
41
|
+
### 2. Capture Exceptions
|
|
41
42
|
|
|
42
43
|
```javascript
|
|
43
|
-
const { getOrbitraceInstance } = require("
|
|
44
|
+
const { getOrbitraceInstance } = require("./orbitrace");
|
|
44
45
|
const orbitrace = getOrbitraceInstance({ service: "api" });
|
|
45
46
|
|
|
46
|
-
// Capture exceptions
|
|
47
47
|
try {
|
|
48
48
|
// Your code here
|
|
49
49
|
} catch (error) {
|
|
50
50
|
await orbitrace.captureException(error, {
|
|
51
51
|
endpoint: "/users",
|
|
52
|
+
action: "createUser",
|
|
52
53
|
});
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
-
// Capture messages
|
|
56
|
-
await orbitrace.captureMessage("User registered", {
|
|
57
|
-
userId: "123",
|
|
58
|
-
email: "user@example.com",
|
|
59
|
-
});
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Frontend Setup (Vue 3 + Pinia)
|
|
63
|
-
|
|
64
|
-
### 1. Initialize Orbitrace
|
|
65
|
-
|
|
66
|
-
```javascript
|
|
67
|
-
// orbitrace.js
|
|
68
|
-
import { provide, inject } from "vue";
|
|
69
|
-
import Orbitrace from "@orbitai/orbitrace";
|
|
70
|
-
|
|
71
|
-
export const ORBITRACE_KEY = Symbol("orbitrace");
|
|
72
|
-
|
|
73
|
-
export function getOrbitraceInstance({ service }) {
|
|
74
|
-
Orbitrace.getInstance({
|
|
75
|
-
apiKey: import.meta.env.VITE_ORBITRACE_API_KEY,
|
|
76
|
-
orgId: import.meta.env.VITE_ORBITRACE_ORG_ID,
|
|
77
|
-
projectId: import.meta.env.VITE_ORBITRACE_PROJECT_ID,
|
|
78
|
-
endpoint: import.meta.env.VITE_ORBITRACE_ENDPOINT,
|
|
79
|
-
environment: import.meta.env.VITE_APP_ENV,
|
|
80
|
-
service,
|
|
81
|
-
version: import.meta.env.VITE_APP_VERSION,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return orbitrace;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function useOrbitrace() {
|
|
88
|
-
const orbitrace = inject(ORBITRACE_KEY);
|
|
89
|
-
if (!orbitrace) {
|
|
90
|
-
throw new Error("Orbitrace not properly initialized");
|
|
91
|
-
}
|
|
92
|
-
return orbitrace;
|
|
93
|
-
}
|
|
94
55
|
```
|
|
95
56
|
|
|
96
|
-
###
|
|
57
|
+
### 3. Capture Messages
|
|
97
58
|
|
|
98
59
|
```javascript
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
import App from "./App.vue";
|
|
103
|
-
import { getOrbitraceInstance, ORBITRACE_KEY } from "/path/to/orbitrace";
|
|
104
|
-
|
|
105
|
-
const app = createApp(App);
|
|
106
|
-
const pinia = createPinia();
|
|
107
|
-
|
|
108
|
-
// Initialize Orbitrace
|
|
109
|
-
const orbitrace = getOrbitraceInstance({ service: "webapp" });
|
|
110
|
-
|
|
111
|
-
// Make Orbitrace available everywhere
|
|
112
|
-
app.provide(ORBITRACE_KEY, orbitrace);
|
|
113
|
-
|
|
114
|
-
// Add Orbitrace to Pinia
|
|
115
|
-
pinia.use(({ store }) => {
|
|
116
|
-
store.orbitrace = orbitrace;
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
app.use(pinia);
|
|
120
|
-
app.mount("#app");
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### 3. Usage in Vue Components
|
|
124
|
-
|
|
125
|
-
```vue
|
|
126
|
-
<script setup>
|
|
127
|
-
import { useOrbitrace } from "/path/to/orbitrace";
|
|
128
|
-
|
|
129
|
-
const orbitrace = useOrbitrace();
|
|
130
|
-
|
|
131
|
-
async function handleUserAction() {
|
|
132
|
-
try {
|
|
133
|
-
// Your code here
|
|
134
|
-
} catch (error) {
|
|
135
|
-
await orbitrace.captureException(error, {
|
|
136
|
-
component: "UserProfile",
|
|
137
|
-
action: "updateProfile",
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Log custom events
|
|
143
|
-
async function trackEvent() {
|
|
144
|
-
await orbitrace.captureMessage("User completed onboarding", {
|
|
145
|
-
userId: "user123",
|
|
146
|
-
completedSteps: ["profile", "preferences"],
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
</script>
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
### 4. Usage in Pinia Stores
|
|
153
|
-
|
|
154
|
-
```javascript
|
|
155
|
-
// stores/userStore.js
|
|
156
|
-
import { defineStore } from "pinia";
|
|
157
|
-
|
|
158
|
-
export const useUserStore = defineStore("user", {
|
|
159
|
-
state: () => ({
|
|
160
|
-
user: null,
|
|
161
|
-
}),
|
|
162
|
-
actions: {
|
|
163
|
-
async fetchUser() {
|
|
164
|
-
try {
|
|
165
|
-
// Fetch user logic
|
|
166
|
-
} catch (error) {
|
|
167
|
-
await this.orbitrace.captureException(error, {
|
|
168
|
-
store: "userStore",
|
|
169
|
-
action: "fetchUser",
|
|
170
|
-
});
|
|
171
|
-
throw error;
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
},
|
|
60
|
+
await orbitrace.captureMessage("User registered", {
|
|
61
|
+
userId: "123",
|
|
62
|
+
email: "user@example.com",
|
|
175
63
|
});
|
|
176
64
|
```
|
|
177
65
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
For Vite:
|
|
181
|
-
|
|
182
|
-
```env
|
|
183
|
-
VITE_ORBITRACE_API_KEY=your-api-key
|
|
184
|
-
VITE_ORBITRACE_ORG_ID=your-org-id
|
|
185
|
-
VITE_ORBITRACE_PROJECT_ID=your-project-id
|
|
186
|
-
VITE_ORBITRACE_ENDPOINT=your-endpoint
|
|
187
|
-
VITE_APP_ENV=your-environment
|
|
188
|
-
VITE_APP_VERSION=your-version
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
For Node.js:
|
|
66
|
+
## Environment Variables
|
|
192
67
|
|
|
193
68
|
```env
|
|
194
|
-
ORBITRACE_API_KEY=your-api-key
|
|
69
|
+
ORBITRACE_API_KEY=your-backend-api-key
|
|
195
70
|
ORBITRACE_ORG_ID=your-org-id
|
|
196
71
|
ORBITRACE_PROJECT_ID=your-project-id
|
|
197
72
|
ORBITRACE_ENDPOINT=your-endpoint
|
|
198
|
-
APP_ENV=
|
|
199
|
-
APP_VERSION=
|
|
73
|
+
APP_ENV=production
|
|
74
|
+
APP_VERSION=1.0.0
|
|
75
|
+
ORBITRACE_DISABLED=false
|
|
200
76
|
```
|
|
201
77
|
|
|
78
|
+
## Security Model
|
|
79
|
+
|
|
80
|
+
Orbitrace authenticates ingestion requests with `ORBITRACE_API_KEY`. Keep this key only in backend environments such as servers, workers, functions, and CI jobs. Do not use `VITE_`, `NEXT_PUBLIC_`, or other public frontend environment variables for Orbitrace credentials.
|
|
202
81
|
|
|
82
|
+
If this package is initialized in a browser runtime, it throws an error before sending events.
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ class Orbitrace {
|
|
|
2
2
|
static #config = null;
|
|
3
3
|
|
|
4
4
|
static getInstance(config) {
|
|
5
|
+
this.assertServerRuntime();
|
|
5
6
|
this.validateConfig(config);
|
|
6
7
|
|
|
7
8
|
this.#config = {
|
|
@@ -35,6 +36,14 @@ class Orbitrace {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
static assertServerRuntime() {
|
|
40
|
+
if (typeof window !== "undefined" || typeof document !== "undefined") {
|
|
41
|
+
throw new Error(
|
|
42
|
+
"Orbitrace can only be initialized in backend/server runtimes"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
38
47
|
static async captureException(error, metadata = {}) {
|
|
39
48
|
this.checkInitialized();
|
|
40
49
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orbitai/orbitrace",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Error tracking and monitoring for Node.js
|
|
3
|
+
"version": "1.1.10",
|
|
4
|
+
"description": "Error tracking and monitoring for backend Node.js applications",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|