mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-11-27 02:44:24 +01:00
* Initial plan * Configure OpenTelemetry activity source and service name Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * tests * auth --------- Co-authored-by: StefH <249938+StefH@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
// Copyright © WireMock.Net
|
|
|
|
using System.Collections;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using Stef.Validation;
|
|
using WireMock.Settings;
|
|
|
|
namespace WireMock.OpenTelemetry;
|
|
|
|
/// <summary>
|
|
/// A static helper class to parse commandline arguments into OpenTelemetryOptions.
|
|
/// </summary>
|
|
public static class OpenTelemetryOptionsParser
|
|
{
|
|
private const string Prefix = "OpenTelemetry";
|
|
|
|
/// <summary>
|
|
/// Parse commandline arguments into OpenTelemetryOptions.
|
|
/// </summary>
|
|
/// <param name="args">The commandline arguments</param>
|
|
/// <param name="environment">The environment settings (optional)</param>
|
|
/// <param name="options">The parsed options, or null if OpenTelemetry is not enabled</param>
|
|
/// <returns>Always returns true.</returns>
|
|
public static bool TryParseArguments(string[] args, IDictionary? environment, [NotNullWhen(true)] out OpenTelemetryOptions? options)
|
|
{
|
|
Guard.HasNoNulls(args);
|
|
|
|
var parser = new SimpleSettingsParser();
|
|
parser.Parse(args, environment);
|
|
|
|
if (!parser.GetBoolValue($"{Prefix}Enabled"))
|
|
{
|
|
options = null;
|
|
return false;
|
|
}
|
|
|
|
var activitySourceName = parser.GetStringValue($"{Prefix}ActivitySourceName");
|
|
options = new OpenTelemetryOptions
|
|
{
|
|
ActivitySourceName = string.IsNullOrWhiteSpace(activitySourceName) ? OpenTelemetryOptions.DefaultActivitySourceName : activitySourceName!,
|
|
ExcludeAdminRequests = parser.GetBoolValue($"{Prefix}ExcludeAdminRequests", defaultValue: true),
|
|
OtlpExporterEndpoint = parser.GetStringValue($"{Prefix}OtlpExporterEndpoint")
|
|
};
|
|
|
|
return true;
|
|
}
|
|
}
|