cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use the App Environment SDK in functions?

thomas_c
Dynatrace Guide
Dynatrace Guide

Hi Team,

I need to retrieve and use the environment's URL in a Dashboard/Notebook function.

The docs seems lacking the info on which SDK to import. I tried the following but get an error:

thomas_c_0-1682419101752.png

Could you please guide me on using that SDK?

Thanks,

Thomas

6 REPLIES 6

stefan_eggersto
Dynatrace Mentor
Dynatrace Mentor

Hi Thomas,

@dynatrace-sdk/app-environment can only be used in apps and is not available for ad-hoc functions.

As an alternative, you can use globalThis.environmentUrl to access the environment URL.

Thanks Stefan! That works great in ad-hoc functions too.

Just to close the loop, is there a way to use such globalThis properties in a dashboard's markdown tile? Just like we can do via a dashboard variable.

Can you kindly let me know how extract the incoming header and the body as I need to process those to do other stuff in the app function?  can I use globalThis.? where is the documentation can be found of globalThis.x Thanks in advance for your support

 

Dear Stefan, Can you kindly let me know how extract the incoming header and the body as I need to process those to do other stuff in the app function?  can I use globalThis.? where is the documentation can be found of globalThis.x Thanks in advance for your support

I also see that 

globalThis.environmentUrl  is marked as depricated and they advise to use this code, hope this is helpful to everyone:  
import { getEnvironmentId } from '@dynatrace-sdk/app-environment';

export default async function (payload: unknown = undefined) {
  // Get the current environment ID
  const environmentId = getEnvironmentId();
  return environmentId;
}

import { getEnvironmentUrl } from '@dynatrace-sdk/app-environment';

export default async function (payload: unknown = undefined) {
  // Get the current environment URL
  const environmentUrl = getEnvironmentUrl();
  return environmentUrl;
}
 
If the URL is required use the above

Featured Posts