public async Task Process(IncomingStepContext context, Func <Task> next)
        {
            var messageContext = MessageContext.Current;

            var messagesTypeName = messageContext.Message.Body.GetType().Name;

            const string transactionName = nameof(transactionName);

            NewRelic.SetTransactionName(transactionName, $"{messagesTypeName}");

            foreach (var messageContextHeader in messageContext.Headers)
            {
                NewRelic.AddCustomParameter(messageContextHeader.Key, messageContextHeader.Value);
            }

            Stopwatch stopwatch = Stopwatch.StartNew();

            try
            {
                await next();
            }
            catch (Exception error)
            {
                NewRelic.NoticeError(error, messageContext.Headers);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                NewRelic.RecordResponseTimeMetric($"{messagesTypeName}",
                                                  stopwatch.ElapsedMilliseconds);
            }
        }
    private void InitializePlugin()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);

        try {
            if (agentInstance == null)
            {
                                #if UNITY_IPHONE
                UnityEngine.Debug.Log("Initializing New Relic iOS agent.");
                agentInstance = new NewRelicIos(this);
                                #elif UNITY_ANDROID
                UnityEngine.Debug.Log("Initializing New Relic Android agent.");
                agentInstance = new NewRelicAndroid(this);
                                #endif  // UNITY_ANDROID
            }
        } catch (Exception e) {
            UnityEngine.Debug.LogException(e);
        }
    }
Example #3
0
        private static void LogToNewRelic(ErrorDetails details)
        {
            Trace.TraceError(string.Format("Error: {0}", details.Error.Message));

            var errorData = new Dictionary <string, string>(details.Args)
            {
                { "ActionTaken", details.ActionTaken.ToString() },
                { "OccurrenceTimeStamp", details.OccurrenceTimeStamp.ToString("O") },
                { "Error", details.ExtractErrorMessage() },
                { "StackTrace", details.ExtractStackTrace() }
            };

            Trace.TraceInformation("Logging to NewRelic - Error: {0}", details.Error);

            // Log error to New Relic using API agent
            NewRelic.NoticeError(details.Error, errorData);
        }