Skip to content

Commit 31de68a

Browse files
authored
Merge pull request #360 from Resgrid/develop
RE1-T115 More TTS work plus adding Sentry to TTS service
2 parents 1c45da9 + 4f9e1aa commit 31de68a

5 files changed

Lines changed: 62 additions & 3 deletions

File tree

Core/Resgrid.Config/ExternalErrorConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static class ExternalErrorConfig
2222
public static string ExternalErrorServiceUrlForInternalApi = "";
2323
public static string ExternalErrorServiceUrlForInternalWorker = "";
2424
public static string ExternalErrorServiceUrlForMcp = "";
25+
public static string ExternalErrorServiceUrlForTts = "";
2526
public static double SentryPerfSampleRate = 0.4;
2627
public static double SentryProfilingSampleRate = 0;
2728
#endregion Sentry Settings

Web/Resgrid.Web.Tts/Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,17 @@ WORKDIR /src/Web/Resgrid.Web.Tts
1919
RUN dotnet publish "Resgrid.Web.Tts.csproj" -c Release -o /app/publish /p:UseAppHost=false --no-restore -p:Version=${BUILD_VERSION}
2020

2121
FROM base AS final
22-
RUN apt-get update \
23-
&& apt-get install -y --no-install-recommends espeak-ng ffmpeg ca-certificates \
22+
# Enable multiverse repository for MBROLA packages, install TTS dependencies,
23+
# then clean up in a single RUN layer to keep the image small.
24+
RUN echo "deb http://archive.ubuntu.com/ubuntu/ noble multiverse" >> /etc/apt/sources.list \
25+
&& echo "deb http://archive.ubuntu.com/ubuntu/ noble-updates multiverse" >> /etc/apt/sources.list \
26+
&& apt-get update \
27+
&& apt-get install -y --no-install-recommends \
28+
espeak-ng \
29+
ffmpeg \
30+
ca-certificates \
31+
mbrola \
32+
mbrola-us1 \
2433
&& rm -rf /var/lib/apt/lists/* \
2534
&& groupadd --gid 10001 appgroup \
2635
&& useradd --uid 10001 --gid appgroup --create-home --shell /usr/sbin/nologin appuser

Web/Resgrid.Web.Tts/Program.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,54 @@
99
using Resgrid.Web.Tts.Configuration;
1010
using Resgrid.Web.Tts.Health;
1111
using Resgrid.Web.Tts.Services;
12+
using System.Reflection;
1213
using System.Text.Json;
1314
using System.Threading.RateLimiting;
15+
using Sentry.Profiling;
1416

1517
var builder = WebApplication.CreateBuilder(args);
1618

1719
ConfigProcessor.LoadAndProcessConfig(builder.Configuration["AppOptions:ConfigPath"]);
1820
ConfigProcessor.LoadAndProcessEnvVariables(builder.Configuration.AsEnumerable());
1921

22+
// Configure Sentry error tracking and performance monitoring
23+
if (!string.IsNullOrWhiteSpace(ExternalErrorConfig.ExternalErrorServiceUrlForTts))
24+
{
25+
builder.WebHost.UseSentry(options =>
26+
{
27+
options.Dsn = ExternalErrorConfig.ExternalErrorServiceUrlForTts;
28+
options.AttachStacktrace = true;
29+
options.SendDefaultPii = true;
30+
options.AutoSessionTracking = true;
31+
options.TracesSampleRate = ExternalErrorConfig.SentryPerfSampleRate;
32+
options.Environment = ExternalErrorConfig.Environment;
33+
options.Release = Assembly.GetEntryAssembly()?.GetName().Version?.ToString();
34+
options.ProfilesSampleRate = ExternalErrorConfig.SentryProfilingSampleRate;
35+
36+
// Add profiling integration for performance tracing
37+
options.AddIntegration(new ProfilingIntegration());
38+
39+
options.TracesSampler = samplingContext =>
40+
{
41+
if (samplingContext?.CustomSamplingContext != null)
42+
{
43+
if (samplingContext.CustomSamplingContext.TryGetValue("__HttpPath", out var httpPath))
44+
{
45+
var pathValue = httpPath?.ToString();
46+
if (string.Equals(pathValue, "/health", StringComparison.OrdinalIgnoreCase) ||
47+
string.Equals(pathValue, "/livez", StringComparison.OrdinalIgnoreCase) ||
48+
string.Equals(pathValue, "/readyz", StringComparison.OrdinalIgnoreCase))
49+
{
50+
return 0;
51+
}
52+
}
53+
}
54+
55+
return ExternalErrorConfig.SentryPerfSampleRate;
56+
};
57+
});
58+
}
59+
2060
builder.Logging.ClearProviders();
2161
builder.Logging.AddJsonConsole();
2262

Web/Resgrid.Web.Tts/Resgrid.Web.Tts.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
<ItemGroup>
1313
<PackageReference Include="AWSSDK.S3" Version="3.7.414.5" />
1414
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.2" />
15+
<PackageReference Include="Sentry.AspNetCore" Version="5.4.0" />
16+
<PackageReference Include="Sentry.Profiling" Version="5.4.0" />
1517
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.0.0" />
1618
</ItemGroup>
1719

Web/Resgrid.Web.Tts/appsettings.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66
"Amazon": "Warning"
77
}
88
},
9+
"Sentry": {
10+
"IncludeActivityData": true,
11+
"MaxBreadcrumbs": 50,
12+
"MinimumBreadcrumbLevel": "Information",
13+
"MinimumEventLevel": "Error",
14+
"Debug": false
15+
},
916
"AppOptions": {
1017
"ConfigPath": ""
1118
},
12-
"_Comment": "TTS runtime settings are loaded from Resgrid.Config.TtsConfig via ResgridConfig.json or RESGRID:TtsConfig:* environment variables.",
19+
"_Comment": "TTS runtime settings are loaded from Resgrid.Config.TtsConfig via ResgridConfig.json or RESGRID:TtsConfig:* environment variables. Sentry DSN uses ExternalErrorConfig.ExternalErrorServiceUrlForTts.",
1320
"AllowedHosts": "*",
1421
"ConnectionStrings": {
1522
}

0 commit comments

Comments
 (0)