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.
88%
Does it follow best practices?
Impact
97%
1.15xAverage score across 14 eval scenarios
Low
Low-risk findings worth noting
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:
Session replay is opt-in.
The init() call shown above does not start it, because the @dash0/sdk-web bundle contains no recorder: the recorder ships as the separate @dash0/sdk-web/session-recording entry point.
Session replay records the DOM of every page a visitor sees, so turning it on widens what the site collects about its visitors beyond what browser instrumentation alone collects. Decide whether to enable it from the request:
| The request | Do this |
|---|---|
| Asks for session replay, session recording, or replay by name | Enable it, following the snippet below. |
| Asks for browser instrumentation without mentioning session replay, and the user can be asked | Ask whether to enable session replay, and leave it off until the user answers. |
| Asks for browser instrumentation without mentioning session replay, and the user cannot be asked | Leave it off, and report that it was left off and which snippet below enables it. |
Never add a recorder as an unrequested extra while making an unrelated change to the SDK setup.
Recording starts as soon as a recorder reaches the SDK through any one of these three routes:
sessionRecording.recorder passed to init().startSessionRecording(recorder) call.dash0-session-recording.iife.js script tag, which sets window.dash0Recorder.
init() picks that global up on its own, whatever the order in which the two scripts execute.To keep session replay off, use none of the three routes.
Route 3 is the one that turns replay on without any sessionRecording configuration being visible in the init() call, so check the page's script tags, not just the SDK setup code.
To verify which state a site is in, call setActiveLogLevel('debug') before init() and load the page.
A running recorder logs Session recording started to the browser console.
A configured recorder whose session fell outside samplingRate logs Session recording will not start instead, so treat that message as replay being enabled, not disabled.
To enable session replay, pass the recorder to init():
import { init } from '@dash0/sdk-web';
import { recorder } from '@dash0/sdk-web/session-recording';
init({
serviceName: 'my-frontend',
endpoint: {
url: 'https://<OTLP_ENDPOINT>',
authToken: 'YOUR_AUTH_TOKEN',
},
sessionRecording: { recorder },
});Stop a running recording with stopSessionRecording().
Recording does not resume until startSessionRecording() is called again.
The sessionRecording settings below take effect only when a recorder is provided.
Set them in the same init() call.
| Setting | Default | Change it when |
|---|---|---|
samplingRate | 100 | Recording every session produces more replay data than the dataset should hold. Recorded sessions are always a subset of the sessions that transmit telemetry. |
maskAllInputs | true | Never set this to false unless no form on the page accepts personal or sensitive data. |
maskTextSelector | unset | The page renders personal data as text rather than in inputs. Use "*" to mask all text. |
maskTextClass | "dash0-mask" | The page already uses that class name for something else. |
blockClass | "dash0-block" | The page already uses that class name for something else. |
blockSelector | unset | Elements must not be recorded at all, including <input type="hidden"> values, which maskAllInputs does not mask because they are element attributes. |
recordCanvas | false | The replay is useless without canvas content, and the added payload size is acceptable. |
import { init } from '@dash0/sdk-web';
import { recorder } from '@dash0/sdk-web/session-recording';
init({
serviceName: 'my-frontend',
endpoint: {
url: 'https://<OTLP_ENDPOINT>',
authToken: 'YOUR_AUTH_TOKEN',
},
sessionRecording: {
recorder,
samplingRate: 10,
maskTextSelector: '.customer-name, .order-total',
blockSelector: '[data-pii]',
},
});// Add custom attributes, one name and value per call
import { addSignalAttribute } from '@dash0/sdk-web';
addSignalAttribute('user.tier', 'premium');
// Identify users
import { identify } from '@dash0/sdk-web';
identify('user-123');
// Report custom errors
import { reportError } from '@dash0/sdk-web';
reportError(new Error('Custom error'));
// Send custom events, with attributes nested under `attributes`
import { sendEvent } from '@dash0/sdk-web';
sendEvent('checkout.completed', { attributes: { 'order.id': '123' } });addSignalAttribute applies to signals transmitted after the call.
To attach attributes to the signals of the initial page load, pass additionalSignalAttributes to init() instead.
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,
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()],
});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',
],
}),
);.tessl-plugin
skills
otel-collector
otel-instrumentation
otel-ottl
otel-semantic-conventions