Exemplo n.º 1
0
 private Task PublishErrorReportAsync(OwnerMetaData owner, LambdaErrorReport report)
 {
     try {
         return(Task.WhenAll(new[] {
             PublishErrorReportToRollbarAsync(owner, report),
             _snsClient.PublishAsync(_errorTopic, SerializeJson(report))
         }));
     } catch {
         // capture error report in log; it's the next best thing we can do
         Provider.Log(SerializeJson(report) + "\n");
         return(Task.CompletedTask);
     }
 }
Exemplo n.º 2
0
        private async Task PublishErrorReportToRollbarAsync(OwnerMetaData owner, LambdaErrorReport report)
        {
            if (owner.RollbarAccessToken == null)
            {
                return;
            }

            // convert error report into rollbar data structure
            var rollbar = new Rollbar {
                AccessToken = owner.RollbarAccessToken,
                Data        = new Data {
                    Environment = string.IsNullOrEmpty(Info.DeploymentTier)
                        ? "<DEFAULT>"
                        : Info.DeploymentTier,
                    Level = report.Level?.ToLowerInvariant() switch {
                        "error" => "error",
                        "warning" => "warning",
                        "fatal" => "critical",
                        _ => "error"
                    },
 public Task SendErrorReportAsync(OwnerMetaData owner, LambdaErrorReport report)
 {
     ErrorReport.Should().BeNull();
     ErrorReport = report;
     return(Task.CompletedTask);
 }
Exemplo n.º 4
0
 Task ILogicDependencyProvider.SendErrorReportAsync(OwnerMetaData owner, LambdaErrorReport report)
 => PublishErrorReportAsync(owner, report);
Exemplo n.º 5
0
        private async Task PublishErrorReportToRollbarAsync(OwnerMetaData owner, LambdaErrorReport report)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }
            if (owner.RollbarAccessToken == null)
            {
                return;
            }

            // convert error report into rollbar data structure
            var rollbar = new Rollbar {
                AccessToken = owner.RollbarAccessToken,
                Data        = new Data {
                    Environment = report.ModuleId,
                    Level       = report.Level?.ToLowerInvariant() ?? "error",
                    Timestamp   = report.Timestamp,
                    CodeVersion = report.GitSha,
                    Platform    = report.Platform,
                    Language    = report.Language,
                    Framework   = report.Framework,
                    Fingerprint = report.Fingerprint,
                    Title       = $"{report.FunctionName}: {report.Message}",
                    Custom      = new {
                        report.Message,
                        report.Module,
                        report.ModuleId,
                        report.FunctionId,
                        report.FunctionName,
                        report.GitBranch,
                        report.RequestId
                    },
                    Body = new DataBody {
                        TraceChain = report.Traces?.Select(trace => new Trace {
                            Exception = new ExceptionClass {
                                Class       = trace.Exception?.Type,
                                Message     = trace.Exception?.Message,
                                Description = trace.Exception?.StackTrace
                            },
                            Frames = trace.Frames?.Select(frame => new Frame {
                                Filename = frame.FileName,
                                Lineno   = frame.LineNumber.GetValueOrDefault(),
                                Method   = frame.MethodName
                            }).ToArray()
                        }).ToArray()
                    }
                }
            };

            // in case there are no captured traces, inject a simple error message
            if (rollbar.Data.Body.TraceChain?.Any() != true)
            {
                rollbar.Data.Body.TraceChain = null;
                rollbar.Data.Body            = new DataBody {
                    Message = new Message {
                        Body = report.Raw
                    }
                };
            }

            // send payload to rollbar
            try {
                var response = _rollbarClient.SendRollbarPayload(rollbar);
                LogInfo($"Rollbar.SendRollbarPayload() succeeded: {response}");
            } catch (WebException e) {
                if (e.Response == null)
                {
                    LogWarn($"Rollbar request failed (status: {e.Status}, message: {e.Message})");
                }
                else
                {
                    using (var stream = e.Response.GetResponseStream()) {
                        if (stream == null)
                        {
                            LogWarn($"Rollbar.SendRollbarPayload() failed: {e.Status}");
                        }
                        using (var reader = new StreamReader(stream)) {
                            LogWarn($"Rollbar.SendRollbarPayload() failed: {reader.ReadToEnd()}");
                        }
                    }
                }
            } catch (Exception e) {
                LogErrorAsWarning(e, "Rollbar.SendRollbarPayload() failed");
            }
        }