The SDK provides internal logging functionality to help with debugging and troubleshooting. You can control the verbosity of SDK logs and inspect the current configuration state.
Critical Debug and Logging Behavior:
warndebug() outputs to console synchronouslywarnChanges the active log level of the SDK to control internal logging verbosity.
/**
* Changes the logging verbosity of Dash0's Web SDK
* @param level - The log level to set
* @throws No errors thrown; invalid levels may be ignored
*/
function setActiveLogLevel(level: LogLevel): void;
type LogLevel = "debug" | "info" | "warn" | "error";Default log level: warn
Usage Examples:
import { setActiveLogLevel } from "@dash0/sdk-web";
// Enable debug logging for troubleshooting
setActiveLogLevel("debug");
// Set to info level for moderate verbosity
setActiveLogLevel("info");
// Set to warn (default)
setActiveLogLevel("warn");
// Only show errors
setActiveLogLevel("error");For IIFE (script tag) usage:
dash0("setActiveLogLevel", "debug");Critical Behavior:
warninit() affects initialization loggingLogs the current SDK configuration state to the console.
/**
* Logs the current Dash0 Web SDK configuration state
* @throws No errors thrown; console errors may occur if console is unavailable
*/
function debug(): void;Usage Example:
import { debug } from "@dash0/sdk-web";
// Log current configuration
debug();For IIFE (script tag) usage:
dash0("debug");This will output the internal SDK state including:
Critical Behavior:
debug() before init() may show incomplete configurationThe SDK supports four log levels, each including messages from higher severity levels:
Most verbose level. Includes all SDK internal operations.
setActiveLogLevel("debug");Use for:
Critical Behavior:
Informational messages about SDK operations.
setActiveLogLevel("info");Use for:
Critical Behavior:
Warnings about potential issues that don't prevent SDK operation.
setActiveLogLevel("warn");Use for:
Critical Behavior:
Only critical errors that affect SDK functionality.
setActiveLogLevel("error");Use for:
Critical Behavior:
Enable debug logging during development:
import { init, setActiveLogLevel } from "@dash0/sdk-web";
// Enable debug logging in development
if (process.env.NODE_ENV === "development") {
setActiveLogLevel("debug");
}
init({
serviceName: "my-website",
endpoint: { url: "...", authToken: "..." },
});Use debug logging and configuration inspection when troubleshooting:
import { init, setActiveLogLevel, debug } from "@dash0/sdk-web";
// Enable debug logging
setActiveLogLevel("debug");
// Initialize SDK
init({
serviceName: "my-website",
endpoint: { url: "...", authToken: "..." },
propagators: [
{ type: "traceparent", match: [/.*\/api\/.*/] },
],
});
// Inspect configuration
debug();
// Check browser console for detailed logsUse warn level in production, with ability to enable debug on demand:
import { init, setActiveLogLevel } from "@dash0/sdk-web";
// Default to warn level
setActiveLogLevel("warn");
// Initialize SDK
init({
serviceName: "my-website",
endpoint: { url: "...", authToken: "..." },
});
// Make setActiveLogLevel available globally for debugging
if (typeof window !== "undefined") {
window.enableDash0Debug = () => setActiveLogLevel("debug");
window.disableDash0Debug = () => setActiveLogLevel("warn");
}Then in browser console:
// Enable debug logging in production for troubleshooting
window.enableDash0Debug();
// Disable when done
window.disableDash0Debug();Enable debug logging for specific users or sessions:
import { init, setActiveLogLevel, identify } from "@dash0/sdk-web";
init({
serviceName: "my-website",
endpoint: { url: "...", authToken: "..." },
});
// After user login
async function handleLogin(userId) {
// Enable debug logging for specific users
if (isDebugUser(userId)) {
setActiveLogLevel("debug");
}
identify(userId);
}Allow enabling debug mode via query parameter:
import { init, setActiveLogLevel } from "@dash0/sdk-web";
// Check for debug query parameter
const urlParams = new URLSearchParams(window.location.search);
const debugMode = urlParams.get("dash0_debug") === "true";
if (debugMode) {
setActiveLogLevel("debug");
console.log("Dash0 debug mode enabled via query parameter");
}
init({
serviceName: "my-website",
endpoint: { url: "...", authToken: "..." },
});Usage: https://example.com?dash0_debug=true
Minimize logging overhead in performance-critical scenarios:
import { init, setActiveLogLevel } from "@dash0/sdk-web";
// Only log errors
setActiveLogLevel("error");
init({
serviceName: "my-website",
endpoint: { url: "...", authToken: "..." },
});Use different log levels for different environments:
import { init, setActiveLogLevel } from "@dash0/sdk-web";
// Configure log level based on environment
const logLevels = {
development: "debug",
staging: "info",
production: "warn",
};
setActiveLogLevel(logLevels[process.env.NODE_ENV] || "warn");
init({
serviceName: "my-website",
endpoint: { url: "...", authToken: "..." },
});Use debug() to validate configuration after initialization:
import { init, debug } from "@dash0/sdk-web";
init({
serviceName: "my-website",
endpoint: { url: "...", authToken: "..." },
propagators: [
{ type: "traceparent", match: [/.*\/api\/.*/] },
],
ignoreUrls: [/.*\/health$/],
additionalSignalAttributes: {
"app.version": "1.2.3",
},
});
// Verify configuration in console
debug();SDK logs are written to the browser console with prefixes to identify them as Dash0 SDK messages. The exact format depends on the log level:
Critical Behavior:
warn or error levels in production to minimize overheaddebug() function creates a complete snapshot of the configuration stateThe SDK checks for console availability and log method support before attempting to log. If the console or specific log methods are unavailable, logging is silently disabled.
Critical Behavior:
warn"Debug" is not the same as "debug"debug() before init() may show incomplete or empty configurationinit() is called multiple times, debug() shows the current configurationdebug() output includes sensitive information (auth tokens, etc.)