Getting Started
Unified structured logging for Datadog and Sentry
@octopus-energy/logs provides a unified and structured way to log events and errors to both Datadog and Sentry. It supports client-side and server-side logging and is designed to work seamlessly with Next.js.
This package is a drop-in replacement for @krakentech/blueprint-utils/logging.
Quick start
Install the package
npm i @octopus-energy/logsSet up Datadog (client side)
Add the following to your root layout or _app.tsx (see the @datadog/browser-logs docs for full configuration options):
import { datadogLogs } from "@datadog/browser-logs";
useEffect(() => {
if (process.env.NEXT_PUBLIC_ENVIRONMENT === "production") {
datadogLogs.init({
clientToken: process.env.NEXT_PUBLIC_DATADOG_CLIENT_TOKEN,
site: "datadoghq.eu",
service: "your-service-name",
env: "prod",
});
}
}, []);On the server, logs are output using native console methods (console.error, console.warn,
console.info) which are captured by log drains or observability platforms automatically.
Set up Sentry
Configure Sentry in all three Next.js contexts (see the @sentry/nextjs docs for full configuration options):
import * as Sentry from "@sentry/nextjs";
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.NODE_ENV,
});Log your first event
import { reportEvent } from "@octopus-energy/logs";
reportEvent({
reportTo: "both",
eventType: "validation_error",
description: "Wrong POD number",
severity: "error",
error,
meta: { source: "SupplyPointDetailsPage" },
extra: { step: "OnboardingStep.Supply" },
});Migration from @krakentech/blueprint-utils/logging
The API is identical. Swap the import path and you're done:
- import { reportEvent } from "@krakentech/blueprint-utils/logging";
+ import { reportEvent } from "@octopus-energy/logs";Requirements
| Requirement | Version |
|---|---|
| Node.js | ≥24.0.0 |
| Peer dependency | Version | When |
|---|---|---|
next | >=14.2.0 <17.0.0 | Required |
@datadog/browser-logs | ^7.0.0 | Client-side Datadog logging |
@sentry/nextjs | ^10.0.0 || ^11.0.0 | Sentry error capture |