Skip to content

Commit

Permalink
Merge pull request #86 from wemogy/update/monitoring
Browse files Browse the repository at this point in the history
[FEATURE] Add OTEL Service Names and App Insights Sampling Ratio
  • Loading branch information
robinmanuelthiel authored Nov 25, 2023
2 parents 3820b07 + 4c51a4a commit 233290f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Wemogy.Core.Tests/Json/Demo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Text.Json.Serialization;

namespace Wemogy.Core.Tests;

public class Demo
{
[JsonInclude]
public int Id { get; private set; }
}
22 changes: 22 additions & 0 deletions src/Wemogy.Core.Tests/Json/WemogyJsonTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Text.Json;
using Wemogy.Core.Json;
using Xunit;

namespace Wemogy.Core.Tests;

public class WemogyJsonTests
{
[Fact]
public void PrivateSetters_GetSet()
{
// Arrange
var json = @"{""id"": 123}";

// Act
var demo = JsonSerializer.Deserialize<Demo>(json, WemogyJson.Options);

// Assert
Assert.Equal(123, demo!.Id);
}
}
15 changes: 14 additions & 1 deletion src/Wemogy.Core/Monitoring/MonitoringEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ namespace Wemogy.Core.Monitoring
public class MonitoringEnvironment
{
public string ServiceName { get; }
public string? ServiceNamespace { get; }
public string? ServiceInstanceId { get; }
public string ServiceVersion { get; }
public string ApplicationInsightsConnectionString { get; private set; }
public float ApplicationInsightsSamplingRatio { get; private set; }
public bool UseApplicationInsights => !string.IsNullOrEmpty(ApplicationInsightsConnectionString);
public Uri? OtlpExportEndpoint { get; private set; }
public bool UseOtlpExporter => OtlpExportEndpoint != null;
Expand All @@ -35,9 +38,19 @@ public MonitoringEnvironment(string serviceName, string serviceVersion)
ServiceVersion = serviceVersion;
}

public MonitoringEnvironment WithApplicationInsights(string connectionString)
public MonitoringEnvironment(string serviceName, string serviceNamespace, string serviceInstanceId, string serviceVersion)
: this(serviceName, serviceVersion)
{
ServiceName = serviceName;
ServiceNamespace = serviceNamespace;
ServiceInstanceId = serviceInstanceId;
ServiceVersion = serviceVersion;
}

public MonitoringEnvironment WithApplicationInsights(string connectionString, float samplingRatio = 1f)
{
ApplicationInsightsConnectionString = connectionString;
ApplicationInsightsSamplingRatio = samplingRatio;
return this;
}

Expand Down

0 comments on commit 233290f

Please sign in to comment.