@orbitai/orbitrace 1.1.0
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 +202 -0
- package/dist/index.js +117 -0
- package/dist/index.mjs +131 -0
- package/package.json +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# @orbitai/orbitrace
|
|
2
|
+
|
|
3
|
+
Error tracking and monitoring for Node.js and browser applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @orbitai/orbitrace
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Backend Setup
|
|
12
|
+
|
|
13
|
+
### 1. Initialize Orbitrace
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
// orbitrace.js
|
|
17
|
+
const Orbitrace = require("@orbitai/orbitrace");
|
|
18
|
+
|
|
19
|
+
function getOrbitraceInstance({ service }) {
|
|
20
|
+
console.log("Initializing Orbitrace for service:", service);
|
|
21
|
+
|
|
22
|
+
Orbitrace.getInstance({
|
|
23
|
+
apiKey: process.env.ORBITRACE_API_KEY,
|
|
24
|
+
orgId: process.env.ORBITRACE_ORG_ID,
|
|
25
|
+
projectId: process.env.ORBITRACE_PROJECT_ID,
|
|
26
|
+
endpoint: process.env.ORBITRACE_ENDPOINT,
|
|
27
|
+
environment: process.env.APP_ENV,
|
|
28
|
+
service,
|
|
29
|
+
version: process.env.APP_VERSION,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return Orbitrace;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
getOrbitraceInstance,
|
|
37
|
+
};
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2. Usage
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
const { getOrbitraceInstance } = require("/path/to/orbitrace");
|
|
44
|
+
const orbitrace = getOrbitraceInstance({ service: "api" });
|
|
45
|
+
|
|
46
|
+
// Capture exceptions
|
|
47
|
+
try {
|
|
48
|
+
// Your code here
|
|
49
|
+
} catch (error) {
|
|
50
|
+
await orbitrace.captureException(error, {
|
|
51
|
+
endpoint: "/users",
|
|
52
|
+
});
|
|
53
|
+
}
|
|
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
|
+
```
|
|
95
|
+
|
|
96
|
+
### 2. Setup in Main App
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
// main.js
|
|
100
|
+
import { createApp } from "vue";
|
|
101
|
+
import { createPinia } from "pinia";
|
|
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
|
+
},
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Environment Variables
|
|
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:
|
|
192
|
+
|
|
193
|
+
```env
|
|
194
|
+
ORBITRACE_API_KEY=your-api-key
|
|
195
|
+
ORBITRACE_ORG_ID=your-org-id
|
|
196
|
+
ORBITRACE_PROJECT_ID=your-project-id
|
|
197
|
+
ORBITRACE_ENDPOINT=your-endpoint
|
|
198
|
+
APP_ENV=your-environment
|
|
199
|
+
APP_VERSION=your-version
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
class Orbitrace {
|
|
2
|
+
static #config = null;
|
|
3
|
+
|
|
4
|
+
static getInstance(config) {
|
|
5
|
+
this.validateConfig(config);
|
|
6
|
+
|
|
7
|
+
this.#config = {
|
|
8
|
+
apiKey: config.apiKey,
|
|
9
|
+
orgId: config.orgId,
|
|
10
|
+
projectId: config.projectId,
|
|
11
|
+
endpoint: config.endpoint,
|
|
12
|
+
environment: config.environment || "production",
|
|
13
|
+
version: config.version || "1.0.0",
|
|
14
|
+
service: config.service || "not-specified",
|
|
15
|
+
disabled: config.disabled || false,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static validateConfig(config) {
|
|
20
|
+
const requiredFields = ["apiKey", "orgId", "projectId", "endpoint"];
|
|
21
|
+
const missingFields = requiredFields.filter((field) => !config[field]);
|
|
22
|
+
|
|
23
|
+
if (missingFields.length > 0) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Missing required configuration fields: ${missingFields.join(", ")}`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static checkInitialized() {
|
|
31
|
+
if (!this.#config) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
"Orbitrace must be initialized with Orbitrace.getInstance() before use"
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static async captureException(error, metadata = {}) {
|
|
39
|
+
this.checkInitialized();
|
|
40
|
+
|
|
41
|
+
if (this.#config.disabled) {
|
|
42
|
+
console.log("Orbitrace: Logging is disabled");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const payload = {
|
|
48
|
+
message: error.message,
|
|
49
|
+
stack: error.stack,
|
|
50
|
+
metadata: {
|
|
51
|
+
...metadata,
|
|
52
|
+
env: this.#config.environment,
|
|
53
|
+
version: this.#config.version,
|
|
54
|
+
service: this.#config.service,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return this.sendToApi("capture_exception", payload);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
console.error("Orbitrace: Error capturing exception", err);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static async captureMessage(message, metadata = {}) {
|
|
65
|
+
this.checkInitialized();
|
|
66
|
+
|
|
67
|
+
if (this.#config.disabled) {
|
|
68
|
+
console.log("Orbitrace: Logging is disabled");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const payload = {
|
|
74
|
+
message,
|
|
75
|
+
metadata: {
|
|
76
|
+
...metadata,
|
|
77
|
+
env: this.#config.environment,
|
|
78
|
+
version: this.#config.version,
|
|
79
|
+
service: this.#config.service,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return this.sendToApi("capture_message", payload);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.error("Orbitrace: Error capturing message", err);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static async sendToApi(event, payload) {
|
|
90
|
+
try {
|
|
91
|
+
const response = await fetch(this.#config.endpoint, {
|
|
92
|
+
method: "POST",
|
|
93
|
+
headers: {
|
|
94
|
+
"Content-Type": "application/json",
|
|
95
|
+
"x-orbitrace-api-key": this.#config.apiKey,
|
|
96
|
+
"x-orbitrace-org-id": this.#config.orgId,
|
|
97
|
+
"x-orbitrace-project-id": this.#config.projectId,
|
|
98
|
+
},
|
|
99
|
+
body: JSON.stringify({
|
|
100
|
+
event,
|
|
101
|
+
payload,
|
|
102
|
+
}),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
if (!response.ok) {
|
|
106
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return await response.json();
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.error("Orbitrace: Error sending data to API", error);
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = Orbitrace;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
+
};
|
|
5
|
+
var __accessCheck = (obj, member, msg) => {
|
|
6
|
+
if (!member.has(obj))
|
|
7
|
+
throw TypeError("Cannot " + msg);
|
|
8
|
+
};
|
|
9
|
+
var __privateGet = (obj, member, getter) => {
|
|
10
|
+
__accessCheck(obj, member, "read from private field");
|
|
11
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
12
|
+
};
|
|
13
|
+
var __privateAdd = (obj, member, value) => {
|
|
14
|
+
if (member.has(obj))
|
|
15
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
16
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
17
|
+
};
|
|
18
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
19
|
+
__accessCheck(obj, member, "write to private field");
|
|
20
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/index.js
|
|
25
|
+
var require_src = __commonJS({
|
|
26
|
+
"src/index.js"(exports, module) {
|
|
27
|
+
var _config;
|
|
28
|
+
var Orbitrace = class {
|
|
29
|
+
static init(config) {
|
|
30
|
+
this.validateConfig(config);
|
|
31
|
+
__privateSet(this, _config, {
|
|
32
|
+
apiKey: config.apiKey,
|
|
33
|
+
orgId: config.orgId,
|
|
34
|
+
projectId: config.projectId,
|
|
35
|
+
endpoint: config.endpoint,
|
|
36
|
+
environment: config.environment || "production",
|
|
37
|
+
version: config.version || "1.0.0",
|
|
38
|
+
service: config.service || "not-specified",
|
|
39
|
+
disabled: config.disabled || false
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
static validateConfig(config) {
|
|
43
|
+
const requiredFields = ["apiKey", "orgId", "projectId", "endpoint"];
|
|
44
|
+
const missingFields = requiredFields.filter((field) => !config[field]);
|
|
45
|
+
if (missingFields.length > 0) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Missing required configuration fields: ${missingFields.join(", ")}`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
static checkInitialized() {
|
|
52
|
+
if (!__privateGet(this, _config)) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
"Orbitrace must be initialized with Orbitrace.init() before use"
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
static async captureException(error, metadata = {}) {
|
|
59
|
+
this.checkInitialized();
|
|
60
|
+
if (__privateGet(this, _config).disabled) {
|
|
61
|
+
console.log("Orbitrace: Logging is disabled");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const payload = {
|
|
66
|
+
message: error.message,
|
|
67
|
+
stack: error.stack,
|
|
68
|
+
metadata: {
|
|
69
|
+
...metadata,
|
|
70
|
+
env: __privateGet(this, _config).environment,
|
|
71
|
+
version: __privateGet(this, _config).version,
|
|
72
|
+
service: __privateGet(this, _config).service
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
return this.sendToApi("capture_exception", payload);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
console.error("Orbitrace: Error capturing exception", err);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
static async captureMessage(message, metadata = {}) {
|
|
81
|
+
this.checkInitialized();
|
|
82
|
+
if (__privateGet(this, _config).disabled) {
|
|
83
|
+
console.log("Orbitrace: Logging is disabled");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const payload = {
|
|
88
|
+
message,
|
|
89
|
+
metadata: {
|
|
90
|
+
...metadata,
|
|
91
|
+
env: __privateGet(this, _config).environment,
|
|
92
|
+
version: __privateGet(this, _config).version,
|
|
93
|
+
service: __privateGet(this, _config).service
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return this.sendToApi("capture_message", payload);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
console.error("Orbitrace: Error capturing message", err);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
static async sendToApi(event, payload) {
|
|
102
|
+
try {
|
|
103
|
+
const response = await fetch(__privateGet(this, _config).endpoint, {
|
|
104
|
+
method: "POST",
|
|
105
|
+
headers: {
|
|
106
|
+
"Content-Type": "application/json",
|
|
107
|
+
"x-orbitrace-api-key": __privateGet(this, _config).apiKey,
|
|
108
|
+
"x-orbitrace-org-id": __privateGet(this, _config).orgId,
|
|
109
|
+
"x-orbitrace-project-id": __privateGet(this, _config).projectId
|
|
110
|
+
},
|
|
111
|
+
body: JSON.stringify({
|
|
112
|
+
event,
|
|
113
|
+
payload
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
if (!response.ok) {
|
|
117
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
118
|
+
}
|
|
119
|
+
return await response.json();
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error("Orbitrace: Error sending data to API", error);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
_config = new WeakMap();
|
|
127
|
+
__privateAdd(Orbitrace, _config, null);
|
|
128
|
+
module.exports = Orbitrace;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
export default require_src();
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orbitai/orbitrace",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Error tracking and monitoring for Node.js and browser applications",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "mkdir -p dist && cp src/index.js dist/index.js",
|
|
11
|
+
"deploy": "npm run build && npm version patch && npm publish --access public"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"author": "Orbitai",
|
|
17
|
+
"license": "MIT"
|
|
18
|
+
}
|