@glimt.dev/otel-browser 0.1.2 → 0.2.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 CHANGED
@@ -5,7 +5,7 @@ OpenTelemetry for the browser. Works out of the box, highly configurable.
5
5
  ## Quick Start (3 lines)
6
6
 
7
7
  ```bash
8
- npm install @glimt.dev/otel-browser
8
+ npm install @glimt.dev/otel-browser @opentelemetry/api @opentelemetry/api-logs
9
9
  ```
10
10
 
11
11
  ```ts
@@ -14,7 +14,31 @@ import { registerOTelBrowser } from '@glimt.dev/otel-browser'
14
14
  registerOTelBrowser({ serviceName: 'my-web-app' })
15
15
  ```
16
16
 
17
- Done. Traces go to `http://localhost:4318/v1/traces`, logs to `/v1/logs`.
17
+ Done. Traces go to `https://ingest.glimt.dev/v1/traces`, logs to `/v1/logs`.
18
+
19
+ ### Local Development
20
+
21
+ For local development with a local collector:
22
+
23
+ ```ts
24
+ registerOTelBrowser({
25
+ serviceName: 'my-web-app',
26
+ exporterUrl: 'http://localhost:4318',
27
+ })
28
+ ```
29
+
30
+ ### Production: Glimt.dev Ingest
31
+
32
+ For production with Glimt authentication:
33
+
34
+ ```ts
35
+ registerOTelBrowser({
36
+ serviceName: 'my-web-app',
37
+ // exporterUrl defaults to https://ingest.glimt.dev
38
+ organisationId: 'your-org-id',
39
+ publishableKey: 'your-publishable-key',
40
+ })
41
+ ```
18
42
 
19
43
  ---
20
44
 
@@ -31,8 +55,16 @@ const sdk = registerOTelBrowser({
31
55
  organisationId: 'org_xxx',
32
56
  publishableKey: 'pk_xxx',
33
57
 
34
- // Export
35
- exporterUrl: 'https://ingest.glimt.dev/v1/traces',
58
+ // Release metadata (CRITICAL for source mapping)
59
+ release: {
60
+ commit: process.env.NEXT_PUBLIC_COMMIT_SHA, // or 'abc1234'
61
+ branch: process.env.NEXT_PUBLIC_COMMIT_REF, // or 'main'
62
+ version: '1.0.0',
63
+ environment: 'production',
64
+ },
65
+
66
+ // Export - base URL, SDK derives /v1/traces and /v1/logs
67
+ exporterUrl: 'https://ingest.glimt.dev',
36
68
  exporter: 'http/protobuf', // or 'http/json'
37
69
  exporterHeaders: { 'x-tenant-id': 'acme' },
38
70
  credentials: 'include', // for CORS
@@ -50,9 +82,9 @@ const sdk = registerOTelBrowser({
50
82
  },
51
83
 
52
84
  // Capture
53
- errors: { captureUnhandled: true },
54
- console: { enabled: true }, // capture console.* as logs
55
- includeUserAgent: false, // privacy default
85
+ captureUnhandledErrors: true, // window.onerror, unhandledrejection (default: true)
86
+ captureConsoleLogs: true, // console.* as OTLP logs (default: false)
87
+ includeUserAgent: false, // privacy default
56
88
 
57
89
  // Initial user context
58
90
  user: { userId: 'user_123', role: 'admin' },
@@ -68,6 +100,35 @@ sdk.setUserContext(null)
68
100
 
69
101
  ---
70
102
 
103
+ ## Environment Variables (via Build Tools)
104
+
105
+ Browsers don't have runtime environment variables, but you can inject them at build time using your bundler:
106
+
107
+ **Next.js (`next.config.mjs`):**
108
+ ```js
109
+ // Automatically available as process.env.NEXT_PUBLIC_*
110
+ // Set in .env or CI environment
111
+ ```
112
+
113
+ **Vite (`vite.config.ts`):**
114
+ ```ts
115
+ export default defineConfig({
116
+ define: {
117
+ 'import.meta.env.VITE_OTEL_ENDPOINT': JSON.stringify(process.env.OTEL_EXPORTER_OTLP_ENDPOINT),
118
+ 'import.meta.env.VITE_COMMIT_SHA': JSON.stringify(process.env.COMMIT_SHA),
119
+ }
120
+ })
121
+ ```
122
+
123
+ **Webpack:**
124
+ ```js
125
+ new webpack.DefinePlugin({
126
+ 'process.env.OTEL_ENDPOINT': JSON.stringify(process.env.OTEL_EXPORTER_OTLP_ENDPOINT),
127
+ })
128
+ ```
129
+
130
+ ---
131
+
71
132
  ## React / Next.js Integration
72
133
 
73
134
  ```tsx
@@ -83,6 +144,11 @@ export function TelemetryProvider({ userId }: { userId?: string }) {
83
144
  serviceName: process.env.NEXT_PUBLIC_OTEL_SERVICE_NAME!,
84
145
  exporterUrl: process.env.NEXT_PUBLIC_OTEL_EXPORTER_OTLP_ENDPOINT,
85
146
  user: userId ? { userId } : undefined,
147
+ release: {
148
+ commit: process.env.NEXT_PUBLIC_COMMIT_SHA || process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA,
149
+ branch: process.env.NEXT_PUBLIC_COMMIT_REF || process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF,
150
+ environment: process.env.NEXT_PUBLIC_VERCEL_ENV,
151
+ }
86
152
  })
87
153
  }, [])
88
154
 
@@ -139,8 +205,8 @@ Access-Control-Allow-Credentials: true (if using credentials)
139
205
 
140
206
  | Feature | Default |
141
207
  |---------|---------|
142
- | Trace exporter | `http/protobuf` → `localhost:4318/v1/traces` |
143
- | Log exporter | `http/protobuf` → auto-derived `/v1/logs` |
208
+ | Trace exporter | `http/protobuf` → `https://ingest.glimt.dev/v1/traces` |
209
+ | Log exporter | `http/protobuf` → `https://ingest.glimt.dev/v1/logs` |
144
210
  | Instrumentations | document-load, user-interaction, xhr, fetch |
145
211
  | Error capture | `window.onerror`, `unhandledrejection` |
146
212
  | User agent | NOT included (privacy) |