App Environment
Obtain the basic information about the app and the environment in which it's running.
npm install @dynatrace-sdk/app-environment
Functions
getAppId
Retrieves the app id.
Returns
Return type | Description |
---|---|
string | app id defined in app config. Note: If the Dynatrace JavaScript runtime isn't available, 'dt.missing.app.id' will be returned and a warning will be logged to the console. |
Code example
import { getAppId } from '@dynatrace-sdk/platform/app-environment';
// Get the current app's ID
const appId = getAppId();
getAppName
Retrieves the app name.
Returns
Return type | Description |
---|---|
string | app name defined in app config. Note: If the Dynatrace JavaScript runtime isn't available, 'dt.missing.app.name' will be returned and a warning will be logged to the console. |
Code example
import { getAppName } from '@dynatrace-sdk/platform/app-environment';
// Get the current app's name
const appName = getAppName();
getAppVersion
Retrieves the app version.
Returns
Return type | Description |
---|---|
string | app version defined in app manifest. Note: If the Dynatrace JavaScript runtime isn't available, 'dt.missing.app.version' will be returned and a warning will be logged to the console. |
Code example
import { getAppVersion } from '@dynatrace-sdk/platform/app-environment';
// Get the current app's version
const appVersion = getAppVersion();
getCurrentUserDetails
Retrieves the information about currently logged user
Returns
Return type | Description |
---|---|
UserDetails | id, name and email of currently logged user. Note: If the Dynatrace JavaScript runtime isn't available, a default UserDetails placeholder object with values ('dt.missing.user.id', 'dt.missing.user.name', 'dt.missing.user.email') will be returned and a warning will be logged to the console. |
Code example
import { getCurrentUserDetails } from '@dynatrace-sdk/platform/app-environment';
// Get the details of the currently logged-in user
const userDetails = getCurrentUserDetails();
// Use destructuring to extract specific properties
const { id, name, email } = getCurrentUserDetails();
getEnvironmentId
Retrieves the environment id.
Returns
Return type | Description |
---|---|
string | environment id on which app is run. Note: If the Dynatrace JavaScript runtime isn't available, 'dt.missing.environment.id' will be returned and a warning will be logged to the console. |
Code example
import { getEnvironmentId } from '@dynatrace-sdk/platform/app-environment';
// Get the current environment ID
const environmentId = getEnvironmentId();
getEnvironmentUrl
Retrieves the environment url.
Returns
Return type | Description |
---|---|
string | environment url on which app is run. Note: If the Dynatrace JavaScript runtime isn't available, 'https://dynatrace.com/' will be returned and a warning will be logged to the console. |
Code example
import { getEnvironmentUrl } from '@dynatrace-sdk/platform/app-environment';
// Get the current environment URL
const environmentUrl = getEnvironmentUrl();
Types
UserDetails
Information about currently logged user
Properties
Name | Type |
---|---|
email*required | string |
id*required | string |
name*required | string |