diff --git a/src/Wemogy.Core/Monitoring/MonitoringEnvironment.cs b/src/Wemogy.Core/Monitoring/MonitoringEnvironment.cs
index 58d06ed..99b9952 100644
--- a/src/Wemogy.Core/Monitoring/MonitoringEnvironment.cs
+++ b/src/Wemogy.Core/Monitoring/MonitoringEnvironment.cs
@@ -12,7 +12,7 @@ public class MonitoringEnvironment
public string ServiceVersion { get; }
public string ApplicationInsightsConnectionString { get; private set; }
public float ApplicationInsightsSamplingRatio { get; private set; }
- public bool UseApplicationInsights => !string.IsNullOrEmpty(ApplicationInsightsConnectionString);
+ public bool UseApplicationInsights { get; private set; }
public Uri? OtlpExportEndpoint { get; private set; }
public bool UseOtlpExporter => OtlpExportEndpoint != null;
public bool UsePrometheus { get; private set; }
@@ -49,10 +49,44 @@ public MonitoringEnvironment(string serviceName, string serviceNamespace, string
ServiceVersion = serviceVersion;
}
+ ///
+ /// Adds an Application Insights exporter to publish metrics to.
+ /// Fails, if the Connection String is null or empty.
+ ///
+ /// The connection string to export to.
+ /// The sampling ratio to use.
public MonitoringEnvironment WithApplicationInsights(string connectionString, float samplingRatio = 1f)
{
+ if (string.IsNullOrEmpty(connectionString))
+ {
+ throw new ArgumentException("The connection string must not be null or empty.", nameof(connectionString));
+ }
+
ApplicationInsightsConnectionString = connectionString;
ApplicationInsightsSamplingRatio = samplingRatio;
+ UseApplicationInsights = true;
+ return this;
+ }
+
+ ///
+ /// Adds an Application Insights exporter to publish metrics to.
+ /// Skips, if the Connection String is null or empty.
+ ///
+ /// The connection string to export to.
+ /// The sampling ratio to use.
+ public MonitoringEnvironment WithOptionalApplicationInsights(string? connectionString, float samplingRatio = 1f)
+ {
+ if (!string.IsNullOrEmpty(connectionString))
+ {
+ ApplicationInsightsConnectionString = connectionString;
+ ApplicationInsightsSamplingRatio = samplingRatio;
+ UseApplicationInsights = true;
+ }
+ else
+ {
+ UseApplicationInsights = false;
+ }
+
return this;
}