sb-dev/openquant / .agents/skills/otel-instrumentation
otel-instrumentation
VerifiedConfigures trace spans, defines custom metrics, sets up log exporters, and optimizes sampling strategies for OpenTelemetry instrumentation. Use when instrumenting applications with traces, metrics, or logs. Triggers on requests for observability, telemetry, tracing, metrics collection, logging integration, or OTel setup.
| File | Kind | Size |
|---|---|---|
| README.md | markdown | 4.8 KB |
| SKILL.md | skill md | 6.0 KB |
| rules/capture-database-query-parameters.md | markdown | 4.9 KB |
| rules/logs.md | markdown | 10.1 KB |
| rules/metrics.md | markdown | 22.7 KB |
| rules/platforms/k8s.md | markdown | 7.7 KB |
| rules/resolve-values.md | markdown | 11.3 KB |
| rules/resources.md | markdown | 10.9 KB |
| rules/sdks/browser.md | markdown | 5.2 KB |
| rules/sdks/dotnet.md | markdown | 20.6 KB |
| rules/sdks/go.md | markdown | 29.9 KB |
| rules/sdks/java.md | markdown | 17.2 KB |
| rules/sdks/nextjs.md | markdown | 16.2 KB |
| rules/sdks/nodejs.md | markdown | 24.7 KB |
| rules/sdks/php.md | markdown | 16.2 KB |
| rules/sdks/python.md | markdown | 18.4 KB |
| rules/sdks/ruby.md | markdown | 15.1 KB |
| rules/sdks/scala.md | markdown | 23.6 KB |
| rules/sensitive-data.md | markdown | 16.2 KB |
| rules/spans.md | markdown | 32.0 KB |
| rules/telemetry.md | markdown | 2.1 KB |
| rules/validation.md | markdown | 8.9 KB |
| rules/verify-dependencies.md | markdown | 6.6 KB |
rules/sdks/browser.md
View on GitHub---
title: 'Browser Instrumentation'
impact: HIGH
tags:
- browser
- web
- frontend
- rum
---
# Browser Instrumentation
Instrument web applications to monitor performance, user sessions, requests, and errors.
## Use Cases
- **Real User Monitoring (RUM)**: Capture actual user performance metrics including page load times and resource loading
- **Frontend Performance Analysis**: Identify bottlenecks in network requests, script execution, and rendering
- **Error Tracking**: Capture uncaught JavaScript errors and promise rejections
- **End-to-End Tracing**: Connect frontend interactions with backend traces
- **Custom Instrumentation**: Monitor specific user interactions or business logic workflows
## Option 1: Dash0 SDK Web (Recommended)
100% open source. Designed to work with Dash0. Simplest setup with sensible defaults.
### Prerequisites
1. **OTLP Endpoint**: Your observability platform's HTTP endpoint
- In Dash0: [Settings → Organization → Endpoints → "OTLP via HTTP"](https://app.dash0.com/settings/endpoints?s=eJwtyzEOgCAQRNG7TG1Cb29h5REMcVclIUDYsSLcXUxsZ95vcJgbxNObEjNET_9Eok9wY2FIlzlNUnJItM_GYAM2WK7cqmgdlbcDE0yjHlRZfr7KuDJj2W-yoPf-AmNVJ2I%3D)
- Format: `https://<region>.your-platform.com`
2. **Auth Token**: API token for telemetry ingestion
- In Dash0: [Settings → Auth Tokens → Create Token](https://app.dash0.com/settings/auth-tokens)
**Security**: Browser auth tokens are exposed in client code. Use a dedicated auth token with:
- Limited dataset access
- `Ingesting` permissions only
- No access to sensitive data or admin functions
### Installation
```bash
npm install @dash0/sdk-web
```
### Initialization
Initialize as early as possible in your application:
```javascript
import { init } from '@dash0/sdk-web';
init({
serviceName: 'my-frontend',
endpoint: {
url: 'https://<OTLP_ENDPOINT>',
authToken: 'YOUR_AUTH_TOKEN',
},
});
```
For Next.js, use the `instrumentation-client.js` file.
### Features
Auto-instrumentation captures without code modifications:
- Page loads and navigation timing
- Fetch/XHR requests with trace propagation
- User sessions
- JavaScript errors and promise rejections
### Customization
```javascript
// Add custom attributes
import { addAttributes } from '@dash0/sdk-web';
addAttributes({ 'user.tier': 'premium' });
// Identify users
import { setUser } from '@dash0/sdk-web';
setUser({ id: 'user-123' });
// Report custom errors
import { reportError } from '@dash0/sdk-web';
reportError(new Error('Custom error'));
// Send custom events
import { sendEvent } from '@dash0/sdk-web';
sendEvent('checkout.completed', { order_id: '123' });
```
### Resources
- [GitHub Repository](https://github.com/dash0hq/dash0-sdk-web)
## Option 2: OpenTelemetry JS SDK
OpenTelemetry's official SDK for browser instrumentation. Use when you need fine-grained control.
**Note**: Currently experimental.
### Installation
```bash
npm install @opentelemetry/api \
@opentelemetry/sdk-trace-web \
@opentelemetry/auto-instrumentations-web \
@opentelemetry/exporter-trace-otlp-http
```
For bundling (Rollup example):
```bash
npm install --save-dev rollup @rollup/plugin-node-resolve rollup-plugin-commonjs
```
Add to `package.json`:
```json
{ "type": "module" }
```
### Initialization
Create `instrumentation.js`:
```javascript
import {
WebTracerProvider,
BatchSpanProcessor,
AlwaysOnSampler,
} from '@opentelemetry/sdk-trace-web';
import { getWebAutoInstrumentations } from '@opentelemetry/auto-instrumentations-web';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
const provider = new WebTracerProvider({
// The browser has no environment variables, so the AlwaysOn sampler must be
// set in code; see ../spans.md#sampling.
sampler: new AlwaysOnSampler(),
spanProcessors: [
new BatchSpanProcessor(
new OTLPTraceExporter({
url: 'https://<OTLP_ENDPOINT>/v1/traces',
headers: { Authorization: 'Bearer YOUR_AUTH_TOKEN' },
}),
),
],
});
provider.register();
registerInstrumentations({
instrumentations: [getWebAutoInstrumentations()],
});
```
### Bundling
Create `rollup.config.js`:
```javascript
import resolve from '@rollup/plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
export default {
input: 'src/instrumentation.js',
output: { file: 'dist/index.js', format: 'iife' },
plugins: [resolve(), commonjs()],
};
```
Build:
```bash
npm run build
```
### HTML Integration
```html
<script src="dist/index.js"></script>
```
### Testing
Open your website in a browser. Network tab will show calls to the Dash0 ingestion API.
### Resources
- [OpenTelemetry JS Documentation](https://opentelemetry.io/docs/languages/js/getting-started/browser/)
## Browser-to-Server Correlation
To connect frontend traces with backend traces:
### 1. Configure Trace Propagation
```javascript
import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';
new FetchInstrumentation({
propagateTraceHeaderCorsUrls: [/api\.yoursite\.com/],
});
```
### 2. Backend CORS Configuration
```javascript
app.use(
cors({
allowedHeaders: [
'Content-Type',
'Authorization',
'traceparent',
'tracestate',
],
}),
);
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |