Expert guidance for configuring and deploying the OpenTelemetry Collector. Use when setting up a Collector pipeline, configuring receivers, exporters, or processors, deploying a Collector to Kubernetes or Docker, or forwarding telemetry to Dash0. Triggers on requests involving collector, pipeline, OTLP receiver, exporter, or Dash0 collector setup.
100
100%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Advisory
Suggest reviewing before use
Instrument web applications to monitor performance, user sessions, requests, and errors.
100% open source. Designed to work with Dash0. Simplest setup with sensible defaults.
https://<region>.your-platform.comSecurity: Browser auth tokens are exposed in client code. Use a dedicated auth token with:
Ingesting permissions onlynpm install @dash0/sdk-webInitialize as early as possible in your application:
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.
Auto-instrumentation captures without code modifications:
// 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' });OpenTelemetry's official SDK for browser instrumentation. Use when you need fine-grained control.
Note: Currently experimental.
npm install @opentelemetry/api \
@opentelemetry/sdk-trace-web \
@opentelemetry/auto-instrumentations-web \
@opentelemetry/exporter-trace-otlp-httpFor bundling (Rollup example):
npm install --save-dev rollup @rollup/plugin-node-resolve rollup-plugin-commonjsAdd to package.json:
{ "type": "module" }Create instrumentation.js:
import {
WebTracerProvider,
BatchSpanProcessor,
} 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();
provider.addSpanProcessor(
new BatchSpanProcessor(
new OTLPTraceExporter({
url: 'https://<OTLP_ENDPOINT>/v1/traces',
headers: { Authorization: 'Bearer YOUR_AUTH_TOKEN' },
}),
),
);
provider.register();
registerInstrumentations({
instrumentations: [getWebAutoInstrumentations()],
});Create rollup.config.js:
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:
npm run build<script src="dist/index.js"></script>Open your website in a browser. Network tab will show calls to the Dash0 ingestion API.
To connect frontend traces with backend traces:
import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';
new FetchInstrumentation({
propagateTraceHeaderCorsUrls: [/api\.yoursite\.com/],
});app.use(
cors({
allowedHeaders: [
'Content-Type',
'Authorization',
'traceparent',
'tracestate',
],
}),
);