Currently, the RUM web client retrieves credentials for all sessions even if the sessionSampleRate is < 1. In order to reduce the number of unnecessary requests to Cognito and STS, we will only set/retrieve credentials for sessions that are sampled.
To do this, we will call getSession() to get the session and verify if it's recorded or not. Currently, a new session is created when we get a session and it doesn't exist. This PR introduces no change to this default behavior as the new boolean variable createIfNull, that is checked before creating a new session, is set to true by default. We will only set it to false when retrieving the session information to determine whether the web client should retrieve credentials.
I also considered checking if the eventCache had events instead of checking if the session was recorded. However, this approach was rejected as these two scenarios could diverge. We will only check if the session is recorded to keep a single source of truth.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Currently, the RUM web client retrieves credentials for all sessions even if the
sessionSampleRate
is < 1. In order to reduce the number of unnecessary requests to Cognito and STS, we will only set/retrieve credentials for sessions that are sampled.To do this, we will call
getSession()
to get the session and verify if it's recorded or not. Currently, a new session is created when we get a session and it doesn't exist. This PR introduces no change to this default behavior as the new boolean variablecreateIfNull
, that is checked before creating a new session, is set totrue
by default. We will only set it tofalse
when retrieving the session information to determine whether the web client should retrieve credentials.I also considered checking if the eventCache had events instead of checking if the session was recorded. However, this approach was rejected as these two scenarios could diverge. We will only check if the session is recorded to keep a single source of truth.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.