Skip to content

Commit f88153e

Browse files
committed
Adding Sentry and removing Rebus.
1 parent 0557dac commit f88153e

File tree

8 files changed

+66
-239
lines changed

8 files changed

+66
-239
lines changed

eFormAPI/Plugins/GreateBelt.Pn/GreateBelt.Pn/EformGreateBeltPlugin.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
SOFTWARE.
2323
*/
2424

25+
using System.Runtime.InteropServices;
26+
using System.Text.RegularExpressions;
27+
using Sentry;
28+
2529
namespace GreateBelt.Pn
2630
{
2731
using System;
@@ -39,7 +43,6 @@ namespace GreateBelt.Pn
3943
using Microting.ItemsPlanningBase.Infrastructure.Data;
4044
using Services.GreateBeltLocalizationService;
4145
using Services.GreateBeltReportService;
42-
using Services.RebusService;
4346

4447
public class EformGreateBeltPlugin : IEformPlugin
4548
{
@@ -58,7 +61,6 @@ public Assembly PluginAssembly()
5861

5962
public void ConfigureServices(IServiceCollection services)
6063
{
61-
services.AddSingleton<IRebusService, RebusService>();
6264
services.AddTransient<IGreateBeltLocalizationService, GreateBeltLocalizationService>();
6365
services.AddTransient<IGreateBeltReportService, GreateBeltReportService>();
6466
services.AddControllers();
@@ -74,6 +76,49 @@ public void ConfigureOptionsServices(IServiceCollection services, IConfiguration
7476

7577
public void ConfigureDbContext(IServiceCollection services, string connectionString)
7678
{
79+
SentrySdk.Init(options =>
80+
{
81+
// A Sentry Data Source Name (DSN) is required.
82+
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
83+
// You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
84+
options.Dsn = "https://2cd3071eb1d210f5384914322eb6e765@o4506241219428352.ingest.us.sentry.io/4508266870145024";
85+
86+
// When debug is enabled, the Sentry client will emit detailed debugging information to the console.
87+
// This might be helpful, or might interfere with the normal operation of your application.
88+
// We enable it here for demonstration purposes when first trying Sentry.
89+
// You shouldn't do this in your applications unless you're troubleshooting issues with Sentry.
90+
options.Debug = false;
91+
92+
// This option is recommended. It enables Sentry's "Release Health" feature.
93+
options.AutoSessionTracking = true;
94+
95+
// This option is recommended for client applications only. It ensures all threads use the same global scope.
96+
// If you're writing a background service of any kind, you should remove this.
97+
options.IsGlobalModeEnabled = true;
98+
99+
// This option will enable Sentry's tracing features. You still need to start transactions and spans.
100+
options.EnableTracing = true;
101+
});
102+
103+
string pattern = @"Database=(\d+)_eform-angular-greate-belt-plugin;";
104+
Match match = Regex.Match(connectionString!, pattern);
105+
106+
if (match.Success)
107+
{
108+
string numberString = match.Groups[1].Value;
109+
int number = int.Parse(numberString);
110+
SentrySdk.ConfigureScope(scope =>
111+
{
112+
scope.SetTag("customerNo", number.ToString());
113+
Console.WriteLine("customerNo: " + number);
114+
scope.SetTag("osVersion", Environment.OSVersion.ToString());
115+
Console.WriteLine("osVersion: " + Environment.OSVersion);
116+
scope.SetTag("osArchitecture", RuntimeInformation.OSArchitecture.ToString());
117+
Console.WriteLine("osArchitecture: " + RuntimeInformation.OSArchitecture);
118+
scope.SetTag("osName", RuntimeInformation.OSDescription);
119+
Console.WriteLine("osName: " + RuntimeInformation.OSDescription);
120+
});
121+
}
77122
var itemsPlannigConnectionString = connectionString.Replace(
78123
"eform-angular-greate-belt-plugin",
79124
"eform-angular-items-planning-plugin");

eFormAPI/Plugins/GreateBelt.Pn/GreateBelt.Pn/GreateBelt.Pn.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<PackageReference Include="Microting.eForm" Version="8.0.68" />
2727
<PackageReference Include="Microting.eFormApi.BasePn" Version="8.0.69" />
2828
<PackageReference Include="Microting.ItemsPlanningBase" Version="8.0.62" />
29+
<PackageReference Include="Sentry" Version="4.13.0" />
2930
</ItemGroup>
3031

3132
</Project>

eFormAPI/Plugins/GreateBelt.Pn/GreateBelt.Pn/Installers/RebusHandlerInstaller.cs

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

eFormAPI/Plugins/GreateBelt.Pn/GreateBelt.Pn/Installers/RebusInstaller.cs

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

eFormAPI/Plugins/GreateBelt.Pn/GreateBelt.Pn/Services/GreateBeltLocalizationService/GreateBeltLocalizationService.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,9 @@ namespace GreateBelt.Pn.Services.GreateBeltLocalizationService
2727
using Microsoft.Extensions.Localization;
2828
using Microting.eFormApi.BasePn.Localization.Abstractions;
2929

30-
public class GreateBeltLocalizationService : IGreateBeltLocalizationService
30+
public class GreateBeltLocalizationService(IEformLocalizerFactory factory) : IGreateBeltLocalizationService
3131
{
32-
private readonly IStringLocalizer _localizer;
33-
34-
public GreateBeltLocalizationService(IEformLocalizerFactory factory)
35-
{
36-
_localizer = factory.Create(typeof(EformGreateBeltPlugin));
37-
}
32+
private readonly IStringLocalizer _localizer = factory.Create(typeof(EformGreateBeltPlugin));
3833

3934
public string GetString(string key)
4035
{

eFormAPI/Plugins/GreateBelt.Pn/GreateBelt.Pn/Services/GreateBeltReportService/GreateBeltReportService.cs

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020

2121
using System.Collections.Generic;
2222
using System.Text.RegularExpressions;
23+
using Sentry;
2324

2425
namespace GreateBelt.Pn.Services.GreateBeltReportService
2526
{
@@ -36,34 +37,20 @@ namespace GreateBelt.Pn.Services.GreateBeltReportService
3637
using Microting.eFormApi.BasePn.Infrastructure.Models.Common;
3738
using Microting.ItemsPlanningBase.Infrastructure.Data;
3839

39-
public class GreateBeltReportService : IGreateBeltReportService
40+
public class GreateBeltReportService(
41+
ILogger<GreateBeltReportService> logger,
42+
ItemsPlanningPnDbContext itemsPlanningPnDbContext,
43+
IUserService userService,
44+
IGreateBeltLocalizationService localizationService,
45+
IEFormCoreService core)
46+
: IGreateBeltReportService
4047
{
41-
private readonly ILogger<GreateBeltReportService> _logger;
42-
private readonly ItemsPlanningPnDbContext _itemsPlanningPnDbContext;
43-
private readonly IUserService _userService;
44-
private readonly IGreateBeltLocalizationService _localizationService;
45-
private readonly IEFormCoreService _core;
46-
47-
public GreateBeltReportService(
48-
ILogger<GreateBeltReportService> logger,
49-
ItemsPlanningPnDbContext itemsPlanningPnDbContext,
50-
IUserService userService,
51-
IGreateBeltLocalizationService localizationService,
52-
IEFormCoreService core)
53-
{
54-
_logger = logger;
55-
_itemsPlanningPnDbContext = itemsPlanningPnDbContext;
56-
_userService = userService;
57-
_localizationService = localizationService;
58-
_core = core;
59-
}
60-
6148
public async Task<OperationDataResult<Paged<GreateBeltReportIndexModel>>> Index(GreateBeltReportIndexRequestModel model)
6249
{
6350
try
6451
{
65-
var core = await _core.GetCore();
66-
var sdkDbContext = core.DbContextHelper.GetDbContext();
52+
var core1 = await core.GetCore();
53+
var sdkDbContext = core1.DbContextHelper.GetDbContext();
6754

6855
var casesQuery = sdkDbContext.Cases
6956
.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
@@ -88,7 +75,7 @@ public async Task<OperationDataResult<Paged<GreateBeltReportIndexModel>>> Index(
8875
.ToListAsync();
8976

9077
var foundCaseIds = foundCases.Select(x => x.Id).ToList();
91-
var planningQuery = _itemsPlanningPnDbContext.Plannings
78+
var planningQuery = itemsPlanningPnDbContext.Plannings
9279
.Where(x => model.EformIds.Contains(x.RelatedEFormId))
9380
.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
9481
.Select(x => new
@@ -104,7 +91,7 @@ public async Task<OperationDataResult<Paged<GreateBeltReportIndexModel>>> Index(
10491
var plannings = await planningQuery
10592
.ToListAsync();
10693

107-
var planningCasesQuery = _itemsPlanningPnDbContext.PlanningCases
94+
var planningCasesQuery = itemsPlanningPnDbContext.PlanningCases
10895
.Include(x => x.Planning)
10996
.Where(x => foundCaseIds.Contains(x.MicrotingSdkCaseId))
11097
.Where(x => x.Status == 100)
@@ -267,9 +254,11 @@ public async Task<OperationDataResult<Paged<GreateBeltReportIndexModel>>> Index(
267254
}
268255
catch (Exception e)
269256
{
270-
_logger.LogError(e, $"User {_userService.GetCurrentUserFullName()} logged in from GreateBeltReportService.Index");
257+
SentrySdk.CaptureException(e);
258+
logger.LogError(e, $"User {userService.GetCurrentUserFullName()} logged in from GreateBeltReportService.Index");
259+
logger.LogTrace(e.StackTrace);
271260
return new OperationDataResult<Paged<GreateBeltReportIndexModel>>(false,
272-
_localizationService.GetString("ErrorWhileReadCases"));
261+
localizationService.GetString("ErrorWhileReadCases"));
273262
}
274263
}
275264
}

eFormAPI/Plugins/GreateBelt.Pn/GreateBelt.Pn/Services/RebusService/IRebusService.cs

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

eFormAPI/Plugins/GreateBelt.Pn/GreateBelt.Pn/Services/RebusService/RebusService.cs

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

0 commit comments

Comments
 (0)