cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Not a customer? Start a free trial

Click the Start a free trial link to start a 15-day SaaS trial of our product and join our community as a trial user. If you are an existing customer do not start a free trial.

AppDynamics customers and established members should click the sign in button to authenticate.

End User Monitoring (EUM)

Dynamically set App Key for SPA

taylor_garey
New Poster

Dynamically set App Key for SPA

My company builds an Atomic SPA JavaScript application, compiled once, deployed for any Environment (DEV, QA, PROD). Because the same piece of code is used for DEV, QA and PROD we cannot have a Static AppKey. We have multiple AppDynamics accounts, one for each environment. 

 

So, how do we configure the SPA JavaScript application at runtime? Simple we call a REST service at a "local" url of : /spa/config and it returns the appropiate configuration for that environment. 

 

Note: We don't want to compile a JS app for every environment, we like having one build that can be deployed anywhere. 

 

So that doesn't work with AppDynamics because you must put the AppKey in the header of your index file. 

 

What I would like to happen: 

 

1. add AppDynamic snippit to index.html header. do all the initial loading and setup but don't transfer any data back to AppDynamic central, just store it. 

2. SPA finished loading and calls /spa/config REST service to pull config, including EUM_APP_KEY. 

2. Once EUM_APP_KEY is set, start transmitting data, both stored and live. 

 

Is this currently possible? If not, is it possible to update current scripts? 

 

Tags (1)
By replying you agree to the Terms and Conditions of the AppDynamics Community.
Dynamically set App Key for SPA
3 REPLIES 3
Deepanshu.Grover
AppDynamics Team

Re: Dynamically set App Key for SPA

Hi Taylor,

 

Currently we don't support modifying our JS agent files as it can lead to unexpected errrors on the page and can even effect the monitoring as well.

 

From your use case I can understand that for all your three environments, i.e. Dev, QA and Prod there is a need to get JS agents with different app keys, so instead of doing that at runtime, can you just use the same agent code with different app key as described in our manual injection piece and then see if that works?

https://docs.appdynamics.com/display/PRO44/Manual+Injection+of+the+JavaScript+Agent

 

You can even customize each JS agent for different environment as mentioned below:

https://docs.appdynamics.com/display/PRO44/Customize+the+JavaScript+Agent

 

Let us know is this helps.

 

Thanks,

Deepanshu

taylor_garey
New Poster

Re: Dynamically set App Key for SPA

I was more concerned with the Lifecycle and when the JS agent was initialized.

In general, it's recommended to put it in the index.html file's header so it's loaded first. If we dynamically set the app_key it will need to be initialized later in the lifecycle.

1. Index.html
2. JS Loaded
3. SPA calls REST config service to pull ENV parameters
4. Initialize AppDynamic JS Agent with app_key

As I understand we will lose some loading metrics if we don't initialize the Agent in the index.html header.

We can try it and see what happens.
Deepanshu.Grover
AppDynamics Team

Re: Dynamically set App Key for SPA

Hi Taylor,

 

Yes, your understanding is correct and you might miss few metrics if JS agent is not loaded/initialized early on the application page.

 

Let us know if you have any further queries around this.

 

Thanks,

Deepanshu