App Functions
Serverless TypeScript functions that run on AppEngine. Every TypeScript file in the /api directory is automatically deployed as an API endpoint.
Creating a Function
// api/health-check.ts
export default async function (payload: { url: string }) {
const start = Date.now();
const response = await fetch(payload.url);
return { status: response.status, latency: Date.now() - start, ok: response.ok };
}
Calling from UI
Two ways โ imperative or hook:
// Option 1: Imperative (from our DOOM app)
import { functions } from "@dynatrace-sdk/app-utils";
const result = await functions.call("health-check", { url: "https://api.example.com" });
// Option 2: Hook (from official Dynatrace tutorial)
import { useAppFunction } from "@dynatrace-sdk/react-hooks";
const result = useAppFunction({ name: "health-check", data: { url: "https://api.example.com" } });
// result.data, result.isLoading, result.error
Use Case Use App Function?
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ
DQL query No โ use useDqlQuery directly
External API call Yes โ credentials stay server-side
Heavy data processing Yes โ don't block the browser
Data that needs secrets Yes โ secrets never reach the UI
๐ก App Functions run server-side on AppEngine. Logs go to Grail (queryable with DQL). HTTP errors return specific codes: 540 = JavaScript error, 541 = timeout/memory exceeded.
๐ Try it: Create an app function: add a .ts file in the api/ directory โ export a default async function โ call it from your UI with useAppFunction. App functions run server-side with their own permissions โ perfect for data processing.