From 4460a14251b593c710e9dd58db47ac20fba4b68b Mon Sep 17 00:00:00 2001 From: Ryan Stutzman Date: Fri, 21 Nov 2025 14:53:04 -0500 Subject: [PATCH] feat: add DATADOG_STORAGE_TIER env support for logs tools --- README.md | 8 ++++++-- src/tools/logs/tool.ts | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7273e95..08b606f 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,7 @@ You need valid Datadog API credentials to use this MCP server: - `DATADOG_APP_KEY`: Your Datadog Application key - `DATADOG_SITE` (optional): The Datadog site (e.g. `datadoghq.eu`) - `DATADOG_SUBDOMAIN` (optional): The Datadog subdomain (e.g. `.datadoghq.com`) +- `DATADOG_STORAGE_TIER` (optional): Logs storage tier for v2 logs searches. Supported values: `indexes`, `online-archives`, or `flex`. Use `flex` for non-prod SAAS environments where logs are stored in the Flex tier. Export them in your environment before running the server: @@ -221,6 +222,7 @@ export DATADOG_API_KEY="your_api_key" export DATADOG_APP_KEY="your_app_key" export DATADOG_SITE="your_datadog_site" # Optional export DATADOG_SUBDOMAIN="your_datadog_subdomain" # Optional +export DATADOG_STORAGE_TIER="flex" # Optional: indexes | online-archives | flex ``` ## Installation @@ -271,7 +273,8 @@ On Windows: `%APPDATA%/Claude/claude_desktop_config.json` "DATADOG_API_KEY": "", "DATADOG_APP_KEY": "", "DATADOG_SITE": "", // Optional - "DATADOG_SUBDOMAIN": "" // Optional + "DATADOG_SUBDOMAIN": "", // Optional + "DATADOG_STORAGE_TIER": "indexes" // Optional: indexes | online-archives | flex } } } @@ -290,7 +293,8 @@ Or specify via `npx`: "DATADOG_API_KEY": "", "DATADOG_APP_KEY": "", "DATADOG_SITE": "", // Optional - "DATADOG_SUBDOMAIN": "" // Optional + "DATADOG_SUBDOMAIN": "", // Optional + "DATADOG_STORAGE_TIER": "indexes" // Optional: indexes | online-archives | flex } } } diff --git a/src/tools/logs/tool.ts b/src/tools/logs/tool.ts index 322a7f7..fa107c8 100644 --- a/src/tools/logs/tool.ts +++ b/src/tools/logs/tool.ts @@ -1,11 +1,36 @@ -import { ExtendedTool, ToolHandlers } from '../../utils/types' import { v2 } from '@datadog/datadog-api-client' +import { log } from '../../utils/helper' import { createToolSchema } from '../../utils/tool' -import { GetLogsZodSchema, GetAllServicesZodSchema } from './schema' +import { ExtendedTool, ToolHandlers } from '../../utils/types' +import { GetAllServicesZodSchema, GetLogsZodSchema } from './schema' type LogsToolName = 'get_logs' | 'get_all_services' type LogsTool = ExtendedTool +// Storage tier configuration from environment +const SUPPORTED_STORAGE_TIERS = ['indexes', 'online-archives', 'flex'] as const +type StorageTier = (typeof SUPPORTED_STORAGE_TIERS)[number] + +const configuredStorageTier: StorageTier | undefined = (() => { + const value = process.env.DATADOG_STORAGE_TIER + if (!value) { + return undefined + } + + const normalized = value.toLowerCase() + if (!SUPPORTED_STORAGE_TIERS.includes(normalized as StorageTier)) { + log( + 'error', + `Invalid DATADOG_STORAGE_TIER="${value}". Supported values: ${SUPPORTED_STORAGE_TIERS.join( + ', ', + )}`, + ) + return undefined + } + + return normalized as StorageTier +})() + export const LOGS_TOOLS: LogsTool[] = [ createToolSchema( GetLogsZodSchema, @@ -36,6 +61,10 @@ export const createLogsToolHandlers = ( // `from` and `to` are in epoch seconds, but the Datadog API expects milliseconds from: `${from * 1000}`, to: `${to * 1000}`, + // Optional storage tier for Logs v2 (indexes, online-archives, flex) + ...(configuredStorageTier + ? { storageTier: configuredStorageTier } + : {}), }, page: { limit, @@ -70,6 +99,10 @@ export const createLogsToolHandlers = ( // `from` and `to` are in epoch seconds, but the Datadog API expects milliseconds from: `${from * 1000}`, to: `${to * 1000}`, + // Optional storage tier for Logs v2 (indexes, online-archives, flex) + ...(configuredStorageTier + ? { storageTier: configuredStorageTier } + : {}), }, page: { limit,