Skip to content

Commit 16898d7

Browse files
authored
NewRelic integration (#717)
* NewRelic integration - iOS * NewRelic integration - Android * BackgroundLogger removed * iOS pipeline - macOS version bumped * Proguard rules updated && notification builder disposed fix
1 parent 7238eaa commit 16898d7

File tree

24 files changed

+226
-171
lines changed

24 files changed

+226
-171
lines changed

BMM.Api/Framework/ILogger.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ public interface ILogger
99
void Warn(string tag, string message);
1010
void Error(string tag, string message);
1111
void Error(string tag, string message, Exception exception, bool presentedToUser = false);
12+
void TrackEvent(string message, IDictionary<string, string> properties);
1213
}
1314
}

BMM.Core/App.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
using BMM.Core.Models.POs.Tracks.Interfaces;
8080
using BMM.Core.NewMediaPlayer;
8181
using BMM.Core.NewMediaPlayer.Abstractions;
82-
using Microsoft.AppCenter;
8382
using MvvmCross;
8483
using MvvmCross.Base;
8584
using MvvmCross.IoC;
@@ -115,10 +114,6 @@ public override void Initialize()
115114
Registrations.Start(GlobalConstants.ApplicationName);
116115
BlobCache.ApplicationName = GlobalConstants.PackageName;
117116

118-
#if DEBUG
119-
AppCenter.LogLevel = LogLevel.Info;
120-
#endif
121-
122117
SetupLanguageBinder();
123118

124119
Mvx.IoCProvider.LazyConstructAndRegisterSingleton<IRememberedQueueService, RememberedQueueService>();
@@ -134,7 +129,7 @@ public override void Initialize()
134129
Mvx.IoCProvider.RegisterType<IResponseDeserializer, ResponseDeserializer>();
135130
Mvx.IoCProvider.RegisterType<IBmmVersionProvider, BmmVersionProvider>();
136131

137-
Mvx.IoCProvider.RegisterType<IAnalytics, AppCenterAnalytics>();
132+
Mvx.IoCProvider.RegisterType<IAnalytics, NewRelicAnalytics>();
138133
Mvx.IoCProvider.LazyConstructAndRegisterSingleton<IDeepLinkHandler, DeepLinkHandler>();
139134
Mvx.IoCProvider.RegisterType<IShareLink, ShareLink>();
140135
Mvx.IoCProvider.RegisterType<IAppNavigator, AppNavigator>();
@@ -277,8 +272,6 @@ public override void Initialize()
277272
},
278273
MvxReference.Strong);
279274

280-
Mvx.IoCProvider.ConstructAndRegisterSingleton<BackgroundLogger, BackgroundLogger>();
281-
282275
Mvx.IoCProvider.RegisterType<PersistedEventWriter>();
283276
Mvx.IoCProvider.RegisterType<FirebaseConfigUpdater>();
284277
Mvx.IoCProvider.RegisterType<AfterStartupSupportEndsPopupDisplayer>();

BMM.Core/BMM.Core.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
<PackageReference Include="akavache" Version="9.1.7" />
1717
<PackageReference Include="IdentityModel" Version="7.0.0" />
1818
<PackageReference Include="IdentityModel.OidcClient" Version="6.0.0" />
19-
<PackageReference Include="Microsoft.AppCenter" Version="5.0.1" />
20-
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.1" />
2119
<PackageReference Include="MvvmCross" Version="9.2.0" />
2220
<PackageReference Include="MvvmCross.Plugin.JsonLocalization" Version="9.2.0" />
2321
<PackageReference Include="MvvmCross.Plugin.Messenger" Version="9.2.0" />

BMM.Core/Constants/AnalyticsConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace BMM.Core.Constants
22
{
33
public class AnalyticsConstants
44
{
5+
public const string NewRelicEventType = "BMM";
56
public const string ConnectionParameterName = "ConnectionType";
67
}
78
}

BMM.Core/Helpers/AnalyticsInitializer.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Microsoft.AppCenter;
2-
using Microsoft.AppCenter.Analytics;
3-
using Microsoft.Maui.Devices;
1+
using Microsoft.Maui.Devices;
42

53
namespace BMM.Core.Helpers
64
{
@@ -15,9 +13,6 @@ public abstract class AnalyticsInitializer
1513

1614
public static void IOSRegister()
1715
{
18-
if (!AppCenter.Configured)
19-
AppCenter.Start(GlobalConstants.iOSAppSecret, typeof(Analytics));
20-
2116
if (ShouldInitSentry)
2217
SentrySdk.Init(SetupSentry);
2318
}

BMM.Core/Helpers/GlobalConstants.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public class GlobalConstants
5656
public const bool PushNotificationsEnabledDefault = true;
5757
public const int NetworkRequestTimeout = 10;
5858
public const int DefaultNumberOfPodcastTracksToDownload = 3;
59-
public const string DroidAppSecret = "#{Android_APP_SECRET_PLACEHOLDER}#";
60-
public const string iOSAppSecret = "#{iOS_APP_SECRET_PLACEHOLDER}#";
6159
public const string SentryDsn = "#{SENTRY_DSN_PLACEHOLDER}#";
60+
public const string NewRelicAndroidToken = "#{NEW_RELIC_ANDROID_PLACEHOLDER}#";
61+
public const string NewRelic_iOSToken = "#{NEW_RELIC_IOS_PLACEHOLDER}#";
6262

6363
public const string AndroidUpdateLink = "https://play.google.com/store/apps/details?id=org.brunstad.bmm";
6464
public const string IosUpdateLink = "itms-apps://apps.apple.com/no/app/bmm-brunstad/id777577855";

BMM.Core/Implementations/Analytics/AppCenterAnalytics.cs renamed to BMM.Core/Implementations/Analytics/NewRelicAnalytics.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
namespace BMM.Core.Implementations.Analytics
1010
{
11-
public class AppCenterAnalytics : IAnalytics
11+
public class NewRelicAnalytics : IAnalytics
1212
{
1313
private readonly ILogger _logger;
1414
private readonly IUserStorage _userStorage;
1515
private readonly IFirebaseRemoteConfig _remoteConfig;
1616
private readonly IConnection _connection;
1717

18-
public AppCenterAnalytics(
18+
public NewRelicAnalytics(
1919
ILogger logger,
2020
IUserStorage userStorage,
2121
IFirebaseRemoteConfig remoteConfig,
@@ -48,9 +48,9 @@ public void LogEvent(string eventName, IDictionary<string, object> parameters)
4848

4949
parameters.Add(AnalyticsConstants.ConnectionParameterName, AnalyticsUtils.GetConnectionType(_connection));
5050

51-
Dictionary<string, string> dString = parameters.ToDictionary(k => k.Key, k => k.Value == null ? "null" : k.Value.ToString());
51+
var dString = parameters.ToDictionary(k => k.Key, k => k.Value == null ? "null" : k.Value.ToString());
5252
_logger.Info("Analytics", eventName + " {" + string.Join(",", dString.Select(kv => $"{kv.Key}={kv.Value}")) + "}");
53-
Microsoft.AppCenter.Analytics.Analytics.TrackEvent(eventName, dString);
53+
_logger.TrackEvent(eventName, dString);
5454
}
5555
}
5656
}

BMM.Core/Implementations/Downloading/BackgroundLogger.cs

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

BMM.Core/Implementations/Exceptions/ErrorDialogDisplayingLogger.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@ public void Error(string tag, string message, Exception exception, bool presente
4444
_logger.Error(tag, message, exception, presentedToUser);
4545
_mainThreadAsyncDispatcher.ExecuteOnMainThreadAsync(() => _userDialogs.AlertAsync(exception.Message));
4646
}
47+
48+
public void TrackEvent(string message, IDictionary<string, string> properties)
49+
{
50+
_logger.TrackEvent(message, properties);
51+
}
4752
}
4853
}

BMM.Core/Implementations/Logger/BaseLogger.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using BMM.Api.Framework;
22
using BMM.Core.Constants;
3-
using BMM.Core.Implementations.Exceptions;
43
using BMM.Core.Implementations.Security;
54
using BMM.Core.Utils;
6-
using Microsoft.AppCenter;
75

86
namespace BMM.Core.Implementations.Logger
97
{
@@ -25,22 +23,24 @@ protected BaseLogger(
2523
_connection = connection;
2624
_userStorage = userStorage;
2725
}
28-
26+
2927
public void Debug(string tag, string message)
3028
{
31-
AppCenterLog.Debug(tag, message);
29+
Console.WriteLine($"DEBUG - {tag} - {message}");
3230
}
3331

3432
public void Info(string tag, string message)
3533
{
36-
AppCenterLog.Info(tag, message);
34+
Console.WriteLine($"INFO - {tag} - {message}");
3735
}
3836

37+
public abstract void TrackEvent(string message, IDictionary<string, string> properties);
38+
3939
public void Warn(string tag, string message)
4040
{
4141
var parameters = InitializeDictionaryWithBasicParameters(tag, message);
42-
AppCenterLog.Warn(tag, message);
43-
Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Warning", parameters);
42+
Console.WriteLine($"WARN - {tag} - {message}");
43+
TrackEvent("Warning", parameters);
4444
}
4545

4646
public virtual void Error(string tag, string message)
@@ -51,21 +51,20 @@ public virtual void Error(string tag, string message)
5151
GetSentryScope(parameters),
5252
SentryLevel.Error);
5353

54-
AppCenterLog.Error(tag, message);
55-
Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Error without exception", parameters);
54+
TrackEvent("Error without exception", parameters);
5655
}
5756

5857
public virtual void Error(string tag, string message, Exception exception, bool presentedToUser = false)
5958
{
6059
var parameters = InitializeDictionaryWithBasicParameters(tag, message, presentedToUser);
6160

6261
SentrySdk.CaptureException(exception, GetSentryScope(parameters));
63-
AppCenterLog.Error(tag, message, exception);
64-
62+
Console.WriteLine($"ERROR - {tag} - {message} \n \n {exception}");
63+
6564
parameters.Add(StackTrackParameterName, exception.StackTrace);
6665
parameters.Add(ExceptionParameterName, exception.ToString());
6766

68-
Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Error with exception", parameters);
67+
TrackEvent("Error with exception", parameters);
6968
}
7069

7170
private static Action<Scope> GetSentryScope(IDictionary<string, string> parameters)

0 commit comments

Comments
 (0)