Ejemplo n.º 1
0
 //--- Constructors ---
 public ConvertedLogEntry(OwnerMetaData owner, DateTimeOffset timestamp, ALambdaLogRecord record, string json)
 {
     Owner     = owner ?? throw new ArgumentNullException(nameof(owner));
     Timestamp = timestamp;
     Record    = record ?? throw new ArgumentNullException(nameof(record));
     Json      = json ?? throw new ArgumentNullException(nameof(json));
 }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 3
0
        private OwnerMetaData PopulateOwnerMetaData(RegistrationResourceProperties properties, OwnerMetaData?owner = null)
        {
            if (owner == null)
            {
                owner = new OwnerMetaData();
            }

            // support pre-0.8 notation where only 'Module' is present in the properties (no 'ModuleInfo')
            string?moduleInfo = null;
            string?module     = null;

            if (properties.ModuleInfo != null)
            {
                moduleInfo = properties.ModuleInfo;
                module     = properties.ModuleInfo.Split(':', 2)[0];
            }
            else if (properties.Module != null)
            {
                moduleInfo = properties.Module;
                module     = properties.Module?.Split(':', 2)[0];
            }

            // create/update owner record
            owner.ModuleId   = properties.ModuleId ?? owner.ModuleId;
            owner.Module     = module ?? owner.Module;
            owner.ModuleInfo = moduleInfo ?? owner.ModuleInfo;

            // function record
            owner.FunctionId           = properties.FunctionId ?? owner.FunctionId;
            owner.FunctionName         = properties.FunctionName ?? owner.FunctionName;
            owner.FunctionLogGroupName = properties.FunctionLogGroupName ?? owner.FunctionLogGroupName;
            owner.FunctionPlatform     = properties.FunctionPlatform ?? owner.FunctionPlatform;
            owner.FunctionFramework    = properties.FunctionFramework ?? owner.FunctionFramework;
            owner.FunctionLanguage     = properties.FunctionLanguage ?? owner.FunctionLanguage;
            owner.FunctionMaxMemory    = (properties.FunctionMaxMemory != 0)
                ? properties.FunctionMaxMemory
                : owner.FunctionMaxMemory;
            owner.FunctionMaxDuration = (TimeSpan.FromSeconds(properties.FunctionMaxDuration) != TimeSpan.Zero)
                ? TimeSpan.FromSeconds(properties.FunctionMaxDuration)
                : TimeSpan.FromSeconds(owner.FunctionMaxDuration.TotalSeconds);

            // app record
            owner.AppId        = properties.AppId ?? owner.AppId;
            owner.AppName      = properties.AppName ?? owner.AppName;
            owner.AppLogGroup  = properties.AppLogGroup ?? owner.AppLogGroup;
            owner.AppPlatform  = properties.AppPlatform ?? owner.AppPlatform;
            owner.AppFramework = properties.AppFramework ?? owner.AppFramework;
            owner.AppLanguage  = properties.AppLanguage ?? owner.AppLanguage;
            return(owner);
        }
 //--- Constructors ---
 public ProgressLogEntryAsync(ITestOutputHelper output)
 {
     _provider = new MockDependencyProvider(output);
     _logic    = new Logic(_provider);
     _owner    = new OwnerMetaData {
         Module               = "Test.Module:1.0@origin",
         ModuleId             = "ModuleId",
         FunctionId           = "ModuleName-FunctionName-NT5EUXTNTXXD",
         FunctionName         = "FunctionName",
         FunctionLogGroupName = "/aws/lambda/MyTestFunction",
         FunctionPlatform     = "Platform",
         FunctionFramework    = "Framework",
         FunctionLanguage     = "Language",
         FunctionMaxDuration  = TimeSpan.FromMilliseconds(10000),
         FunctionMaxMemory    = 128
     };
 }
Ejemplo n.º 5
0
 private OwnerMetaData PopulateOwnerMetaData(RegistrationResourceProperties properties, OwnerMetaData owner = null)
 {
     if (owner == null)
     {
         owner = new OwnerMetaData();
     }
     owner.ModuleId             = properties.ModuleId ?? owner.ModuleId;
     owner.Module               = properties.Module ?? owner.Module;
     owner.FunctionId           = properties.FunctionId ?? owner.FunctionId;
     owner.FunctionName         = properties.FunctionName ?? owner.FunctionName;
     owner.FunctionLogGroupName = properties.FunctionLogGroupName ?? owner.FunctionLogGroupName;
     owner.FunctionPlatform     = properties.FunctionPlatform ?? owner.FunctionPlatform;
     owner.FunctionFramework    = properties.FunctionFramework ?? owner.FunctionFramework;
     owner.FunctionLanguage     = properties.FunctionLanguage ?? owner.FunctionLanguage;
     owner.FunctionMaxMemory    = Math.Max(properties.FunctionMaxMemory, owner.FunctionMaxMemory);
     owner.FunctionMaxDuration  = TimeSpan.FromSeconds(Math.Max(properties.FunctionMaxDuration, owner.FunctionMaxDuration.TotalSeconds));
     return(owner);
 }
Ejemplo n.º 6
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 SendUsageReportAsync(OwnerMetaData owner, UsageReport report)
 {
     UsageReport.Should().BeNull();
     UsageReport = report;
     return(Task.CompletedTask);
 }
 public Task SendErrorReportAsync(OwnerMetaData owner, LambdaErrorReport report)
 {
     ErrorReport.Should().BeNull();
     ErrorReport = report;
     return(Task.CompletedTask);
 }
Ejemplo n.º 9
0
 public Task SendMetricsAsync(OwnerMetaData owner, DateTimeOffset timestamp, LambdaMetricsRecord record)
 {
     return(Task.CompletedTask);
 }
Ejemplo n.º 10
0
 public Task SendUsageReportAsync(OwnerMetaData owner, DateTimeOffset timestamp, LambdaUsageRecord report)
 {
     UsageReport.Should().BeNull();
     UsageReport = report;
     return(Task.CompletedTask);
 }
Ejemplo n.º 11
0
 async Task ILogicDependencyProvider.SendUsageReportAsync(OwnerMetaData owner, UsageReport report)
 => await _snsClient.PublishAsync(_usageTopic, SerializeJson(report));
Ejemplo n.º 12
0
 Task ILogicDependencyProvider.SendErrorReportAsync(OwnerMetaData owner, LambdaErrorReport report)
 => PublishErrorReportAsync(owner, report);
Ejemplo n.º 13
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");
            }
        }