Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demo/otel-collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ receivers:
cors:
allowed_origins:
- "https://mquentin.github.io"
- "http://localhost:5173"
allowed_headers:
- "*"

Expand Down
9 changes: 8 additions & 1 deletion examples/all-instrumentations/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@
<body>
<open-telemetry>
<h1>OpenTelemetry Browser Instrumentations</h1>
<p>Open the browser console to see instrumentation output.</p>
<p>
Open the browser console to see instrumentation output. Logs include
<code>session.id</code>
and <code>browser.document.url.full</code> as resource attributes.
</p>
<button id="test-button" type="button">Test Click</button>
<button id="xhr-button" type="button">Send XHR</button>
<button id="fetch-button" type="button">Send Fetch</button>
<button id="push-history-button" type="button">Push History</button>
<button id="rotate-session-button" type="button">Rotate Session</button>
<p id="status"></p>
</open-telemetry>
</body>
</html>
7 changes: 4 additions & 3 deletions examples/all-instrumentations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
},
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/api-logs": "^0.213.0",
"@opentelemetry/sdk-logs": "^0.213.0",
"@opentelemetry/browser-instrumentation": "file:../../packages/instrumentation",
"@opentelemetry/browser-sdk": "file:../../packages/sdk-browser",
"@opentelemetry/exporter-logs-otlp-http": "^0.213.0",
"@opentelemetry/instrumentation": "^0.213.0",
"@opentelemetry/browser-instrumentation": "file:../../packages/instrumentation"
"@opentelemetry/sdk-logs": "^0.213.0"
}
}
45 changes: 38 additions & 7 deletions examples/all-instrumentations/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
import './style.css';
import { DiagConsoleLogger, DiagLogLevel, diag } from '@opentelemetry/api';
import { logs } from '@opentelemetry/api-logs';
import { NavigationTimingInstrumentation } from '@opentelemetry/browser-instrumentation/experimental/navigation-timing';
import { ResourceTimingInstrumentation } from '@opentelemetry/browser-instrumentation/experimental/resource-timing';
import { UserActionInstrumentation } from '@opentelemetry/browser-instrumentation/experimental/user-action';
import { WebVitalsInstrumentation } from '@opentelemetry/browser-instrumentation/experimental/web-vitals';
import { initializeSdk } from '@opentelemetry/browser-sdk/experimental/entities';
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import {
BatchLogRecordProcessor,
ConsoleLogRecordExporter,
LoggerProvider,
SimpleLogRecordProcessor,
} from '@opentelemetry/sdk-logs';

diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.VERBOSE);

const loggerProvider = new LoggerProvider({
processors: [new SimpleLogRecordProcessor(new ConsoleLogRecordExporter())],
const sdk = initializeSdk({
serviceName: 'examples-all-instrumentations',
serviceVersion: '0.0.0',
logRecordProcessors: [
new SimpleLogRecordProcessor(new ConsoleLogRecordExporter()),
new BatchLogRecordProcessor(
new OTLPLogExporter({ url: 'http://localhost:4318/v1/logs' }),
),
],
});

logs.setGlobalLoggerProvider(loggerProvider);

registerInstrumentations({
instrumentations: [
new NavigationTimingInstrumentation(),
Expand All @@ -31,12 +37,37 @@ registerInstrumentations({
],
});

// ── UI wiring ───────────────────────────────────────────────────────────────
const status = document.getElementById('status');
const updateStatus = () => {
if (!status) {
return;
}
status.textContent = `session.id=${sdk.getSessionId() ?? '<none>'} · browser.document.url.full=${sdk.documentTracker.getHref()}`;
};
sdk.documentTracker.addObserver(() => updateStatus());
updateStatus();

document.getElementById('xhr-button')?.addEventListener('click', () => {
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://httpbin.org/get');
xhr.send();
});

document.getElementById('fetch-button')?.addEventListener('click', () => {
fetch('https://httpbin.org/get');
void fetch('https://httpbin.org/get');
});

document
.getElementById('push-history-button')
?.addEventListener('click', () => {
const next = `${window.location.pathname}?n=${Math.floor(Math.random() * 1000)}`;
history.pushState({}, '', next);
});

document
.getElementById('rotate-session-button')
?.addEventListener('click', () => {
sdk.rotateSession();
updateStatus();
});
Loading
Loading