Skip to content

Commit fadd728

Browse files
committed
fix: address PR review feedback on event workers and tracker duplication
- SqsStickerPrintedWorker: unwrap EventBridge envelope before deserializing (was deserializing message.Body directly as StickerPrintedEventV1, missing the CloudWatchEvent<JsonElement> outer envelope; mirrored StickerPrintedSqsHandler) - ServiceBusStickerPrintedWorker: add return after DeadLetterMessageAsync calls so CompleteMessageAsync is never called on an already-settled message - PrintService.Client: remove duplicate DatadogTransactionTracker; reference Core implementation via IDatadogTransactionTracker instead
1 parent a237e71 commit fadd728

7 files changed

Lines changed: 36 additions & 112 deletions

File tree

print-service/src/Stickerlandia.PrintService.Client/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Stickerlandia.PrintService.Client.Configuration;
1616
using Stickerlandia.PrintService.Client.Services;
1717
using Stickerlandia.PrintService.Client.Telemetry;
18+
using CoreObs = Stickerlandia.PrintService.Core.Observability;
1819

1920
var builder = WebApplication.CreateBuilder(args);
2021
builder.Configuration.AddEnvironmentVariables();
@@ -77,7 +78,7 @@
7778
builder.Services.AddRazorComponents()
7879
.AddInteractiveServerComponents();
7980

80-
builder.Services.AddSingleton<DatadogTransactionTracker>();
81+
builder.Services.AddSingleton<CoreObs.IDatadogTransactionTracker, CoreObs.DatadogTransactionTracker>();
8182
// Add configuration service (singleton - shared across app)
8283
builder.Services.AddSingleton<IConfigurationService, ConfigurationService>();
8384

print-service/src/Stickerlandia.PrintService.Client/Services/PrintJobPollingService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Stickerlandia.PrintService.Client.Configuration;
1212
using Stickerlandia.PrintService.Client.Models;
1313
using Stickerlandia.PrintService.Client.Telemetry;
14+
using CoreObs = Stickerlandia.PrintService.Core.Observability;
1415

1516
namespace Stickerlandia.PrintService.Client.Services;
1617

@@ -25,15 +26,15 @@ internal sealed class PrintJobPollingService : BackgroundService
2526
private readonly ClientStatusService _statusService;
2627
private readonly PrintClientInstrumentation _instrumentation;
2728
private readonly ILogger<PrintJobPollingService> _logger;
28-
private readonly DatadogTransactionTracker _transactionTracker;
29+
private readonly CoreObs.IDatadogTransactionTracker _transactionTracker;
2930

3031
public PrintJobPollingService(
3132
IPrintServiceApiClient apiClient,
3233
ILocalStorageService localStorage,
3334
IConfigurationService configService,
3435
ClientStatusService statusService,
3536
PrintClientInstrumentation instrumentation,
36-
ILogger<PrintJobPollingService> logger, DatadogTransactionTracker transactionTracker)
37+
ILogger<PrintJobPollingService> logger, CoreObs.IDatadogTransactionTracker transactionTracker)
3738
{
3839
_apiClient = apiClient;
3940
_localStorage = localStorage;

print-service/src/Stickerlandia.PrintService.Client/Stickerlandia.PrintService.Client.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<BlazorDisableThrowNavigationException>true</BlazorDisableThrowNavigationException>
88
</PropertyGroup>
99

10+
<ItemGroup>
11+
<ProjectReference Include="..\Stickerlandia.PrintService.Core\Stickerlandia.PrintService.Core.csproj" />
12+
</ItemGroup>
13+
1014
<ItemGroup>
1115
<InternalsVisibleTo Include="Stickerlandia.PrintService.Client.Tests" />
1216
<!-- Required for FakeItEasy to mock internal types -->

print-service/src/Stickerlandia.PrintService.Client/Telemetry/DatadogTransactionTracker.cs

Lines changed: 0 additions & 103 deletions
This file was deleted.

user-management/src/Stickerlandia.UserManagement.AWS/SqsStickerPrintedWorker.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
// Copyright 2025 Datadog, Inc.
1010

1111
using System.Text.Json;
12+
using Amazon.Lambda.CloudWatchEvents;
1213
using Amazon.SQS;
1314
using Amazon.SQS.Model;
15+
using CloudNative.CloudEvents;
16+
using CloudNative.CloudEvents.SystemTextJson;
1417
using Datadog.Trace;
1518
using Microsoft.Extensions.DependencyInjection;
1619
using Microsoft.Extensions.Logging;
@@ -19,7 +22,6 @@
1922
using Stickerlandia.UserManagement.Core;
2023
using Stickerlandia.UserManagement.Core.Observability;
2124
using Stickerlandia.UserManagement.Core.StickerPrintedEvent;
22-
using Stickerlandia.UserManagement.Core.StickerPrintedEvent;
2325

2426
namespace Stickerlandia.UserManagement.AWS;
2527

@@ -30,6 +32,7 @@ public class SqsStickerPrintedWorker : IMessagingWorker
3032
private readonly ILogger<SqsStickerPrintedWorker> _logger;
3133
private readonly AmazonSQSClient _sqsClient;
3234
private readonly IOptions<AwsConfiguration> _awsConfiguration;
35+
private readonly JsonSerializerOptions _jsonSerializerOptions = new() { PropertyNameCaseInsensitive = true };
3336

3437
public SqsStickerPrintedWorker(ILogger<SqsStickerPrintedWorker> logger,
3538
AmazonSQSClient sqsClient, IServiceScopeFactory serviceScopeFactory,
@@ -62,7 +65,20 @@ private async Task ProcessMessageAsync(Message message)
6265
using var scope = _serviceScopeFactory.CreateScope();
6366
var handler = scope.ServiceProvider.GetRequiredService<StickerPrintedHandler>();
6467

65-
var evtData = JsonSerializer.Deserialize<StickerPrintedEventV1>(message.Body);
68+
var envelope = JsonSerializer.Deserialize<CloudWatchEvent<JsonElement>>(message.Body, _jsonSerializerOptions);
69+
70+
if (envelope == null)
71+
{
72+
await _sqsClient.SendMessageAsync(_awsConfiguration.Value.StickerPrintedDLQUrl, message.Body);
73+
await _sqsClient.DeleteMessageAsync(_awsConfiguration.Value.StickerPrintedQueueUrl, message.ReceiptHandle);
74+
return;
75+
}
76+
77+
var detailBytes = JsonSerializer.SerializeToUtf8Bytes(envelope.Detail, _jsonSerializerOptions);
78+
var formatter = new JsonEventFormatter<StickerPrintedEventV1>();
79+
var cloudEvent = await formatter.DecodeStructuredModeMessageAsync(
80+
new MemoryStream(detailBytes), null, new List<CloudEventAttribute>());
81+
var evtData = (StickerPrintedEventV1?)cloudEvent.Data;
6682

6783
if (evtData == null)
6884
{
@@ -71,10 +87,9 @@ private async Task ProcessMessageAsync(Message message)
7187
return;
7288
}
7389

74-
// Process your message here
7590
try
7691
{
77-
await handler.Handle(evtData!);
92+
await handler.Handle(evtData);
7893
}
7994
catch (InvalidUserException ex)
8095
{

user-management/src/Stickerlandia.UserManagement.AWS/Stickerlandia.UserManagement.AWS.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
<ItemGroup>
1010
<PackageReference Include="Amazon.Lambda.Annotations" Version="1.8.0" />
11+
<PackageReference Include="Amazon.Lambda.CloudWatchEvents" Version="4.4.0" />
1112
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.3" />
1213
<PackageReference Include="Amazon.Lambda.Core" Version="2.8.0" />
1314
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" />

user-management/src/Stickerlandia.UserManagement.Azure/ServiceBusStickerPrintedWorker.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ private async Task ProcessMessageAsync(ProcessMessageEventArgs args)
8080
stickerPrinted = JsonSerializer.Deserialize<StickerPrintedEventV1>(messageBody);
8181
}
8282

83-
if (stickerPrinted == null) await args.DeadLetterMessageAsync(args.Message, "Message body cannot be deserialized");
84-
83+
if (stickerPrinted == null)
84+
{
85+
await args.DeadLetterMessageAsync(args.Message, "Message body cannot be deserialized");
86+
return;
87+
}
88+
8589
try
8690
{
8791
await handler.Handle(stickerPrinted!);
@@ -90,6 +94,7 @@ private async Task ProcessMessageAsync(ProcessMessageEventArgs args)
9094
{
9195
Log.InvalidUser(_logger, ex);
9296
await args.DeadLetterMessageAsync(args.Message, "Invalid account id");
97+
return;
9398
}
9499

95100
// Complete the message

0 commit comments

Comments
 (0)