@orbitai/orbitrace 1.1.9 → 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.
Files changed (3) hide show
  1. package/README.md +22 -142
  2. package/dist/index.js +9 -10
  3. 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 and browser applications.
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,7 +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.APP_ENV !== "production",
30
+ disabled: process.env.ORBITRACE_DISABLED === "true",
31
31
  });
32
32
 
33
33
  return Orbitrace;
@@ -38,165 +38,45 @@ module.exports = {
38
38
  };
39
39
  ```
40
40
 
41
- ### 2. Usage
41
+ ### 2. Capture Exceptions
42
42
 
43
43
  ```javascript
44
- const { getOrbitraceInstance } = require("/path/to/orbitrace");
44
+ const { getOrbitraceInstance } = require("./orbitrace");
45
45
  const orbitrace = getOrbitraceInstance({ service: "api" });
46
46
 
47
- // Capture exceptions
48
47
  try {
49
48
  // Your code here
50
49
  } catch (error) {
51
50
  await orbitrace.captureException(error, {
52
51
  endpoint: "/users",
52
+ action: "createUser",
53
53
  });
54
54
  }
55
-
56
- // Capture messages
57
- await orbitrace.captureMessage("User registered", {
58
- userId: "123",
59
- email: "user@example.com",
60
- });
61
55
  ```
62
56
 
63
- ## Frontend Setup (Vue 3 + Pinia)
64
-
65
- ### 1. Initialize Orbitrace
57
+ ### 3. Capture Messages
66
58
 
67
59
  ```javascript
68
- // orbitrace.js
69
- import { provide, inject } from "vue";
70
- import Orbitrace from "@orbitai/orbitrace";
71
-
72
- export const ORBITRACE_KEY = Symbol("orbitrace");
73
-
74
- export function getOrbitraceInstance({ service }) {
75
- Orbitrace.getInstance({
76
- apiKey: import.meta.env.VITE_ORBITRACE_API_KEY,
77
- orgId: import.meta.env.VITE_ORBITRACE_ORG_ID,
78
- projectId: import.meta.env.VITE_ORBITRACE_PROJECT_ID,
79
- endpoint: import.meta.env.VITE_ORBITRACE_ENDPOINT,
80
- environment: import.meta.env.VITE_APP_ENV,
81
- service,
82
- version: import.meta.env.VITE_APP_VERSION,
83
- disabled: process.env.APP_ENV !== "production",
84
- });
85
-
86
- return orbitrace;
87
- }
88
-
89
- export function useOrbitrace() {
90
- const orbitrace = inject(ORBITRACE_KEY);
91
- if (!orbitrace) {
92
- throw new Error("Orbitrace not properly initialized");
93
- }
94
- return orbitrace;
95
- }
96
- ```
97
-
98
- ### 2. Setup in Main App
99
-
100
- ```javascript
101
- // main.js
102
- import { createApp } from "vue";
103
- import { createPinia } from "pinia";
104
- import App from "./App.vue";
105
- import { getOrbitraceInstance, ORBITRACE_KEY } from "/path/to/orbitrace";
106
-
107
- const app = createApp(App);
108
- const pinia = createPinia();
109
-
110
- // Initialize Orbitrace
111
- const orbitrace = getOrbitraceInstance({ service: "webapp" });
112
-
113
- // Make Orbitrace available everywhere
114
- app.provide(ORBITRACE_KEY, orbitrace);
115
-
116
- // Add Orbitrace to Pinia
117
- pinia.use(({ store }) => {
118
- store.orbitrace = orbitrace;
119
- });
120
-
121
- app.use(pinia);
122
- app.mount("#app");
123
- ```
124
-
125
- ### 3. Usage in Vue Components
126
-
127
- ```vue
128
- <script setup>
129
- import { useOrbitrace } from "/path/to/orbitrace";
130
-
131
- const orbitrace = useOrbitrace();
132
-
133
- async function handleUserAction() {
134
- try {
135
- // Your code here
136
- } catch (error) {
137
- await orbitrace.captureException(error, {
138
- component: "UserProfile",
139
- action: "updateProfile",
140
- });
141
- }
142
- }
143
-
144
- // Log custom events
145
- async function trackEvent() {
146
- await orbitrace.captureMessage("User completed onboarding", {
147
- userId: "user123",
148
- completedSteps: ["profile", "preferences"],
149
- });
150
- }
151
- </script>
152
- ```
153
-
154
- ### 4. Usage in Pinia Stores
155
-
156
- ```javascript
157
- // stores/userStore.js
158
- import { defineStore } from "pinia";
159
-
160
- export const useUserStore = defineStore("user", {
161
- state: () => ({
162
- user: null,
163
- }),
164
- actions: {
165
- async fetchUser() {
166
- try {
167
- // Fetch user logic
168
- } catch (error) {
169
- await this.orbitrace.captureException(error, {
170
- store: "userStore",
171
- action: "fetchUser",
172
- });
173
- throw error;
174
- }
175
- },
176
- },
60
+ await orbitrace.captureMessage("User registered", {
61
+ userId: "123",
62
+ email: "user@example.com",
177
63
  });
178
64
  ```
179
65
 
180
- ### Environment Variables
181
-
182
- For Vite:
66
+ ## Environment Variables
183
67
 
184
68
  ```env
185
- VITE_ORBITRACE_API_KEY=your-api-key
186
- VITE_ORBITRACE_ORG_ID=your-org-id
187
- VITE_ORBITRACE_PROJECT_ID=your-project-id
188
- VITE_ORBITRACE_ENDPOINT=your-endpoint
189
- VITE_APP_ENV=your-environment
190
- VITE_APP_VERSION=your-version
191
- ```
192
-
193
- For Node.js:
194
-
195
- ```env
196
- ORBITRACE_API_KEY=your-api-key
69
+ ORBITRACE_API_KEY=your-backend-api-key
197
70
  ORBITRACE_ORG_ID=your-org-id
198
71
  ORBITRACE_PROJECT_ID=your-project-id
199
72
  ORBITRACE_ENDPOINT=your-endpoint
200
- APP_ENV=your-environment
201
- APP_VERSION=your-version
73
+ APP_ENV=production
74
+ APP_VERSION=1.0.0
75
+ ORBITRACE_DISABLED=false
202
76
  ```
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.
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,8 +36,12 @@ class Orbitrace {
35
36
  }
36
37
  }
37
38
 
38
- static isBrowser() {
39
- return typeof window !== "undefined" && Boolean(window.location?.origin);
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
+ }
40
45
  }
41
46
 
42
47
  static async captureException(error, metadata = {}) {
@@ -92,7 +97,7 @@ class Orbitrace {
92
97
 
93
98
  static async sendToApi(event, payload) {
94
99
  try {
95
- const fetchOptions = {
100
+ const response = await fetch(this.#config.endpoint, {
96
101
  method: "POST",
97
102
  headers: {
98
103
  "Content-Type": "application/json",
@@ -104,13 +109,7 @@ class Orbitrace {
104
109
  event,
105
110
  payload,
106
111
  }),
107
- };
108
-
109
- if (this.isBrowser()) {
110
- fetchOptions.referrerPolicy = "origin";
111
- }
112
-
113
- const response = await fetch(this.#config.endpoint, fetchOptions);
112
+ });
114
113
 
115
114
  if (!response.ok) {
116
115
  throw new Error(`HTTP error! status: ${response.status}`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orbitai/orbitrace",
3
- "version": "1.1.9",
4
- "description": "Error tracking and monitoring for Node.js and browser applications",
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"