tracebeam-sdk 0.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 +141 -0
- package/dist/client-CaHega3m.d.mts +207 -0
- package/dist/client-CaHega3m.d.ts +207 -0
- package/dist/index.d.mts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +580 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +550 -0
- package/dist/index.mjs.map +1 -0
- package/dist/integrations/express.d.mts +70 -0
- package/dist/integrations/express.d.ts +70 -0
- package/dist/integrations/express.js +90 -0
- package/dist/integrations/express.js.map +1 -0
- package/dist/integrations/express.mjs +64 -0
- package/dist/integrations/express.mjs.map +1 -0
- package/dist/integrations/fastify.d.mts +76 -0
- package/dist/integrations/fastify.d.ts +76 -0
- package/dist/integrations/fastify.js +87 -0
- package/dist/integrations/fastify.js.map +1 -0
- package/dist/integrations/fastify.mjs +61 -0
- package/dist/integrations/fastify.mjs.map +1 -0
- package/package.json +67 -0
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# tracebeam-sdk
|
|
2
|
+
|
|
3
|
+
A lightweight, non-blocking Node.js SDK for sending errors and events to the TraceBeam API Observability Platform.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🚀 **Non-blocking** - Events queued and sent in background
|
|
8
|
+
- âš¡ **Batching** - Events batched for efficient transmission
|
|
9
|
+
- 🔄 **Retry** - Automatic retry with exponential backoff
|
|
10
|
+
- 🔒 **Secure** - API keys via environment variables
|
|
11
|
+
- 📦 **Lightweight** - Zero runtime dependencies (uses native fetch)
|
|
12
|
+
- 🎯 **TypeScript** - Full type support
|
|
13
|
+
|
|
14
|
+
## Requirements
|
|
15
|
+
|
|
16
|
+
- Node.js 18+
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install tracebeam-sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { TraceBeamSDK } from 'tracebeam-sdk';
|
|
28
|
+
|
|
29
|
+
// Initialize from environment variables
|
|
30
|
+
const sdk = TraceBeamSDK.fromEnv();
|
|
31
|
+
|
|
32
|
+
// Capture an exception
|
|
33
|
+
try {
|
|
34
|
+
await doSomething();
|
|
35
|
+
} catch (error) {
|
|
36
|
+
sdk.captureException(error);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Capture a message
|
|
40
|
+
sdk.captureMessage('User signed up', { level: 'info' });
|
|
41
|
+
|
|
42
|
+
// Graceful shutdown
|
|
43
|
+
await sdk.close();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Environment Variables
|
|
47
|
+
|
|
48
|
+
| Variable | Required | Default | Description |
|
|
49
|
+
|----------|----------|---------|-------------|
|
|
50
|
+
| `TRACEBEAM_API_KEY` | Yes | - | Your API key |
|
|
51
|
+
| `TRACEBEAM_PROJECT_ID` | Yes | - | Your project ID |
|
|
52
|
+
| `TRACEBEAM_ENVIRONMENT` | No | development | Environment name |
|
|
53
|
+
| `TRACEBEAM_ENDPOINT` | No | https://ingest.tracebeam.io | API endpoint |
|
|
54
|
+
| `TRACEBEAM_BATCH_SIZE` | No | 100 | Events per batch |
|
|
55
|
+
| `TRACEBEAM_FLUSH_INTERVAL` | No | 5000 | Flush interval (ms) |
|
|
56
|
+
| `TRACEBEAM_DEBUG` | No | false | Enable debug logging |
|
|
57
|
+
|
|
58
|
+
## Manual Configuration
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
const sdk = new TraceBeamSDK({
|
|
62
|
+
apiKey: 'sk_xxx',
|
|
63
|
+
projectId: 'proj_xxx',
|
|
64
|
+
environment: 'production',
|
|
65
|
+
batchSize: 50,
|
|
66
|
+
flushInterval: 3000,
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Context
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
// Set user context
|
|
74
|
+
sdk.setUser('user_123');
|
|
75
|
+
|
|
76
|
+
// Set tags (included in all events)
|
|
77
|
+
sdk.setTag('region', 'us-east-1');
|
|
78
|
+
sdk.setTags({ service: 'api', version: '1.0.0' });
|
|
79
|
+
|
|
80
|
+
// Set extra context
|
|
81
|
+
sdk.setExtra('account_type', 'premium');
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Framework Integrations
|
|
85
|
+
|
|
86
|
+
### Express
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import express from 'express';
|
|
90
|
+
import { TraceBeamSDK } from 'tracebeam-sdk';
|
|
91
|
+
import { expressErrorHandler } from 'tracebeam-sdk/integrations/express';
|
|
92
|
+
|
|
93
|
+
const app = express();
|
|
94
|
+
const sdk = TraceBeamSDK.fromEnv();
|
|
95
|
+
|
|
96
|
+
// Your routes...
|
|
97
|
+
|
|
98
|
+
// Add error handler AFTER all routes
|
|
99
|
+
app.use(expressErrorHandler(sdk));
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Fastify
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import Fastify from 'fastify';
|
|
106
|
+
import { TraceBeamSDK } from 'tracebeam-sdk';
|
|
107
|
+
import { tracebeamPlugin } from 'tracebeam-sdk/integrations/fastify';
|
|
108
|
+
|
|
109
|
+
const fastify = Fastify();
|
|
110
|
+
const sdk = TraceBeamSDK.fromEnv();
|
|
111
|
+
|
|
112
|
+
fastify.register(tracebeamPlugin, { sdk });
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Capture Options
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
sdk.captureException(error, {
|
|
119
|
+
level: 'fatal',
|
|
120
|
+
tags: { feature: 'auth' },
|
|
121
|
+
extra: { userId: '123', endpoint: '/login' },
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
sdk.captureMessage('Important event', {
|
|
125
|
+
level: 'warning',
|
|
126
|
+
tags: { category: 'billing' },
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Graceful Shutdown
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
process.on('SIGTERM', async () => {
|
|
134
|
+
await sdk.close();
|
|
135
|
+
process.exit(0);
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
MIT
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK configuration options
|
|
3
|
+
*/
|
|
4
|
+
interface TraceBeamConfig {
|
|
5
|
+
/** API key for authentication (required) */
|
|
6
|
+
apiKey: string;
|
|
7
|
+
/** Project ID to send events for (required) */
|
|
8
|
+
projectId: string;
|
|
9
|
+
/** Environment name (default: 'development') */
|
|
10
|
+
environment?: string;
|
|
11
|
+
/** Ingest API endpoint (default: 'https://ingest.tracebeam.io') */
|
|
12
|
+
endpoint?: string;
|
|
13
|
+
/** Max events per batch (default: 100) */
|
|
14
|
+
batchSize?: number;
|
|
15
|
+
/** Flush interval in milliseconds (default: 5000) */
|
|
16
|
+
flushInterval?: number;
|
|
17
|
+
/** HTTP request timeout in milliseconds (default: 10000) */
|
|
18
|
+
timeout?: number;
|
|
19
|
+
/** Max events to hold in queue (default: 10000) */
|
|
20
|
+
maxQueueSize?: number;
|
|
21
|
+
/** Sample rate 0.0-1.0 (default: 1.0) */
|
|
22
|
+
sampleRate?: number;
|
|
23
|
+
/** Enable debug logging (default: false) */
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Event severity levels
|
|
28
|
+
*/
|
|
29
|
+
type EventLevel = 'debug' | 'info' | 'warning' | 'error' | 'fatal';
|
|
30
|
+
/**
|
|
31
|
+
* Tags for event categorization
|
|
32
|
+
*/
|
|
33
|
+
type Tags = Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* Extra context data for events
|
|
36
|
+
*/
|
|
37
|
+
type Extra = Record<string, unknown>;
|
|
38
|
+
/**
|
|
39
|
+
* Event payload sent to the Ingest API
|
|
40
|
+
*/
|
|
41
|
+
interface Event {
|
|
42
|
+
/** Project ID */
|
|
43
|
+
project_id: string;
|
|
44
|
+
/** Error message or event description */
|
|
45
|
+
error: string;
|
|
46
|
+
/** Severity level */
|
|
47
|
+
level: EventLevel;
|
|
48
|
+
/** Environment (prod, staging, dev) */
|
|
49
|
+
environment: string;
|
|
50
|
+
/** ISO 8601 timestamp */
|
|
51
|
+
timestamp: string;
|
|
52
|
+
/** Key-value tags for categorization */
|
|
53
|
+
tags: Tags;
|
|
54
|
+
/** Additional context data */
|
|
55
|
+
extra: Extra;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Options for capture methods
|
|
59
|
+
*/
|
|
60
|
+
interface CaptureOptions {
|
|
61
|
+
/** Severity level */
|
|
62
|
+
level?: EventLevel;
|
|
63
|
+
/** Additional tags */
|
|
64
|
+
tags?: Tags;
|
|
65
|
+
/** Additional context */
|
|
66
|
+
extra?: Extra;
|
|
67
|
+
/** Custom timestamp (ISO 8601) */
|
|
68
|
+
timestamp?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Batch payload sent to Ingest API
|
|
72
|
+
*/
|
|
73
|
+
interface EventBatch {
|
|
74
|
+
events: Event[];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Success response from Ingest API
|
|
78
|
+
*/
|
|
79
|
+
interface TransportSuccessResponse {
|
|
80
|
+
success: true;
|
|
81
|
+
events_accepted: number;
|
|
82
|
+
message: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Error response from Ingest API
|
|
86
|
+
*/
|
|
87
|
+
interface TransportErrorResponse {
|
|
88
|
+
success: false;
|
|
89
|
+
error: string;
|
|
90
|
+
message: string;
|
|
91
|
+
code: number;
|
|
92
|
+
retry_after?: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Transport response (success or error)
|
|
96
|
+
*/
|
|
97
|
+
type TransportResponse = TransportSuccessResponse | TransportErrorResponse;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* TraceBeamSDK client for capturing and sending events
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* // Initialize from environment variables
|
|
105
|
+
* const sdk = TraceBeamSDK.fromEnv();
|
|
106
|
+
*
|
|
107
|
+
* // Capture an exception
|
|
108
|
+
* try {
|
|
109
|
+
* doSomething();
|
|
110
|
+
* } catch (error) {
|
|
111
|
+
* sdk.captureException(error);
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* // Capture a message
|
|
115
|
+
* sdk.captureMessage('User signup completed', {
|
|
116
|
+
* level: 'info',
|
|
117
|
+
* tags: { feature: 'auth' }
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* // Graceful shutdown
|
|
121
|
+
* await sdk.close();
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
declare class TraceBeamSDK {
|
|
125
|
+
private readonly config;
|
|
126
|
+
private readonly transport;
|
|
127
|
+
private readonly queue;
|
|
128
|
+
private globalTags;
|
|
129
|
+
private globalExtra;
|
|
130
|
+
private userId;
|
|
131
|
+
private isInitialized;
|
|
132
|
+
/**
|
|
133
|
+
* Create SDK instance from configuration
|
|
134
|
+
*/
|
|
135
|
+
constructor(config: TraceBeamConfig);
|
|
136
|
+
/**
|
|
137
|
+
* Create SDK instance from environment variables
|
|
138
|
+
*
|
|
139
|
+
* Required env vars:
|
|
140
|
+
* - TRACEBEAM_API_KEY
|
|
141
|
+
* - TRACEBEAM_PROJECT_ID
|
|
142
|
+
*
|
|
143
|
+
* Optional env vars:
|
|
144
|
+
* - TRACEBEAM_ENVIRONMENT (default: 'development')
|
|
145
|
+
* - TRACEBEAM_ENDPOINT (default: 'https://ingest.tracebeam.io')
|
|
146
|
+
* - TRACEBEAM_BATCH_SIZE (default: 100)
|
|
147
|
+
* - TRACEBEAM_FLUSH_INTERVAL (default: 5000)
|
|
148
|
+
* - TRACEBEAM_HTTP_TIMEOUT (default: 10000)
|
|
149
|
+
* - TRACEBEAM_MAX_QUEUE_SIZE (default: 10000)
|
|
150
|
+
* - TRACEBEAM_SAMPLE_RATE (default: 1.0)
|
|
151
|
+
* - TRACEBEAM_DEBUG (default: false)
|
|
152
|
+
*/
|
|
153
|
+
static fromEnv(): TraceBeamSDK;
|
|
154
|
+
/**
|
|
155
|
+
* Capture an exception/error
|
|
156
|
+
* Returns immediately (non-blocking)
|
|
157
|
+
*/
|
|
158
|
+
captureException(error: Error | string, options?: CaptureOptions): void;
|
|
159
|
+
/**
|
|
160
|
+
* Capture a message/event
|
|
161
|
+
* Returns immediately (non-blocking)
|
|
162
|
+
*/
|
|
163
|
+
captureMessage(message: string, options?: CaptureOptions): void;
|
|
164
|
+
/**
|
|
165
|
+
* Set the current user ID
|
|
166
|
+
* Will be included in all subsequent events
|
|
167
|
+
*/
|
|
168
|
+
setUser(userId: string | null): void;
|
|
169
|
+
/**
|
|
170
|
+
* Set a global tag
|
|
171
|
+
* Will be included in all subsequent events
|
|
172
|
+
*/
|
|
173
|
+
setTag(key: string, value: string): void;
|
|
174
|
+
/**
|
|
175
|
+
* Set multiple global tags
|
|
176
|
+
* Will be included in all subsequent events
|
|
177
|
+
*/
|
|
178
|
+
setTags(tags: Tags): void;
|
|
179
|
+
/**
|
|
180
|
+
* Set global extra context
|
|
181
|
+
* Will be included in all subsequent events
|
|
182
|
+
*/
|
|
183
|
+
setExtra(key: string, value: unknown): void;
|
|
184
|
+
/**
|
|
185
|
+
* Set multiple global extra context values
|
|
186
|
+
*/
|
|
187
|
+
setExtras(extras: Extra): void;
|
|
188
|
+
/**
|
|
189
|
+
* Manually flush queued events
|
|
190
|
+
* Call this to ensure events are sent before process exit
|
|
191
|
+
*/
|
|
192
|
+
flush(): Promise<void>;
|
|
193
|
+
/**
|
|
194
|
+
* Graceful shutdown
|
|
195
|
+
* Flushes remaining events and stops background workers
|
|
196
|
+
*/
|
|
197
|
+
close(): Promise<void>;
|
|
198
|
+
/**
|
|
199
|
+
* Check if SDK is active and can capture events
|
|
200
|
+
*/
|
|
201
|
+
isActive(): boolean;
|
|
202
|
+
private canCapture;
|
|
203
|
+
private createEventWithContext;
|
|
204
|
+
private handleFlush;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export { type CaptureOptions as C, type Event as E, type TraceBeamConfig as T, TraceBeamSDK as a, type EventLevel as b, type Tags as c, type Extra as d, type EventBatch as e, type TransportResponse as f, type TransportSuccessResponse as g, type TransportErrorResponse as h };
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK configuration options
|
|
3
|
+
*/
|
|
4
|
+
interface TraceBeamConfig {
|
|
5
|
+
/** API key for authentication (required) */
|
|
6
|
+
apiKey: string;
|
|
7
|
+
/** Project ID to send events for (required) */
|
|
8
|
+
projectId: string;
|
|
9
|
+
/** Environment name (default: 'development') */
|
|
10
|
+
environment?: string;
|
|
11
|
+
/** Ingest API endpoint (default: 'https://ingest.tracebeam.io') */
|
|
12
|
+
endpoint?: string;
|
|
13
|
+
/** Max events per batch (default: 100) */
|
|
14
|
+
batchSize?: number;
|
|
15
|
+
/** Flush interval in milliseconds (default: 5000) */
|
|
16
|
+
flushInterval?: number;
|
|
17
|
+
/** HTTP request timeout in milliseconds (default: 10000) */
|
|
18
|
+
timeout?: number;
|
|
19
|
+
/** Max events to hold in queue (default: 10000) */
|
|
20
|
+
maxQueueSize?: number;
|
|
21
|
+
/** Sample rate 0.0-1.0 (default: 1.0) */
|
|
22
|
+
sampleRate?: number;
|
|
23
|
+
/** Enable debug logging (default: false) */
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Event severity levels
|
|
28
|
+
*/
|
|
29
|
+
type EventLevel = 'debug' | 'info' | 'warning' | 'error' | 'fatal';
|
|
30
|
+
/**
|
|
31
|
+
* Tags for event categorization
|
|
32
|
+
*/
|
|
33
|
+
type Tags = Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* Extra context data for events
|
|
36
|
+
*/
|
|
37
|
+
type Extra = Record<string, unknown>;
|
|
38
|
+
/**
|
|
39
|
+
* Event payload sent to the Ingest API
|
|
40
|
+
*/
|
|
41
|
+
interface Event {
|
|
42
|
+
/** Project ID */
|
|
43
|
+
project_id: string;
|
|
44
|
+
/** Error message or event description */
|
|
45
|
+
error: string;
|
|
46
|
+
/** Severity level */
|
|
47
|
+
level: EventLevel;
|
|
48
|
+
/** Environment (prod, staging, dev) */
|
|
49
|
+
environment: string;
|
|
50
|
+
/** ISO 8601 timestamp */
|
|
51
|
+
timestamp: string;
|
|
52
|
+
/** Key-value tags for categorization */
|
|
53
|
+
tags: Tags;
|
|
54
|
+
/** Additional context data */
|
|
55
|
+
extra: Extra;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Options for capture methods
|
|
59
|
+
*/
|
|
60
|
+
interface CaptureOptions {
|
|
61
|
+
/** Severity level */
|
|
62
|
+
level?: EventLevel;
|
|
63
|
+
/** Additional tags */
|
|
64
|
+
tags?: Tags;
|
|
65
|
+
/** Additional context */
|
|
66
|
+
extra?: Extra;
|
|
67
|
+
/** Custom timestamp (ISO 8601) */
|
|
68
|
+
timestamp?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Batch payload sent to Ingest API
|
|
72
|
+
*/
|
|
73
|
+
interface EventBatch {
|
|
74
|
+
events: Event[];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Success response from Ingest API
|
|
78
|
+
*/
|
|
79
|
+
interface TransportSuccessResponse {
|
|
80
|
+
success: true;
|
|
81
|
+
events_accepted: number;
|
|
82
|
+
message: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Error response from Ingest API
|
|
86
|
+
*/
|
|
87
|
+
interface TransportErrorResponse {
|
|
88
|
+
success: false;
|
|
89
|
+
error: string;
|
|
90
|
+
message: string;
|
|
91
|
+
code: number;
|
|
92
|
+
retry_after?: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Transport response (success or error)
|
|
96
|
+
*/
|
|
97
|
+
type TransportResponse = TransportSuccessResponse | TransportErrorResponse;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* TraceBeamSDK client for capturing and sending events
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* // Initialize from environment variables
|
|
105
|
+
* const sdk = TraceBeamSDK.fromEnv();
|
|
106
|
+
*
|
|
107
|
+
* // Capture an exception
|
|
108
|
+
* try {
|
|
109
|
+
* doSomething();
|
|
110
|
+
* } catch (error) {
|
|
111
|
+
* sdk.captureException(error);
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* // Capture a message
|
|
115
|
+
* sdk.captureMessage('User signup completed', {
|
|
116
|
+
* level: 'info',
|
|
117
|
+
* tags: { feature: 'auth' }
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* // Graceful shutdown
|
|
121
|
+
* await sdk.close();
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
declare class TraceBeamSDK {
|
|
125
|
+
private readonly config;
|
|
126
|
+
private readonly transport;
|
|
127
|
+
private readonly queue;
|
|
128
|
+
private globalTags;
|
|
129
|
+
private globalExtra;
|
|
130
|
+
private userId;
|
|
131
|
+
private isInitialized;
|
|
132
|
+
/**
|
|
133
|
+
* Create SDK instance from configuration
|
|
134
|
+
*/
|
|
135
|
+
constructor(config: TraceBeamConfig);
|
|
136
|
+
/**
|
|
137
|
+
* Create SDK instance from environment variables
|
|
138
|
+
*
|
|
139
|
+
* Required env vars:
|
|
140
|
+
* - TRACEBEAM_API_KEY
|
|
141
|
+
* - TRACEBEAM_PROJECT_ID
|
|
142
|
+
*
|
|
143
|
+
* Optional env vars:
|
|
144
|
+
* - TRACEBEAM_ENVIRONMENT (default: 'development')
|
|
145
|
+
* - TRACEBEAM_ENDPOINT (default: 'https://ingest.tracebeam.io')
|
|
146
|
+
* - TRACEBEAM_BATCH_SIZE (default: 100)
|
|
147
|
+
* - TRACEBEAM_FLUSH_INTERVAL (default: 5000)
|
|
148
|
+
* - TRACEBEAM_HTTP_TIMEOUT (default: 10000)
|
|
149
|
+
* - TRACEBEAM_MAX_QUEUE_SIZE (default: 10000)
|
|
150
|
+
* - TRACEBEAM_SAMPLE_RATE (default: 1.0)
|
|
151
|
+
* - TRACEBEAM_DEBUG (default: false)
|
|
152
|
+
*/
|
|
153
|
+
static fromEnv(): TraceBeamSDK;
|
|
154
|
+
/**
|
|
155
|
+
* Capture an exception/error
|
|
156
|
+
* Returns immediately (non-blocking)
|
|
157
|
+
*/
|
|
158
|
+
captureException(error: Error | string, options?: CaptureOptions): void;
|
|
159
|
+
/**
|
|
160
|
+
* Capture a message/event
|
|
161
|
+
* Returns immediately (non-blocking)
|
|
162
|
+
*/
|
|
163
|
+
captureMessage(message: string, options?: CaptureOptions): void;
|
|
164
|
+
/**
|
|
165
|
+
* Set the current user ID
|
|
166
|
+
* Will be included in all subsequent events
|
|
167
|
+
*/
|
|
168
|
+
setUser(userId: string | null): void;
|
|
169
|
+
/**
|
|
170
|
+
* Set a global tag
|
|
171
|
+
* Will be included in all subsequent events
|
|
172
|
+
*/
|
|
173
|
+
setTag(key: string, value: string): void;
|
|
174
|
+
/**
|
|
175
|
+
* Set multiple global tags
|
|
176
|
+
* Will be included in all subsequent events
|
|
177
|
+
*/
|
|
178
|
+
setTags(tags: Tags): void;
|
|
179
|
+
/**
|
|
180
|
+
* Set global extra context
|
|
181
|
+
* Will be included in all subsequent events
|
|
182
|
+
*/
|
|
183
|
+
setExtra(key: string, value: unknown): void;
|
|
184
|
+
/**
|
|
185
|
+
* Set multiple global extra context values
|
|
186
|
+
*/
|
|
187
|
+
setExtras(extras: Extra): void;
|
|
188
|
+
/**
|
|
189
|
+
* Manually flush queued events
|
|
190
|
+
* Call this to ensure events are sent before process exit
|
|
191
|
+
*/
|
|
192
|
+
flush(): Promise<void>;
|
|
193
|
+
/**
|
|
194
|
+
* Graceful shutdown
|
|
195
|
+
* Flushes remaining events and stops background workers
|
|
196
|
+
*/
|
|
197
|
+
close(): Promise<void>;
|
|
198
|
+
/**
|
|
199
|
+
* Check if SDK is active and can capture events
|
|
200
|
+
*/
|
|
201
|
+
isActive(): boolean;
|
|
202
|
+
private canCapture;
|
|
203
|
+
private createEventWithContext;
|
|
204
|
+
private handleFlush;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export { type CaptureOptions as C, type Event as E, type TraceBeamConfig as T, TraceBeamSDK as a, type EventLevel as b, type Tags as c, type Extra as d, type EventBatch as e, type TransportResponse as f, type TransportSuccessResponse as g, type TransportErrorResponse as h };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { T as TraceBeamConfig } from './client-CaHega3m.mjs';
|
|
2
|
+
export { C as CaptureOptions, E as Event, e as EventBatch, b as EventLevel, d as Extra, c as Tags, a as TraceBeamSDK, h as TransportErrorResponse, f as TransportResponse, g as TransportSuccessResponse } from './client-CaHega3m.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Default configuration values
|
|
6
|
+
*/
|
|
7
|
+
declare const DEFAULT_CONFIG: {
|
|
8
|
+
readonly environment: "development";
|
|
9
|
+
readonly endpoint: "https://ingest.tracebeam.io";
|
|
10
|
+
readonly batchSize: 100;
|
|
11
|
+
readonly flushInterval: 5000;
|
|
12
|
+
readonly timeout: 10000;
|
|
13
|
+
readonly maxQueueSize: 10000;
|
|
14
|
+
readonly sampleRate: 1;
|
|
15
|
+
readonly debug: false;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Configuration error thrown when required values are missing
|
|
19
|
+
*/
|
|
20
|
+
declare class ConfigError extends Error {
|
|
21
|
+
constructor(message: string);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Load configuration from environment variables
|
|
25
|
+
*/
|
|
26
|
+
declare function loadConfigFromEnv(): TraceBeamConfig;
|
|
27
|
+
|
|
28
|
+
export { ConfigError, DEFAULT_CONFIG, TraceBeamConfig, loadConfigFromEnv };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { T as TraceBeamConfig } from './client-CaHega3m.js';
|
|
2
|
+
export { C as CaptureOptions, E as Event, e as EventBatch, b as EventLevel, d as Extra, c as Tags, a as TraceBeamSDK, h as TransportErrorResponse, f as TransportResponse, g as TransportSuccessResponse } from './client-CaHega3m.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Default configuration values
|
|
6
|
+
*/
|
|
7
|
+
declare const DEFAULT_CONFIG: {
|
|
8
|
+
readonly environment: "development";
|
|
9
|
+
readonly endpoint: "https://ingest.tracebeam.io";
|
|
10
|
+
readonly batchSize: 100;
|
|
11
|
+
readonly flushInterval: 5000;
|
|
12
|
+
readonly timeout: 10000;
|
|
13
|
+
readonly maxQueueSize: 10000;
|
|
14
|
+
readonly sampleRate: 1;
|
|
15
|
+
readonly debug: false;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Configuration error thrown when required values are missing
|
|
19
|
+
*/
|
|
20
|
+
declare class ConfigError extends Error {
|
|
21
|
+
constructor(message: string);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Load configuration from environment variables
|
|
25
|
+
*/
|
|
26
|
+
declare function loadConfigFromEnv(): TraceBeamConfig;
|
|
27
|
+
|
|
28
|
+
export { ConfigError, DEFAULT_CONFIG, TraceBeamConfig, loadConfigFromEnv };
|