greenatomy-sdk
v0.2.5
Published
Lightweight Node.js SDK for Greenatomy logs and stats APIs.
Downloads
801
Maintainers
Readme
Greenatomy SDK
Lightweight Node.js SDK for the Greenatomy logs and stats APIs.
Install
npm install greenatomy-sdkFor local development from this repository:
npm install ./greenatomy-sdkIf you are working inside the SDK folder directly:
npm installUsage
const GreenatomyClient = require("greenatomy-sdk");
const client = new GreenatomyClient({
baseUrl: "https://greenatomy-1.onrender.com",
apiKey: "ga_live_your_project_key",
timeout: 8000,
});For your production deployment, use the backend URL on Render:
https://greenatomy-1.onrender.com.
You can authenticate with either:
- apiKey (
x-api-key): Recommended for project-specific telemetry ingestion from production/staging/development apps - token (
Authorization: Bearer <token>): Recommended for authenticated dashboard, user, and project management routesreads
You can also override the default request timeout of 5000 ms with timeout.
Current SDK scope:
getLogs()createLog()getStats()getSummary()greenatomyMiddleware()
API
getLogs(params?)
Fetches log entries from GET /logs.
const logs = await client.getLogs({
page: 1,
limit: 20,
});createLog(payload)
Creates a telemetry log via POST /logs.
const createdLog = await client.createLog({
method: "GET",
path: "/api/users",
statusCode: 200,
durationMs: 142,
cpuUsedMs: 38.5,
});Common payload fields:
method(required)path(required)statusCode(optional)durationMs(required)cpuUsedMs(optional, defaults to0)createdAt(optional)
energyKwh, cost, and cpuUtil are calculated by the backend collector and returned in the stored log.
greenatomyMiddleware(options)
Express-style middleware for automatic inbound request telemetry.
const express = require("express");
const GreenatomyClient = require("greenatomy-sdk");
const { greenatomyMiddleware } = GreenatomyClient;
const app = express();
app.use(
greenatomyMiddleware({
baseUrl: "https://greenatomy-1.onrender.com",
apiKey: "ga_live_project_environment_key",
environment: "production",
});
);By default the middleware:
- tracks every inbound request except
OPTIONS - measures wall-clock request duration
- sends
method,path,statusCode,durationMs, andcreatedAt - never blocks the user request if telemetry submission fails
- associates logs with the issuing project API key
- tags logs by environment (
development,staging,production)
Optional middleware options:
shouldTrack(req, res)to selectively skip requestsonError(error, req, res)to observe telemetry transport failurestimeoutto override the default request timeout
getStats(params?)
Fetches aggregated log stats from GET /logs/stats.
const stats = await client.getStats();getSummary(params?)
Fetches a lightweight deployment-ready overview from GET /logs/summary.
const summary = await client.getSummary({ range: "24h" });Error Handling
The SDK throws GreenatomySdkError for HTTP, timeout, and network failures.
const GreenatomyClient = require("greenatomy-sdk");
const { GreenatomySdkError } = GreenatomyClient;
try {
const logs = await client.getLogs();
console.log(logs);
} catch (error) {
if (error instanceof GreenatomySdkError) {
console.error(error.message);
console.error(error.statusCode);
console.error(error.code);
} else {
throw error;
}
}Possible error.code values:
UNAUTHORIZEDRATE_LIMITEDHTTP_ERRORTIMEOUTNETWORK_ERROR
Notes
baseUrlis required.- Either
tokenorapiKeyis required. - API keys are project-scoped and generated from the dashboard.
- Raw API keys are shown only once during creation.
- Separate API keys can be used per environment for safer production isolation.
timeoutis optional and defaults to5000ms.- The client removes trailing slashes from
baseUrl. - The SDK currently supports logs, telemetry creation, stats, and summary endpoints.
- The SDK now also includes Express-style middleware for inbound request tracking.
tokenis ideal for authenticated dashboard/user access.apiKeyis ideal for project-level telemetry ingestion.
Recommended Onboarding
- Register in the hosted dashboard.
- Create a project.
- Generate an API key for that project.
- Save the raw API key when it is shown. It is only displayed once.
- Configure the SDK with that API key and your hosted
baseUrl.
