Skip to content

Commit 33425b2

Browse files
committed
Fixed structed logging names
1 parent fcfea29 commit 33425b2

File tree

15 files changed

+238
-239
lines changed

15 files changed

+238
-239
lines changed

src/Exceptionless.Core/Billing/StripeEventHandler.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,26 @@ private async Task InvoicePaymentSucceededAsync(Invoice inv)
156156
return;
157157
}
158158

159-
_logger.LogInformation("Stripe payment succeeded. Customer: {CustomerId} Org: {organization} Org Name: {OrganizationName}", inv.CustomerId, org.Id, org.Name);
159+
_logger.LogInformation("Stripe payment succeeded. Customer: {CustomerId} Org: {Organization} Org Name: {OrganizationName}", inv.CustomerId, org.Id, org.Name);
160160
}
161161

162-
private async Task InvoicePaymentFailedAsync(Invoice inv)
162+
private async Task InvoicePaymentFailedAsync(Invoice invoice)
163163
{
164-
var org = await _organizationRepository.GetByStripeCustomerIdAsync(inv.CustomerId);
164+
var org = await _organizationRepository.GetByStripeCustomerIdAsync(invoice.CustomerId);
165165
if (org is null)
166166
{
167-
_logger.LogError("Unknown customer id in payment failed notification: {CustomerId}", inv.CustomerId);
167+
_logger.LogError("Unknown customer id in payment failed notification: {CustomerId}", invoice.CustomerId);
168168
return;
169169
}
170170

171171
var user = await _userRepository.GetByIdAsync(org.BillingChangedByUserId);
172172
if (user is null)
173173
{
174-
_logger.LogError("Unable to find billing user: {0}", org.BillingChangedByUserId);
174+
_logger.LogError("Unable to find billing user: {UserId}", org.BillingChangedByUserId);
175175
return;
176176
}
177177

178-
_logger.LogInformation("Stripe payment failed. Customer: {CustomerId} Org: {organization} Org Name: {OrganizationName} Email: {EmailAddress}", inv.CustomerId, org.Id, org.Name, user.EmailAddress);
178+
_logger.LogInformation("Stripe payment failed. Customer: {CustomerId} Org: {Organization} Org Name: {OrganizationName} Email: {EmailAddress}", invoice.CustomerId, org.Id, org.Name, user.EmailAddress);
179179
await _mailer.SendOrganizationPaymentFailedAsync(user, org);
180180
}
181181
}

src/Exceptionless.Core/Jobs/DailySummaryJob.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Exceptionless.Core.Billing;
1+
using Exceptionless.Core.Billing;
22
using Exceptionless.Core.Configuration;
33
using Exceptionless.Core.Mail;
44
using Exceptionless.Core.Models;
@@ -70,28 +70,28 @@ protected override async Task<JobResult> RunInternalAsync(JobContext context)
7070
var utcStartTime = new DateTime(project.NextSummaryEndOfDayTicks - TimeSpan.TicksPerDay);
7171
if (utcStartTime < processSummariesNewerThan)
7272
{
73-
_logger.LogInformation("Skipping daily summary older than two days for project: {Name}", project.Name);
74-
projectsToBulkUpdate.Add(project);
75-
continue;
76-
}
73+
_logger.LogInformation("Skipping daily summary older than two days for project: {Name}", project.Name);
74+
projectsToBulkUpdate.Add(project);
75+
continue;
76+
}
7777

78-
var notification = new SummaryNotification
79-
{
80-
Id = project.Id,
81-
UtcStartTime = utcStartTime,
82-
UtcEndTime = new DateTime(project.NextSummaryEndOfDayTicks - TimeSpan.TicksPerSecond)
83-
};
78+
var notification = new SummaryNotification
79+
{
80+
Id = project.Id,
81+
UtcStartTime = utcStartTime,
82+
UtcEndTime = new DateTime(project.NextSummaryEndOfDayTicks - TimeSpan.TicksPerSecond)
83+
};
8484

85-
bool summarySent = await SendSummaryNotificationAsync(project, notification);
86-
if (summarySent)
87-
{
88-
await _projectRepository.IncrementNextSummaryEndOfDayTicksAsync(new[] { project });
85+
bool summarySent = await SendSummaryNotificationAsync(project, notification);
86+
if (summarySent)
87+
{
88+
await _projectRepository.IncrementNextSummaryEndOfDayTicksAsync(new[] { project });
8989

90-
// Sleep so we are not hammering the backend as we just generated a report.
91-
await SystemClock.SleepAsync(TimeSpan.FromSeconds(2.5));
92-
}
93-
else
94-
{
90+
// Sleep so we are not hammering the backend as we just generated a report.
91+
await SystemClock.SleepAsync(TimeSpan.FromSeconds(2.5));
92+
}
93+
else
94+
{
9595
projectsToBulkUpdate.Add(project);
9696
}
9797
}
@@ -140,7 +140,7 @@ private async Task<bool> SendSummaryNotificationAsync(Project project, SummaryNo
140140
var organization = await _organizationRepository.GetByIdAsync(project.OrganizationId, o => o.Cache());
141141
if (organization is null)
142142
{
143-
_logger.LogInformation("The organization {organization} for project {ProjectName} may have been deleted. No summaries will be sent", project.OrganizationId, project.Name);
143+
_logger.LogInformation("The organization {Organization} for project {ProjectName} may have been deleted. No summaries will be sent", project.OrganizationId, project.Name);
144144
return false;
145145
}
146146

src/Exceptionless.Core/Jobs/EventNotificationsJob.cs

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Exceptionless.Core.Configuration;
1+
using Exceptionless.Core.Configuration;
22
using Exceptionless.Core.Extensions;
33
using Exceptionless.Core.Mail;
44
using Exceptionless.Core.Models;
@@ -52,7 +52,7 @@ protected override async Task<JobResult> ProcessQueueEntryAsync(QueueEntryContex
5252

5353
bool shouldLog = ev.ProjectId != _appOptions.InternalProjectId;
5454
int sent = 0;
55-
if (shouldLog) _logger.LogTrace("Process notification: project={ProjectId} event={id} stack={stack}", ev.ProjectId, ev.Id, ev.StackId);
55+
if (shouldLog) _logger.LogTrace("Process notification: project={ProjectId} event={Id} stack={Stack}", ev.ProjectId, ev.Id, ev.StackId);
5656

5757
var project = await _projectRepository.GetByIdAsync(ev.ProjectId, o => o.Cache());
5858
if (project is null)
@@ -63,79 +63,79 @@ protected override async Task<JobResult> ProcessQueueEntryAsync(QueueEntryContex
6363
if (shouldLog) _logger.LogTrace("Loaded project: name={ProjectName}", project.Name);
6464

6565
// after the first 2 occurrences, don't send a notification for the same stack more then once every 30 minutes
66-
var lastTimeSentUtc = await _cache.GetAsync<DateTime>(String.Concat("notify:stack-throttle:", ev.StackId), DateTime.MinValue);
67-
if (wi is { TotalOccurrences: > 2, IsRegression: false } && lastTimeSentUtc != DateTime.MinValue && lastTimeSentUtc > SystemClock.UtcNow.AddMinutes(-30))
68-
{
69-
if (shouldLog) _logger.LogInformation("Skipping message because of stack throttling: last sent={LastSentUtc} occurrences={TotalOccurrences}", lastTimeSentUtc, wi.TotalOccurrences);
70-
return JobResult.Success;
71-
}
66+
var lastTimeSentUtc = await _cache.GetAsync<DateTime>(String.Concat("notify:stack-throttle:", ev.StackId), DateTime.MinValue);
67+
if (wi is { TotalOccurrences: > 2, IsRegression: false } && lastTimeSentUtc != DateTime.MinValue && lastTimeSentUtc > SystemClock.UtcNow.AddMinutes(-30))
68+
{
69+
if (shouldLog) _logger.LogInformation("Skipping message because of stack throttling: last sent={LastSentUtc} occurrences={TotalOccurrences}", lastTimeSentUtc, wi.TotalOccurrences);
70+
return JobResult.Success;
71+
}
72+
73+
if (context.CancellationToken.IsCancellationRequested)
74+
return JobResult.Cancelled;
7275

73-
if (context.CancellationToken.IsCancellationRequested)
74-
return JobResult.Cancelled;
76+
// don't send more than 10 notifications for a given project every 30 minutes
77+
var projectTimeWindow = TimeSpan.FromMinutes(30);
78+
string cacheKey = String.Concat("notify:project-throttle:", ev.ProjectId, "-", SystemClock.UtcNow.Floor(projectTimeWindow).Ticks);
79+
double notificationCount = await _cache.IncrementAsync(cacheKey, 1, projectTimeWindow);
80+
if (notificationCount > 10 && !wi.IsRegression)
81+
{
82+
if (shouldLog) _logger.LogInformation("Skipping message because of project throttling: count={NotificationCount}", notificationCount);
83+
return JobResult.Success;
84+
}
7585

76-
// don't send more than 10 notifications for a given project every 30 minutes
77-
var projectTimeWindow = TimeSpan.FromMinutes(30);
78-
string cacheKey = String.Concat("notify:project-throttle:", ev.ProjectId, "-", SystemClock.UtcNow.Floor(projectTimeWindow).Ticks);
79-
double notificationCount = await _cache.IncrementAsync(cacheKey, 1, projectTimeWindow);
80-
if (notificationCount > 10 && !wi.IsRegression)
86+
foreach (var kv in project.NotificationSettings)
87+
{
88+
var settings = kv.Value;
89+
if (shouldLog) _logger.LogTrace("Processing notification: {Key}", kv.Key);
90+
91+
bool isCritical = ev.IsCritical();
92+
bool shouldReportNewError = settings.ReportNewErrors && wi.IsNew && ev.IsError();
93+
bool shouldReportCriticalError = settings.ReportCriticalErrors && isCritical && ev.IsError();
94+
bool shouldReportRegression = settings.ReportEventRegressions && wi.IsRegression;
95+
bool shouldReportNewEvent = settings.ReportNewEvents && wi.IsNew;
96+
bool shouldReportCriticalEvent = settings.ReportCriticalEvents && isCritical;
97+
bool shouldReport = shouldReportNewError || shouldReportCriticalError || shouldReportRegression || shouldReportNewEvent || shouldReportCriticalEvent;
98+
99+
if (shouldLog)
81100
{
82-
if (shouldLog) _logger.LogInformation("Skipping message because of project throttling: count={NotificationCount}", notificationCount);
83-
return JobResult.Success;
101+
_logger.LogTrace("Settings: new error={ReportNewErrors} critical error={ReportCriticalErrors} regression={ReportEventRegressions} new={ReportNewEvents} critical={ReportCriticalEvents}", settings.ReportNewErrors, settings.ReportCriticalErrors, settings.ReportEventRegressions, settings.ReportNewEvents, settings.ReportCriticalEvents);
102+
_logger.LogTrace("Should process: new error={ShouldReportNewError} critical error={ShouldReportCriticalError} regression={ShouldReportRegression} new={ShouldReportNewEvent} critical={ShouldReportCriticalEvent}", shouldReportNewError, shouldReportCriticalError, shouldReportRegression, shouldReportNewEvent, shouldReportCriticalEvent);
84103
}
85-
86-
foreach (var kv in project.NotificationSettings)
104+
var request = ev.GetRequestInfo();
105+
// check for known bots if the user has elected to not report them
106+
if (shouldReport && !String.IsNullOrEmpty(request?.UserAgent))
87107
{
88-
var settings = kv.Value;
89-
if (shouldLog) _logger.LogTrace("Processing notification: {Key}", kv.Key);
90-
91-
bool isCritical = ev.IsCritical();
92-
bool shouldReportNewError = settings.ReportNewErrors && wi.IsNew && ev.IsError();
93-
bool shouldReportCriticalError = settings.ReportCriticalErrors && isCritical && ev.IsError();
94-
bool shouldReportRegression = settings.ReportEventRegressions && wi.IsRegression;
95-
bool shouldReportNewEvent = settings.ReportNewEvents && wi.IsNew;
96-
bool shouldReportCriticalEvent = settings.ReportCriticalEvents && isCritical;
97-
bool shouldReport = shouldReportNewError || shouldReportCriticalError || shouldReportRegression || shouldReportNewEvent || shouldReportCriticalEvent;
98-
99-
if (shouldLog)
100-
{
101-
_logger.LogTrace("Settings: new error={ReportNewErrors} critical error={ReportCriticalErrors} regression={ReportEventRegressions} new={ReportNewEvents} critical={ReportCriticalEvents}", settings.ReportNewErrors, settings.ReportCriticalErrors, settings.ReportEventRegressions, settings.ReportNewEvents, settings.ReportCriticalEvents);
102-
_logger.LogTrace("Should process: new error={ShouldReportNewError} critical error={ShouldReportCriticalError} regression={ShouldReportRegression} new={ShouldReportNewEvent} critical={ShouldReportCriticalEvent}", shouldReportNewError, shouldReportCriticalError, shouldReportRegression, shouldReportNewEvent, shouldReportCriticalEvent);
103-
}
104-
var request = ev.GetRequestInfo();
105-
// check for known bots if the user has elected to not report them
106-
if (shouldReport && !String.IsNullOrEmpty(request?.UserAgent))
107-
{
108-
var botPatterns = project.Configuration.Settings.GetStringCollection(SettingsDictionary.KnownKeys.UserAgentBotPatterns).ToList();
109-
110-
var info = await _parser.ParseAsync(request.UserAgent);
111-
if (info is not null && info.Device.IsSpider || request.UserAgent.AnyWildcardMatches(botPatterns))
112-
{
113-
shouldReport = false;
114-
if (shouldLog) _logger.LogInformation("Skipping because event is from a bot {UserAgent}", request.UserAgent);
115-
}
116-
}
108+
var botPatterns = project.Configuration.Settings.GetStringCollection(SettingsDictionary.KnownKeys.UserAgentBotPatterns).ToList();
117109

118-
if (!shouldReport)
119-
continue;
120-
121-
bool processed = kv.Key switch
110+
var info = await _parser.ParseAsync(request.UserAgent);
111+
if (info is not null && info.Device.IsSpider || request.UserAgent.AnyWildcardMatches(botPatterns))
122112
{
123-
Project.NotificationIntegrations.Slack => await _slackService
124-
.SendEventNoticeAsync(ev, project, wi.IsNew, wi.IsRegression)
125-
,
126-
_ => await SendEmailNotificationAsync(kv.Key, project, ev, wi, shouldLog)
127-
};
128-
129-
if (shouldLog) _logger.LogTrace("Finished processing notification: {Key}", kv.Key);
130-
if (processed)
131-
sent++;
113+
shouldReport = false;
114+
if (shouldLog) _logger.LogInformation("Skipping because event is from a bot {UserAgent}", request.UserAgent);
115+
}
132116
}
133117

134-
// if we sent any notifications, mark the last time a notification for this stack was sent.
135-
if (sent > 0)
118+
if (!shouldReport)
119+
continue;
120+
121+
bool processed = kv.Key switch
136122
{
123+
Project.NotificationIntegrations.Slack => await _slackService
124+
.SendEventNoticeAsync(ev, project, wi.IsNew, wi.IsRegression)
125+
,
126+
_ => await SendEmailNotificationAsync(kv.Key, project, ev, wi, shouldLog)
127+
};
128+
129+
if (shouldLog) _logger.LogTrace("Finished processing notification: {Key}", kv.Key);
130+
if (processed)
131+
sent++;
132+
}
133+
134+
// if we sent any notifications, mark the last time a notification for this stack was sent.
135+
if (sent > 0)
136+
{
137137
await _cache.SetAsync(String.Concat("notify:stack-throttle:", ev.StackId), SystemClock.UtcNow, SystemClock.UtcNow.AddMinutes(15));
138-
if (shouldLog) _logger.LogInformation("Notifications sent: event={id} stack={stack} count={SentCount}", ev.Id, ev.StackId, sent);
138+
if (shouldLog) _logger.LogInformation("Notifications sent: event={Id} stack={Stack} count={SentCount}", ev.Id, ev.StackId, sent);
139139
}
140140
}
141141
return JobResult.Success;
@@ -164,7 +164,7 @@ private async Task<bool> SendEmailNotificationAsync(string userId, Project proje
164164

165165
if (!user.OrganizationIds.Contains(project.OrganizationId))
166166
{
167-
if (shouldLog) _logger.LogError("Unauthorized user: project={ProjectId} user={UserId} organization={organization} event={id}", project.Id, userId, project.OrganizationId, ev.Id);
167+
if (shouldLog) _logger.LogError("Unauthorized user: project={ProjectId} user={UserId} organization={Organization} event={Id}", project.Id, userId, project.OrganizationId, ev.Id);
168168
return false;
169169
}
170170

0 commit comments

Comments
 (0)