public RequestTracer(
            string applicationKey,
            string applicationName,
            string eSpaceKey,
            string eSpaceName,
            string tenantKey,
            string tenantName,
            string environmentKey,
            string environmentName,
            string frontEndName,
            bool forceEnableMonitoring)
        {
            this.RequestKey      = Guid.NewGuid().ToString();
            this.ModuleKey       = eSpaceKey;
            this.ModuleName      = eSpaceName;
            this.ApplicationKey  = applicationKey;
            this.ApplicationName = applicationName;

            this.CommonRequestEventDetails = new RequestEventDetails();
            this.CommonRequestEventDetails.Add(RequestEventDetails.TENANT_KEY, tenantKey);
            this.CommonRequestEventDetails.Add(RequestEventDetails.TENANT_NAME, tenantName);
            this.CommonRequestEventDetails.Add(RequestEventDetails.ENVIRONMENT_KEY, environmentKey);
            this.CommonRequestEventDetails.Add(RequestEventDetails.ENVIRONMENT_NAME, environmentName);
            this.CommonRequestEventDetails.Add(RequestEventDetails.FRONTEND_NAME, frontEndName == null ? "" : frontEndName);

            // check below for WHY this exists.
            requestEventsGenerator = new RequestEventsGenerator(this);
            if (forceEnableMonitoring)
            {
                requestEventsGenerator.GetPerformanceMonitorStatusFrom(() => true);
            }
        }
        public void RegisterEndRequest(DateTime endRequestInstant)
        {
            try
            {
                RequestEndInstant = endRequestInstant;

                if (MainEventType == RequestTracerEventType.Undefined)
                {
                    //no main event type declared means we do not want to create the event
                    return;
                }

                MainRequestEventDetails = new RequestEventDetails(CommonRequestEventDetails);

                MainRequestEventDetails[RequestEventDetails.END_POINT_NAME] = EntryEndpointName;
                MainRequestEventDetails[RequestEventDetails.END_POINT_KEY]  = EntryEndpointKey;
                MainRequestEventDetails[RequestEventDetails.ACTION_NAME]    = EntryActionName;
                MainRequestEventDetails[RequestEventDetails.ACTION_KEY]     = EntryActionKey;

                TotalServerRequestDuration = Convert.ToInt32((RequestEndInstant - RequestStartInstant).TotalMilliseconds);
                MainRequestEventDetails[RequestEventDetails.DURATION] = TotalServerRequestDuration;

                MainRequestEventDetails[RequestEventDetails.TOTAL_QUERIES_TIME]                = TotalQueriesTime;
                MainRequestEventDetails[RequestEventDetails.TOTAL_QUERIES_CALLS]               = TotalQueriesCalls;
                MainRequestEventDetails[RequestEventDetails.TOTAL_EXTENSIONS_TIME]             = TotalExtensionsTime;
                MainRequestEventDetails[RequestEventDetails.TOTAL_EXTENSIONS_CALLS]            = TotalExtensionsCalls;
                MainRequestEventDetails[RequestEventDetails.TOTAL_CONSUMED_INTEGRATIONS_TIME]  = TotalConsumedIntegrationsTime;
                MainRequestEventDetails[RequestEventDetails.TOTAL_CONSUMED_INTEGRATIONS_CALLS] = TotalConsumedIntegrationsCalls;

                MainRequestEventDetails.Add(RequestEventDetails.CLIENT_IP, ClientIP);

                if (errorCount > 0)
                {
                    MainRequestEventDetails.Add(RequestEventDetails.ERROR_COUNT, errorCount);
                }

                if (MainEventType == RequestTracerEventType.WebScreenServerExecuted)
                {
                    MainRequestEventDetails.Add(RequestEventDetails.SESSION_ACQUISITION_TIME, SessionAcquisitionTime);
                    MainRequestEventDetails.Add(RequestEventDetails.SESSION_SIZE, SessionSize);
                    MainRequestEventDetails.Add(RequestEventDetails.VIEWSTATE_SIZE, ViewStateSize);
                    if (UserId != 0)   // UserId 0 is an anonymous user
                    {
                        MainRequestEventDetails.Add(RequestEventDetails.USERID, UserId);
                    }
                }
                if (ExposedIntegrationType != null && ExposedIntegrationType != "")
                {
                    MainRequestEventDetails.Add(RequestEventDetails.INTEGRATION_TYPE, ExposedIntegrationType);
                }
            }
            catch (Exception e)
            {
                HandleRequestTracerException(e);
            }
        }
 public RequestEventDetails(RequestEventDetails details) : base(details)
 {
 }
        public void CreateEvent(RequestTracerEventType eventType, DateTime startInstant, RequestEventDetails details)
        {
            try
            {
                if (!IsPerformanceMonitorEnabled() ||
                    Convert.ToInt32(details[RequestEventDetails.DURATION]) < EventCreationThreshold(eventType) ||
                    (tracer.MainEventType == RequestTracerEventType.ExposedIntegrationExecuted && !IsExposedIntegrationExecutedEnabled()))
                {
                    return;
                }

                RequestEvent newEvent = new RequestEvent(
                    startInstant,
                    tracer.RequestKey,
                    eventType.ToString(),
                    tracer.ModuleKey,
                    tracer.ModuleName,
                    tracer.ApplicationKey,
                    tracer.ApplicationName,
                    details.ToString()
                    );
                _requestEvents.Add(newEvent);
            }
            catch (Exception e)
            {
                HandleException(e);
            }
        }
 public ESpaceExternalCallDetails(string objectKey, string objectName, string eSpaceKey, string eSpaceName, RequestEventDetails details) : base(details)
 {
     Add(OBJECT_NAME, objectName);
     Add(OBJECT_KEY, objectKey);
     Add(OBJECT_ESPACE_NAME, eSpaceName);
     Add(OBJECT_ESPACE_KEY, eSpaceKey);
     Add(NUMBER_OF_EXECUTIONS, 0);
     Add(RequestEventDetails.DURATION, 0);
 }