kodo-sdk 0.4.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 +260 -0
- package/dist/browser.d.ts +288 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +766 -0
- package/dist/browser.js.map +1 -0
- package/dist/index.d.ts +194 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +403 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# kodo-sdk
|
|
2
|
+
|
|
3
|
+
Official JavaScript/TypeScript SDK for [Kodo](https://github.com/mgthompo1/KODO) Status Pages.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install kodo-sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add kodo-sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add kodo-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Kodo } from 'kodo-sdk';
|
|
19
|
+
|
|
20
|
+
const kodo = new Kodo({
|
|
21
|
+
apiKey: process.env.KODO_API_KEY!,
|
|
22
|
+
baseUrl: 'https://your-kodo-instance.com', // optional
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Send a heartbeat
|
|
26
|
+
await kodo.heartbeat('monitor-id');
|
|
27
|
+
|
|
28
|
+
// Create an incident
|
|
29
|
+
const incident = await kodo.incidents.create({
|
|
30
|
+
title: 'Database connectivity issues',
|
|
31
|
+
severity: 'major',
|
|
32
|
+
message: 'Investigating slow query times',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Resolve it later
|
|
36
|
+
await kodo.incidents.resolve(incident.id, {
|
|
37
|
+
message: 'Root cause identified and fixed',
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
### Process Health
|
|
44
|
+
|
|
45
|
+
Observe whether your async work actually **completes** — not just whether the edge returns `200`. Wrap a unit of work with `workflow()` and instrument each step with `step()`. Your control flow is unchanged: `step()` runs your function, times it, records success/failure, and rethrows on error.
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
await kodo.workflow('checkout-fulfillment', async (wf) => {
|
|
49
|
+
await wf.step('charge_card', () => stripe.charge(order));
|
|
50
|
+
await wf.step('reserve_inventory', () => inventory.reserve(order));
|
|
51
|
+
await wf.step('notify_warehouse', () => warehouse.notify(order));
|
|
52
|
+
await wf.step('mark_fulfilled', () => db.markFulfilled(order));
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
On completion (success or failure) the run appears under **Dashboard → Process Health**, grouped by workflow name. You get completion rate, p95 duration, failed runs **and the exact step that broke**, plus in-flight and stuck-run detection.
|
|
57
|
+
|
|
58
|
+
Telemetry is fire-and-forget — a failure to report never throws into your process. Kōdo only *observes*; retries, checkpointing, and durability stay with your engine (use it alongside Temporal, BullMQ, Cloudflare Workflows, or raw queues).
|
|
59
|
+
|
|
60
|
+
> Server-side only — `workflow()` is for backend processes (workers, jobs, route handlers). Process Health is available on plans that include distributed tracing.
|
|
61
|
+
|
|
62
|
+
### Heartbeats
|
|
63
|
+
|
|
64
|
+
Perfect for monitoring cron jobs, background workers, and scheduled tasks.
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
// Simple heartbeat
|
|
68
|
+
await kodo.heartbeat('backup-job');
|
|
69
|
+
|
|
70
|
+
// With additional info
|
|
71
|
+
await kodo.heartbeat('worker-1', {
|
|
72
|
+
status: 'up',
|
|
73
|
+
response_time_ms: 1523,
|
|
74
|
+
message: 'Processed 1000 items',
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Incidents
|
|
79
|
+
|
|
80
|
+
Full lifecycle management for incidents.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
// List incidents
|
|
84
|
+
const incidents = await kodo.incidents.list({ status: 'investigating' });
|
|
85
|
+
|
|
86
|
+
// Create incident
|
|
87
|
+
const incident = await kodo.incidents.create({
|
|
88
|
+
title: 'API Latency Spike',
|
|
89
|
+
severity: 'minor',
|
|
90
|
+
status: 'investigating',
|
|
91
|
+
message: 'Seeing increased response times',
|
|
92
|
+
services: ['api', 'database'], // Link to affected services
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Update incident
|
|
96
|
+
await kodo.incidents.update(incident.id, {
|
|
97
|
+
status: 'identified',
|
|
98
|
+
message: 'Root cause found: database connection pool exhaustion',
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Resolve incident
|
|
102
|
+
await kodo.incidents.resolve(incident.id, {
|
|
103
|
+
message: 'Connection pool configuration updated. Monitoring.',
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Delete incident
|
|
107
|
+
await kodo.incidents.delete(incident.id);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Services
|
|
111
|
+
|
|
112
|
+
Manage your monitored services.
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
// List services
|
|
116
|
+
const services = await kodo.services.list();
|
|
117
|
+
|
|
118
|
+
// Create service
|
|
119
|
+
const service = await kodo.services.create({
|
|
120
|
+
name: 'Payment API',
|
|
121
|
+
description: 'Handles all payment processing',
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Update status
|
|
125
|
+
await kodo.services.setStatus(service.id, 'degraded');
|
|
126
|
+
|
|
127
|
+
// Quick status changes
|
|
128
|
+
await kodo.services.up(service.id); // Mark operational
|
|
129
|
+
await kodo.services.down(service.id); // Mark major outage
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Metrics
|
|
133
|
+
|
|
134
|
+
Push internal metrics for automatic health detection.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
await kodo.pushMetrics({
|
|
138
|
+
service: 'API Gateway',
|
|
139
|
+
metrics: {
|
|
140
|
+
error_rate: 2.5,
|
|
141
|
+
response_time_ms: 245,
|
|
142
|
+
cpu_percent: 65,
|
|
143
|
+
memory_percent: 78,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Framework Examples
|
|
149
|
+
|
|
150
|
+
### Next.js API Route
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
// app/api/health/route.ts
|
|
154
|
+
import { Kodo } from 'kodo-sdk';
|
|
155
|
+
|
|
156
|
+
const kodo = new Kodo({ apiKey: process.env.KODO_API_KEY! });
|
|
157
|
+
|
|
158
|
+
export async function GET() {
|
|
159
|
+
await kodo.heartbeat('api-health');
|
|
160
|
+
return Response.json({ status: 'ok' });
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Express.js Middleware
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
import express from 'express';
|
|
168
|
+
import { Kodo } from 'kodo-sdk';
|
|
169
|
+
|
|
170
|
+
const app = express();
|
|
171
|
+
const kodo = new Kodo({ apiKey: process.env.KODO_API_KEY! });
|
|
172
|
+
|
|
173
|
+
// Heartbeat on each request
|
|
174
|
+
app.use((req, res, next) => {
|
|
175
|
+
kodo.heartbeat('express-api').catch(console.error);
|
|
176
|
+
next();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Error reporting
|
|
180
|
+
app.use((err, req, res, next) => {
|
|
181
|
+
if (err.critical) {
|
|
182
|
+
kodo.incidents.create({
|
|
183
|
+
title: `Critical: ${err.message}`,
|
|
184
|
+
severity: 'critical',
|
|
185
|
+
}).catch(console.error);
|
|
186
|
+
}
|
|
187
|
+
next(err);
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Background Worker
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import { Kodo } from 'kodo-sdk';
|
|
195
|
+
|
|
196
|
+
const kodo = new Kodo({ apiKey: process.env.KODO_API_KEY! });
|
|
197
|
+
|
|
198
|
+
async function processJob() {
|
|
199
|
+
const start = Date.now();
|
|
200
|
+
|
|
201
|
+
try {
|
|
202
|
+
// Do work...
|
|
203
|
+
await processItems();
|
|
204
|
+
|
|
205
|
+
// Report success
|
|
206
|
+
await kodo.heartbeat('job-processor', {
|
|
207
|
+
status: 'up',
|
|
208
|
+
response_time_ms: Date.now() - start,
|
|
209
|
+
});
|
|
210
|
+
} catch (error) {
|
|
211
|
+
// Report failure
|
|
212
|
+
await kodo.heartbeat('job-processor', {
|
|
213
|
+
status: 'down',
|
|
214
|
+
message: error.message,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Create incident if critical
|
|
218
|
+
await kodo.incidents.create({
|
|
219
|
+
title: 'Job processor failed',
|
|
220
|
+
severity: 'major',
|
|
221
|
+
message: error.stack,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Error Handling
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
import { Kodo, ApiError } from 'kodo-sdk';
|
|
231
|
+
|
|
232
|
+
const kodo = new Kodo({ apiKey: 'invalid-key' });
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
await kodo.incidents.list();
|
|
236
|
+
} catch (error) {
|
|
237
|
+
if (error instanceof ApiError) {
|
|
238
|
+
console.error(`API Error: ${error.message}`);
|
|
239
|
+
console.error(`Status: ${error.status}`);
|
|
240
|
+
console.error(`Body: ${JSON.stringify(error.body)}`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## TypeScript Support
|
|
246
|
+
|
|
247
|
+
Full TypeScript support with exported types:
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import type {
|
|
251
|
+
Incident,
|
|
252
|
+
Service,
|
|
253
|
+
CreateIncidentOptions,
|
|
254
|
+
HeartbeatOptions,
|
|
255
|
+
} from 'kodo-sdk';
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## License
|
|
259
|
+
|
|
260
|
+
MIT
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kodo Browser SDK
|
|
3
|
+
* Client-side error tracking, structured logging, distributed tracing, and performance monitoring
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* - Automatic error capture (window.onerror, unhandledrejection)
|
|
7
|
+
* - Breadcrumb tracking (console, clicks, navigation, XHR, fetch)
|
|
8
|
+
* - Structured logging with levels and context
|
|
9
|
+
* - Distributed tracing with spans
|
|
10
|
+
* - Web Vitals (LCP, FID, CLS)
|
|
11
|
+
* - User context
|
|
12
|
+
* - Ad-blocker bypass (tunneling)
|
|
13
|
+
*/
|
|
14
|
+
export interface KodoConfig {
|
|
15
|
+
/** Beacon public key (bpk_...) - safe for client-side use */
|
|
16
|
+
dsn: string;
|
|
17
|
+
/** Service/app name */
|
|
18
|
+
service?: string;
|
|
19
|
+
/** Release version */
|
|
20
|
+
release?: string;
|
|
21
|
+
/** Environment (auto-detected if not specified) */
|
|
22
|
+
environment?: 'production' | 'staging' | 'development';
|
|
23
|
+
/** Base URL for Kodo (default: https://kodostatus.com) */
|
|
24
|
+
baseUrl?: string;
|
|
25
|
+
/** Tunnel route for ad-blocker bypass (e.g., "/monitoring") */
|
|
26
|
+
tunnel?: string;
|
|
27
|
+
/** Enable automatic breadcrumb capture (default: true) */
|
|
28
|
+
enableBreadcrumbs?: boolean;
|
|
29
|
+
/** Max breadcrumbs to keep (default: 100) */
|
|
30
|
+
maxBreadcrumbs?: number;
|
|
31
|
+
/** Enable debug logging (default: false) */
|
|
32
|
+
debug?: boolean;
|
|
33
|
+
/** Before send hook - return null to drop event */
|
|
34
|
+
beforeSend?: (event: BeaconEvent) => BeaconEvent | null;
|
|
35
|
+
}
|
|
36
|
+
interface BeaconEvent {
|
|
37
|
+
type: 'error' | 'log' | 'trace' | 'vital' | 'message';
|
|
38
|
+
timestamp: number;
|
|
39
|
+
session_id: string;
|
|
40
|
+
url: string;
|
|
41
|
+
user_agent: string;
|
|
42
|
+
service: string | null;
|
|
43
|
+
release: string | null;
|
|
44
|
+
environment: string | null;
|
|
45
|
+
data: Record<string, unknown>;
|
|
46
|
+
context?: BrowserContext;
|
|
47
|
+
}
|
|
48
|
+
interface BrowserContext {
|
|
49
|
+
viewport: {
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
};
|
|
53
|
+
devicePixelRatio: number;
|
|
54
|
+
language: string;
|
|
55
|
+
timezone: string;
|
|
56
|
+
connection?: {
|
|
57
|
+
effectiveType: string;
|
|
58
|
+
downlink?: number;
|
|
59
|
+
rtt?: number;
|
|
60
|
+
};
|
|
61
|
+
memory?: {
|
|
62
|
+
jsHeapSizeLimit: number;
|
|
63
|
+
totalJSHeapSize: number;
|
|
64
|
+
usedJSHeapSize: number;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
interface Breadcrumb {
|
|
68
|
+
category: string;
|
|
69
|
+
message?: string;
|
|
70
|
+
level?: 'debug' | 'info' | 'warning' | 'error';
|
|
71
|
+
data?: Record<string, unknown>;
|
|
72
|
+
timestamp: number;
|
|
73
|
+
}
|
|
74
|
+
interface UserContext {
|
|
75
|
+
id?: string;
|
|
76
|
+
email?: string;
|
|
77
|
+
username?: string;
|
|
78
|
+
[key: string]: unknown;
|
|
79
|
+
}
|
|
80
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
81
|
+
interface LogOptions {
|
|
82
|
+
/** Logger name (e.g., 'auth', 'payments', 'api') */
|
|
83
|
+
logger?: string;
|
|
84
|
+
/** Additional context data */
|
|
85
|
+
context?: Record<string, unknown>;
|
|
86
|
+
/** Stack trace (for errors) */
|
|
87
|
+
stack?: string;
|
|
88
|
+
/** Trace ID for correlation */
|
|
89
|
+
traceId?: string;
|
|
90
|
+
/** Span ID for correlation */
|
|
91
|
+
spanId?: string;
|
|
92
|
+
}
|
|
93
|
+
interface SpanData {
|
|
94
|
+
span_id: string;
|
|
95
|
+
parent_span_id: string | null;
|
|
96
|
+
name: string;
|
|
97
|
+
kind: 'client' | 'server' | 'internal' | 'producer' | 'consumer';
|
|
98
|
+
start_time: number;
|
|
99
|
+
end_time: number;
|
|
100
|
+
status: 'ok' | 'error';
|
|
101
|
+
attributes: Record<string, unknown>;
|
|
102
|
+
events: Array<{
|
|
103
|
+
name: string;
|
|
104
|
+
timestamp: number;
|
|
105
|
+
attributes?: Record<string, unknown>;
|
|
106
|
+
}>;
|
|
107
|
+
}
|
|
108
|
+
declare class Trace {
|
|
109
|
+
private _traceId;
|
|
110
|
+
private _name;
|
|
111
|
+
private _op;
|
|
112
|
+
private _startTime;
|
|
113
|
+
private _spans;
|
|
114
|
+
private _currentSpanId;
|
|
115
|
+
private _status;
|
|
116
|
+
private _tags;
|
|
117
|
+
private _httpMethod?;
|
|
118
|
+
private _httpUrl?;
|
|
119
|
+
private _httpStatusCode?;
|
|
120
|
+
constructor(name: string, options?: {
|
|
121
|
+
op?: string;
|
|
122
|
+
tags?: Record<string, unknown>;
|
|
123
|
+
});
|
|
124
|
+
get traceId(): string;
|
|
125
|
+
/** Start a child span */
|
|
126
|
+
startSpan(name: string, options?: {
|
|
127
|
+
kind?: SpanData['kind'];
|
|
128
|
+
attributes?: Record<string, unknown>;
|
|
129
|
+
}): Span;
|
|
130
|
+
/** Set HTTP details for the trace */
|
|
131
|
+
setHttpDetails(method: string, url: string, statusCode?: number): void;
|
|
132
|
+
/** Add a tag to the trace */
|
|
133
|
+
setTag(key: string, value: unknown): void;
|
|
134
|
+
/** Mark trace as error */
|
|
135
|
+
setError(): void;
|
|
136
|
+
/** Internal: Add completed span */
|
|
137
|
+
_addSpan(span: SpanData): void;
|
|
138
|
+
/** Finish the trace and send it */
|
|
139
|
+
finish(): void;
|
|
140
|
+
}
|
|
141
|
+
declare class Span {
|
|
142
|
+
private _trace;
|
|
143
|
+
private _spanId;
|
|
144
|
+
private _parentSpanId;
|
|
145
|
+
private _name;
|
|
146
|
+
private _kind;
|
|
147
|
+
private _startTime;
|
|
148
|
+
private _attributes;
|
|
149
|
+
private _events;
|
|
150
|
+
private _status;
|
|
151
|
+
private _finished;
|
|
152
|
+
constructor(trace: Trace, spanId: string, parentSpanId: string | null, name: string, kind: SpanData['kind'], attributes?: Record<string, unknown>);
|
|
153
|
+
get spanId(): string;
|
|
154
|
+
/** Set attributes on the span */
|
|
155
|
+
setAttributes(attrs: Record<string, unknown>): void;
|
|
156
|
+
/** Add an event to the span */
|
|
157
|
+
addEvent(name: string, attributes?: Record<string, unknown>): void;
|
|
158
|
+
/** Mark span as error */
|
|
159
|
+
setError(): void;
|
|
160
|
+
/** Finish the span */
|
|
161
|
+
finish(options?: {
|
|
162
|
+
status?: 'ok' | 'error';
|
|
163
|
+
}): void;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Initialize the Kodo SDK
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* import Kodo from 'kodo-sdk/browser';
|
|
171
|
+
*
|
|
172
|
+
* Kodo.init({
|
|
173
|
+
* dsn: 'bpk_your_key_here',
|
|
174
|
+
* service: 'my-app',
|
|
175
|
+
* release: '1.0.0',
|
|
176
|
+
* });
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
declare function init(config: KodoConfig): void;
|
|
180
|
+
/**
|
|
181
|
+
* Set user context for all events
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* Kodo.setUser({ id: 'user123', email: 'user@example.com' });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
declare function setUser(user: UserContext | null): void;
|
|
189
|
+
/**
|
|
190
|
+
* Add a breadcrumb manually
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* Kodo.addBreadcrumb({
|
|
195
|
+
* category: 'user',
|
|
196
|
+
* message: 'Clicked checkout button',
|
|
197
|
+
* level: 'info',
|
|
198
|
+
* });
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
declare function addBreadcrumb(breadcrumb: Omit<Breadcrumb, 'timestamp'>): void;
|
|
202
|
+
/**
|
|
203
|
+
* Capture an exception manually
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* try {
|
|
208
|
+
* riskyOperation();
|
|
209
|
+
* } catch (error) {
|
|
210
|
+
* Kodo.captureException(error);
|
|
211
|
+
* }
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
declare function captureException(error: Error, context?: Record<string, unknown>): void;
|
|
215
|
+
/**
|
|
216
|
+
* Send a structured log message
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* Kodo.log('info', 'User signed in', {
|
|
221
|
+
* logger: 'auth',
|
|
222
|
+
* context: { userId: '123', method: 'oauth' }
|
|
223
|
+
* });
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
declare function log(level: LogLevel, message: string, options?: LogOptions): void;
|
|
227
|
+
declare const debug: (message: string, options?: LogOptions) => void;
|
|
228
|
+
declare const info: (message: string, options?: LogOptions) => void;
|
|
229
|
+
declare const warn: (message: string, options?: LogOptions) => void;
|
|
230
|
+
declare const error: (message: string, options?: LogOptions) => void;
|
|
231
|
+
declare const fatal: (message: string, options?: LogOptions) => void;
|
|
232
|
+
/**
|
|
233
|
+
* Start a distributed trace
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* const trace = Kodo.startTrace('checkout-flow', { op: 'user.action' });
|
|
238
|
+
*
|
|
239
|
+
* const fetchSpan = trace.startSpan('fetch-cart', { kind: 'client' });
|
|
240
|
+
* await fetchCart();
|
|
241
|
+
* fetchSpan.finish();
|
|
242
|
+
*
|
|
243
|
+
* trace.finish();
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
declare function startTrace(name: string, options?: {
|
|
247
|
+
op?: string;
|
|
248
|
+
tags?: Record<string, unknown>;
|
|
249
|
+
}): Trace;
|
|
250
|
+
/**
|
|
251
|
+
* Wrap an async function with tracing
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* const result = await Kodo.trace('api-call', async (span) => {
|
|
256
|
+
* span.setAttributes({ endpoint: '/api/orders' });
|
|
257
|
+
* const response = await fetch('/api/orders');
|
|
258
|
+
* span.setAttributes({ status: response.status });
|
|
259
|
+
* return response.json();
|
|
260
|
+
* });
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
declare function trace<T>(name: string, fn: (span: Span) => Promise<T>, options?: {
|
|
264
|
+
op?: string;
|
|
265
|
+
}): Promise<T>;
|
|
266
|
+
/**
|
|
267
|
+
* Flush all pending events immediately
|
|
268
|
+
*/
|
|
269
|
+
declare function flush(): Promise<void>;
|
|
270
|
+
declare const Kodo: {
|
|
271
|
+
init: typeof init;
|
|
272
|
+
setUser: typeof setUser;
|
|
273
|
+
addBreadcrumb: typeof addBreadcrumb;
|
|
274
|
+
captureException: typeof captureException;
|
|
275
|
+
flush: typeof flush;
|
|
276
|
+
log: typeof log;
|
|
277
|
+
debug: (message: string, options?: LogOptions) => void;
|
|
278
|
+
info: (message: string, options?: LogOptions) => void;
|
|
279
|
+
warn: (message: string, options?: LogOptions) => void;
|
|
280
|
+
error: (message: string, options?: LogOptions) => void;
|
|
281
|
+
fatal: (message: string, options?: LogOptions) => void;
|
|
282
|
+
startTrace: typeof startTrace;
|
|
283
|
+
trace: typeof trace;
|
|
284
|
+
};
|
|
285
|
+
export default Kodo;
|
|
286
|
+
export { init, setUser, addBreadcrumb, captureException, flush, log, debug, info, warn, error, fatal, startTrace, trace };
|
|
287
|
+
export type { LogLevel, LogOptions, Trace, Span };
|
|
288
|
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