@deeptracer/react 0.3.0 → 0.3.1
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 +224 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# @deeptracer/react
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@deeptracer/react)
|
|
4
|
+
|
|
5
|
+
DeepTracer React integration — provider, error boundary, and hooks for automatic error capture. Re-exports everything from `@deeptracer/browser`.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @deeptracer/react
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Peer dependencies:** `react >=18`, `react-dom >=18`
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { DeepTracerProvider, DeepTracerErrorBoundary, useLogger } from "@deeptracer/react"
|
|
19
|
+
|
|
20
|
+
function App() {
|
|
21
|
+
return (
|
|
22
|
+
<DeepTracerProvider config={{
|
|
23
|
+
product: "my-app",
|
|
24
|
+
service: "web",
|
|
25
|
+
environment: "production",
|
|
26
|
+
endpoint: "https://deeptracer.example.com",
|
|
27
|
+
apiKey: "dt_live_xxx",
|
|
28
|
+
}}>
|
|
29
|
+
<DeepTracerErrorBoundary fallback={<div>Something went wrong</div>}>
|
|
30
|
+
<MyApp />
|
|
31
|
+
</DeepTracerErrorBoundary>
|
|
32
|
+
</DeepTracerProvider>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function MyApp() {
|
|
37
|
+
const logger = useLogger()
|
|
38
|
+
|
|
39
|
+
function handleClick() {
|
|
40
|
+
logger.info("Button clicked", { component: "MyApp" })
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return <button onClick={handleClick}>Click me</button>
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## API Reference
|
|
48
|
+
|
|
49
|
+
### `DeepTracerProvider`
|
|
50
|
+
|
|
51
|
+
React context provider that creates and manages a DeepTracer Logger instance. Automatically captures browser global errors (`window.onerror` and `unhandledrejection`).
|
|
52
|
+
|
|
53
|
+
**Props:**
|
|
54
|
+
|
|
55
|
+
| Prop | Type | Default | Description |
|
|
56
|
+
|------|------|---------|-------------|
|
|
57
|
+
| `config` | `LoggerConfig` | — | Logger configuration. Creates a new Logger internally. |
|
|
58
|
+
| `logger` | `Logger` | — | An existing Logger instance to share. Mutually exclusive with `config`. |
|
|
59
|
+
| `captureErrors` | `boolean` | `true` | Automatically capture unhandled window errors. |
|
|
60
|
+
| `children` | `ReactNode` | — | Child components with access to the logger via `useLogger()`. |
|
|
61
|
+
|
|
62
|
+
If neither `config` nor `logger` is provided, the provider reads from environment variables automatically:
|
|
63
|
+
|
|
64
|
+
| Environment Variable | Description |
|
|
65
|
+
|---------------------|-------------|
|
|
66
|
+
| `NEXT_PUBLIC_DEEPTRACER_ENDPOINT` | Ingestion endpoint URL (required) |
|
|
67
|
+
| `NEXT_PUBLIC_DEEPTRACER_API_KEY` | API key (required) |
|
|
68
|
+
| `NEXT_PUBLIC_DEEPTRACER_PRODUCT` | Product name (required) |
|
|
69
|
+
| `NEXT_PUBLIC_DEEPTRACER_SERVICE` | Service name (default: `"web"`) |
|
|
70
|
+
| `NEXT_PUBLIC_DEEPTRACER_ENVIRONMENT` | `"production"` or `"staging"` (default: `"production"`) |
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
// Explicit config
|
|
74
|
+
<DeepTracerProvider config={{
|
|
75
|
+
product: "my-app",
|
|
76
|
+
service: "web",
|
|
77
|
+
environment: "production",
|
|
78
|
+
endpoint: process.env.NEXT_PUBLIC_DEEPTRACER_ENDPOINT!,
|
|
79
|
+
apiKey: process.env.NEXT_PUBLIC_DEEPTRACER_API_KEY!,
|
|
80
|
+
}}>
|
|
81
|
+
{children}
|
|
82
|
+
</DeepTracerProvider>
|
|
83
|
+
|
|
84
|
+
// Zero-config (reads NEXT_PUBLIC_DEEPTRACER_* env vars)
|
|
85
|
+
<DeepTracerProvider>{children}</DeepTracerProvider>
|
|
86
|
+
|
|
87
|
+
// Existing logger instance
|
|
88
|
+
<DeepTracerProvider logger={myLogger}>{children}</DeepTracerProvider>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
### `DeepTracerErrorPage`
|
|
94
|
+
|
|
95
|
+
Drop-in function component for Next.js `error.tsx` or `global-error.tsx`. Receives `{ error, reset }` from Next.js, calls `captureError()` in `useEffect`, and shows a default fallback UI with a "Try again" button.
|
|
96
|
+
|
|
97
|
+
**One-line setup:**
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
// app/global-error.tsx
|
|
101
|
+
"use client"
|
|
102
|
+
export { DeepTracerErrorPage as default } from "@deeptracer/react"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
// app/error.tsx
|
|
107
|
+
"use client"
|
|
108
|
+
export { DeepTracerErrorPage as default } from "@deeptracer/react"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Requires a `<DeepTracerProvider>` in the component tree. If no provider is found, the error is displayed but not reported (a `console.warn` is emitted).
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
### `useDeepTracerErrorReporter(error, severity?)`
|
|
116
|
+
|
|
117
|
+
Hook for custom error pages that still want automatic error reporting. Use when you want your own UI but still want DeepTracer to capture the error.
|
|
118
|
+
|
|
119
|
+
**Parameters:**
|
|
120
|
+
- `error: Error` — the error to report
|
|
121
|
+
- `severity: "low" | "medium" | "high" | "critical"` — default: `"high"`
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
// app/error.tsx — custom UI with automatic reporting
|
|
125
|
+
"use client"
|
|
126
|
+
import { useDeepTracerErrorReporter } from "@deeptracer/react"
|
|
127
|
+
|
|
128
|
+
export default function ErrorPage({ error, reset }: { error: Error; reset: () => void }) {
|
|
129
|
+
useDeepTracerErrorReporter(error)
|
|
130
|
+
return (
|
|
131
|
+
<div>
|
|
132
|
+
<h2>Oops! {error.message}</h2>
|
|
133
|
+
<button onClick={reset}>Try again</button>
|
|
134
|
+
</div>
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
### `DeepTracerErrorBoundary`
|
|
142
|
+
|
|
143
|
+
Class-based React error boundary that catches rendering errors in child components and reports them to DeepTracer.
|
|
144
|
+
|
|
145
|
+
**Props:**
|
|
146
|
+
|
|
147
|
+
| Prop | Type | Description |
|
|
148
|
+
|------|------|-------------|
|
|
149
|
+
| `fallback` | `ReactNode \| (({ error, resetErrorBoundary }) => ReactNode)` | Content to show on error. |
|
|
150
|
+
| `children` | `ReactNode` | Components to protect. |
|
|
151
|
+
| `onError` | `(error: Error, errorInfo: ErrorInfo) => void` | Called after the error is caught and reported. |
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
import { DeepTracerErrorBoundary } from "@deeptracer/react"
|
|
155
|
+
|
|
156
|
+
// Static fallback
|
|
157
|
+
<DeepTracerErrorBoundary fallback={<div>Something went wrong</div>}>
|
|
158
|
+
<MyComponent />
|
|
159
|
+
</DeepTracerErrorBoundary>
|
|
160
|
+
|
|
161
|
+
// Render function fallback
|
|
162
|
+
<DeepTracerErrorBoundary
|
|
163
|
+
fallback={({ error, resetErrorBoundary }) => (
|
|
164
|
+
<div>
|
|
165
|
+
<p>Error: {error.message}</p>
|
|
166
|
+
<button onClick={resetErrorBoundary}>Retry</button>
|
|
167
|
+
</div>
|
|
168
|
+
)}
|
|
169
|
+
>
|
|
170
|
+
<MyComponent />
|
|
171
|
+
</DeepTracerErrorBoundary>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
### `useLogger()`
|
|
177
|
+
|
|
178
|
+
Hook that returns the DeepTracer Logger from context. Throws with a clear error message if used outside a `<DeepTracerProvider>`.
|
|
179
|
+
|
|
180
|
+
```tsx
|
|
181
|
+
import { useLogger } from "@deeptracer/react"
|
|
182
|
+
|
|
183
|
+
function MyComponent() {
|
|
184
|
+
const logger = useLogger()
|
|
185
|
+
|
|
186
|
+
async function handleSubmit() {
|
|
187
|
+
try {
|
|
188
|
+
await submitData()
|
|
189
|
+
logger.info("Form submitted successfully")
|
|
190
|
+
} catch (error) {
|
|
191
|
+
logger.captureError(error, { severity: "high" })
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return <button onClick={handleSubmit}>Submit</button>
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Re-exported from @deeptracer/browser
|
|
200
|
+
|
|
201
|
+
All exports from `@deeptracer/browser` and `@deeptracer/core` are available directly from this package. You do not need to install them separately.
|
|
202
|
+
|
|
203
|
+
## Monorepo
|
|
204
|
+
|
|
205
|
+
This package is part of the [DeepTracer JavaScript SDK](https://github.com/getdeeptracer/deeptracer-js) monorepo:
|
|
206
|
+
|
|
207
|
+
| Package | Description |
|
|
208
|
+
|---------|-------------|
|
|
209
|
+
| [`@deeptracer/core`](https://github.com/getdeeptracer/deeptracer-js/tree/main/packages/core) | Zero-dependency shared core |
|
|
210
|
+
| [`@deeptracer/node`](https://github.com/getdeeptracer/deeptracer-js/tree/main/packages/node) | Node.js/Bun SDK |
|
|
211
|
+
| [`@deeptracer/ai`](https://github.com/getdeeptracer/deeptracer-js/tree/main/packages/ai) | AI SDK wrappers |
|
|
212
|
+
| [`@deeptracer/browser`](https://github.com/getdeeptracer/deeptracer-js/tree/main/packages/browser) | Browser SDK |
|
|
213
|
+
| **`@deeptracer/react`** | React integration (this package) |
|
|
214
|
+
| [`@deeptracer/nextjs`](https://github.com/getdeeptracer/deeptracer-js/tree/main/packages/nextjs) | Next.js integration |
|
|
215
|
+
|
|
216
|
+
## Links
|
|
217
|
+
|
|
218
|
+
- [deeptracer.dev](https://deeptracer.dev) — Homepage
|
|
219
|
+
- [Docs](https://deeptracer.dev/docs) — Documentation
|
|
220
|
+
- [GitHub](https://github.com/getdeeptracer/deeptracer-js) — Source code
|
|
221
|
+
|
|
222
|
+
## License
|
|
223
|
+
|
|
224
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deeptracer/react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "DeepTracer React integration — provider, error boundary, and hooks for automatic error capture",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@deeptracer/browser": "0.3.
|
|
35
|
+
"@deeptracer/browser": "0.3.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": ">=18",
|