Skip to main content

App functions

App functions represent an app's backend. They're built, bundled, and deployed together with your Dynatrace App. The Dynatrace App Toolkit makes developing and deploying app functions as easy as possible.

Every TypeScript file in your project's /api directory is automatically deployed as an app function and therefore exposed as an API endpoint.

Currently, you can deploy functions built with JavaScript/TypeScript, which run within the Dynatrace JavaScript runtime.

Function interface

The Dynatrace JavaScript runtime expects a single default function exported from your function files. This function can contain a single payload parameter, which is the function body of the incoming request.

Every input to your function needs to be passed via the function body. You can consume it via the payload parameter in your function.

Here's an example:

export default (payload) => {
return 'Hello World';
};

Call your app functions

You can call your app functions from various places, including its user interface, ad-hoc functions in Notebooks and Workflows, or from outside the platform via the public API.

The following sections show you how you can do this.

Call app functions from your app

The @dynatrace-sdk/app-utils package makes it easy to call your functions from within your app code. Calling the call function of the functions namespace returns the response of the called app function.

You have to pass the name of the function and an optional payload:

import { functions } from '@dynatrace-sdk/app-utils';

const response = await functions.call('hello-world', { username: 'john', fruits: ['apple', 'orange'] });

Optionally, you can also use the native Javascript fetch function to call your function:

const res = await fetch('/api/hello-world', {
method: 'POST',
body: JSON.stringify(input),
}).then((response) => response.text());
tip

You can only call app functions from the app that they belong to. You can't call app functions that are part of another app.

Call app functions from Notebooks or Workflows

With the @dynatrace-sdk/adhoc-utils package you can call app functions exposed by an app from Notebooks or Workflows.

The call function exposed by the functions namespace expects both the appId and the functionName as well as an optional data parameter to pass in the function payload:

import { functions } from '@dynatrace-sdk/adhoc-utils';

const response = await functions.call('my.app.id', 'hello-world', { username: 'john', fruits: ['apple', 'orange'] });

Call app functions from outside the platform

App functions are exposed via a public API endpoint and can be called from anywhere outside the platform. When calling your function from outside the platform you need to consider the following points:

  • You need to call the absolute API URL address
    • https://abc12345.apps.dynatrace.com/platform/app-engine/app-functions/v1/apps/<Your-App-ID>/api/<Your-Function-Name>
  • You need to take care of authentication by yourself. App function requests are authenticated via oAuth. Read Access platform APIs from outside for more details.

After obtaining a Bearer token from the single sign-on (SSO) token endpoint, a curl request to your app function could look like this:

curl --request GET 'https://abc12345.apps.dynatrace.com/platform/app-engine/app-functions/v1/apps/my.app.id/api/hello-world' \
--header 'Authorization: Bearer {your-bearer-token}'

Use cases

The most important use cases for app functions are:

  • Accessing third party APIs to be used within your app
  • Heavy data processing that ideally shouldn't take place in the browser
  • Data wrangling to make the data easily consumable within the app's web UI
  • Requests that need credentials for authentication that shouldn't be exposed in the app's UI code

Runtime limitations

Currently, the following restrictions apply to functions:

  • Function execution times out after 60 seconds.
  • Functions can't call functions of other apps.
  • Functions are deployed in an environment with 256 MB RAM.
  • Functions can't send binary responses.
  • Function inputs/outputs can't be larger than 6 MB, respectively.
  • There is a limit on concurrent requests you can make to app functions. You'll get back the HTTP 429 Too Many Requests response status code when you reach the limit.
  • Calls to external hosts need to be explicitly allowed (see guide).

Still have questions?
Find answers in the Dynatrace Community