Skip to Content
Octopus Energy Packages

Recipes

Common use cases and best practices

Setting the log target

Send an info event to Datadog with extra context:

import { reportEvent } from "@octopus-energy/logs";

reportEvent({
  reportTo: "datadog",
  eventType: "meter_power_change",
  description: "User requested a change in meter power capacity to 4.5kW",
  severity: "info",
  meta: { source: "MeterPowerCapacityChange" },
  extra: { accountNumber },
});

Event types

You can pass any string as eventType, but the use of an explicit type is recommended for better consistency and discoverability.

export const EventType = {
  BlockedRequest: "blocked_request",
  GraphQLError: "graphql_error",
  GenericInfo: "generic_info",
  InvalidData: "invalid_data",
  MissingData: "missing_data",
  UnexpectedError: "unexpected_error",
  ValidationError: "validation_error",
} as const;

export type EventType = (typeof EventType)[keyof typeof EventType];

Pass a generic type to reportEvent to restrict accepted values:

import { reportEvent } from "@octopus-energy/logs";

reportEvent<EventType>({
  reportTo: "datadog",
  eventType: "graphql_error",
  description: "Mutation failed",
});

On this page