Skip to content

Commit

Permalink
Merge pull request #81 from wemogy/rmt/otlp-monitoring
Browse files Browse the repository at this point in the history
[BREAKING] Add OTLP to monitoring environment
  • Loading branch information
robinmanuelthiel authored Sep 20, 2023
2 parents 350a420 + d2b5824 commit 4614390
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 56 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dotnet.defaultSolution": "src/Wemogy.Core.sln",
"cSpell.words": ["Otlp"]
}
12 changes: 0 additions & 12 deletions src/Wemogy.Core/Monitoring/IMonitoringService.cs

This file was deleted.

47 changes: 44 additions & 3 deletions src/Wemogy.Core/Monitoring/MonitoringEnvironment.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
using System;
using System.Collections.Generic;
using System.Reflection;

namespace Wemogy.Core.Monitoring
{
public class MonitoringEnvironment
{
public string ServiceName { get; }
public string ServiceVersion { get; }
public string ApplicationInsightsConnectionString { get; private set; }
public bool UsePrometheus { get; private set; }
public bool UseApplicationInsights => !string.IsNullOrEmpty(ApplicationInsightsConnectionString);
public Uri? OtlpExportEndpoint { get; private set; }
public bool UseOtlpExporter => OtlpExportEndpoint != null;
public bool UsePrometheus { get; private set; }
public HashSet<string> MeterNames { get; private set; }

public MonitoringEnvironment(string serviceName)
public MonitoringEnvironment()
{
ServiceName = serviceName;
ServiceName = Assembly.GetEntryAssembly().GetName().Name!;
ServiceVersion = Assembly.GetEntryAssembly().GetName().Version != null
? Assembly.GetExecutingAssembly().GetName().Version!.ToString()
: "0.0.0";

ApplicationInsightsConnectionString = string.Empty;
UsePrometheus = false;
OtlpExportEndpoint = null;
MeterNames = new HashSet<string>();
}

public MonitoringEnvironment(string serviceName, string serviceVersion)
: this()
{
ServiceName = serviceName;
ServiceVersion = serviceVersion;
}

public MonitoringEnvironment WithApplicationInsights(string connectionString)
Expand All @@ -20,10 +41,30 @@ public MonitoringEnvironment WithApplicationInsights(string connectionString)
return this;
}

/// <summary>
/// Adds an OpenTelemetry protocol (OTLP) exporter (e.g. Jaeger) to publish metrics to.
/// </summary>
/// <param name="endpoint">The endpoint to export to.</param>
public MonitoringEnvironment WithOtlpExporter(Uri endpoint)
{
OtlpExportEndpoint = endpoint;
return this;
}

public MonitoringEnvironment WithPrometheus()
{
UsePrometheus = true;
return this;
}

/// <summary>
/// Registers a System.Diagnostics.Metrics.Meter at the environment. The meter itself has to be created outside the environment.
/// </summary>
/// <param name="meterName">Name of the meter</param>
public MonitoringEnvironment WithMeter(string meterName)
{
MeterNames.Add(meterName);
return this;
}
}
}
41 changes: 0 additions & 41 deletions src/Wemogy.Core/Monitoring/MonitoringService.cs

This file was deleted.

0 comments on commit 4614390

Please sign in to comment.