tracebeam-sdk 0.1.1 → 0.2.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.
@@ -53,6 +53,8 @@ interface Event {
53
53
  tags: Tags;
54
54
  /** Additional context data */
55
55
  extra: Extra;
56
+ /** Request latency in milliseconds */
57
+ latency?: number;
56
58
  }
57
59
  /**
58
60
  * Options for capture methods
@@ -66,6 +68,8 @@ interface CaptureOptions {
66
68
  extra?: Extra;
67
69
  /** Custom timestamp (ISO 8601) */
68
70
  timestamp?: string;
71
+ /** Request latency in milliseconds */
72
+ latency?: number;
69
73
  }
70
74
  /**
71
75
  * Batch payload sent to Ingest API
@@ -97,111 +101,38 @@ interface TransportErrorResponse {
97
101
  type TransportResponse = TransportSuccessResponse | TransportErrorResponse;
98
102
 
99
103
  /**
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
- * ```
104
+ * TraceBeamSDK client for capturing and sending events via OTLP
123
105
  */
124
106
  declare class TraceBeamSDK {
125
107
  private readonly config;
126
- private readonly transport;
127
- private readonly queue;
108
+ private provider;
109
+ private tracer;
110
+ private isInitialized;
128
111
  private globalTags;
129
112
  private globalExtra;
130
113
  private userId;
131
- private isInitialized;
132
114
  /**
133
115
  * Create SDK instance from configuration
134
116
  */
135
117
  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
118
  static fromEnv(): TraceBeamSDK;
154
119
  /**
155
120
  * Capture an exception/error
156
- * Returns immediately (non-blocking)
157
121
  */
158
- captureException(error: Error | string, options?: CaptureOptions): void;
122
+ captureException(error: Error | string | unknown, options?: CaptureOptions): void;
159
123
  /**
160
- * Capture a message/event
161
- * Returns immediately (non-blocking)
124
+ * Capture a message
162
125
  */
163
126
  captureMessage(message: string, options?: CaptureOptions): void;
164
- /**
165
- * Set the current user ID
166
- * Will be included in all subsequent events
167
- */
168
127
  setUser(userId: string | null): void;
169
- /**
170
- * Set a global tag
171
- * Will be included in all subsequent events
172
- */
173
128
  setTag(key: string, value: string): void;
174
- /**
175
- * Set multiple global tags
176
- * Will be included in all subsequent events
177
- */
178
129
  setTags(tags: Tags): void;
179
- /**
180
- * Set global extra context
181
- * Will be included in all subsequent events
182
- */
183
130
  setExtra(key: string, value: unknown): void;
184
- /**
185
- * Set multiple global extra context values
186
- */
187
131
  setExtras(extras: Extra): void;
188
- /**
189
- * Manually flush queued events
190
- * Call this to ensure events are sent before process exit
191
- */
192
132
  flush(): Promise<void>;
193
- /**
194
- * Graceful shutdown
195
- * Flushes remaining events and stops background workers
196
- */
197
133
  close(): Promise<void>;
198
- /**
199
- * Check if SDK is active and can capture events
200
- */
201
134
  isActive(): boolean;
202
135
  private canCapture;
203
- private createEventWithContext;
204
- private handleFlush;
205
136
  }
206
137
 
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 };
138
+ export { type CaptureOptions as C, type EventLevel as E, type TraceBeamConfig as T, TraceBeamSDK as a, type Tags as b, type Extra as c, type Event as d, type EventBatch as e, type TransportSuccessResponse as f, type TransportErrorResponse as g, type TransportResponse as h };
@@ -53,6 +53,8 @@ interface Event {
53
53
  tags: Tags;
54
54
  /** Additional context data */
55
55
  extra: Extra;
56
+ /** Request latency in milliseconds */
57
+ latency?: number;
56
58
  }
57
59
  /**
58
60
  * Options for capture methods
@@ -66,6 +68,8 @@ interface CaptureOptions {
66
68
  extra?: Extra;
67
69
  /** Custom timestamp (ISO 8601) */
68
70
  timestamp?: string;
71
+ /** Request latency in milliseconds */
72
+ latency?: number;
69
73
  }
70
74
  /**
71
75
  * Batch payload sent to Ingest API
@@ -97,111 +101,38 @@ interface TransportErrorResponse {
97
101
  type TransportResponse = TransportSuccessResponse | TransportErrorResponse;
98
102
 
99
103
  /**
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
- * ```
104
+ * TraceBeamSDK client for capturing and sending events via OTLP
123
105
  */
124
106
  declare class TraceBeamSDK {
125
107
  private readonly config;
126
- private readonly transport;
127
- private readonly queue;
108
+ private provider;
109
+ private tracer;
110
+ private isInitialized;
128
111
  private globalTags;
129
112
  private globalExtra;
130
113
  private userId;
131
- private isInitialized;
132
114
  /**
133
115
  * Create SDK instance from configuration
134
116
  */
135
117
  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
118
  static fromEnv(): TraceBeamSDK;
154
119
  /**
155
120
  * Capture an exception/error
156
- * Returns immediately (non-blocking)
157
121
  */
158
- captureException(error: Error | string, options?: CaptureOptions): void;
122
+ captureException(error: Error | string | unknown, options?: CaptureOptions): void;
159
123
  /**
160
- * Capture a message/event
161
- * Returns immediately (non-blocking)
124
+ * Capture a message
162
125
  */
163
126
  captureMessage(message: string, options?: CaptureOptions): void;
164
- /**
165
- * Set the current user ID
166
- * Will be included in all subsequent events
167
- */
168
127
  setUser(userId: string | null): void;
169
- /**
170
- * Set a global tag
171
- * Will be included in all subsequent events
172
- */
173
128
  setTag(key: string, value: string): void;
174
- /**
175
- * Set multiple global tags
176
- * Will be included in all subsequent events
177
- */
178
129
  setTags(tags: Tags): void;
179
- /**
180
- * Set global extra context
181
- * Will be included in all subsequent events
182
- */
183
130
  setExtra(key: string, value: unknown): void;
184
- /**
185
- * Set multiple global extra context values
186
- */
187
131
  setExtras(extras: Extra): void;
188
- /**
189
- * Manually flush queued events
190
- * Call this to ensure events are sent before process exit
191
- */
192
132
  flush(): Promise<void>;
193
- /**
194
- * Graceful shutdown
195
- * Flushes remaining events and stops background workers
196
- */
197
133
  close(): Promise<void>;
198
- /**
199
- * Check if SDK is active and can capture events
200
- */
201
134
  isActive(): boolean;
202
135
  private canCapture;
203
- private createEventWithContext;
204
- private handleFlush;
205
136
  }
206
137
 
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 };
138
+ export { type CaptureOptions as C, type EventLevel as E, type TraceBeamConfig as T, TraceBeamSDK as a, type Tags as b, type Extra as c, type Event as d, type EventBatch as e, type TransportSuccessResponse as f, type TransportErrorResponse as g, type TransportResponse as h };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tracebeam-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Node.js SDK for TraceBeam API Observability Platform",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -53,7 +53,7 @@
53
53
  "vitest": "^2.0.0"
54
54
  },
55
55
  "peerDependencies": {
56
- "express": "^4.0.0 || ^5.0.0",
56
+ "express": "^5.2.1",
57
57
  "fastify": "^4.0.0 || ^5.0.0"
58
58
  },
59
59
  "peerDependenciesMeta": {
@@ -63,5 +63,14 @@
63
63
  "fastify": {
64
64
  "optional": true
65
65
  }
66
+ },
67
+ "dependencies": {
68
+ "@opentelemetry/api": "^1.9.0",
69
+ "@opentelemetry/auto-instrumentations-node": "^0.68.0",
70
+ "@opentelemetry/exporter-trace-otlp-http": "^0.210.0",
71
+ "@opentelemetry/resources": "^2.4.0",
72
+ "@opentelemetry/sdk-trace-node": "^2.4.0",
73
+ "@opentelemetry/semantic-conventions": "^1.39.0",
74
+ "@types/express": "^5.0.6"
66
75
  }
67
- }
76
+ }