Files
WireMock.Net/src/WireMock.Net.OpenTelemetry/OpenTelemetryOptionsParser.cs
Petr Houška 4525c61847 Add OTEL tracing support for Wiremock + automatic OTEL for Aspire integration (#1418)
* Update aspire to 13.1 (examples + code)

Allows usage of aspire CLI which is very useful for dev in codespaces (for my next PR).

* Add OTEL support

* Initial PR feedback

* PR feedback

* PR feedback

* PR feedback

* Cleanup.

* Cleanup

* Fix

* Fix

* Rename stuff around to be more accurate

* PR feedback

* Update WireMock.Net.OpenTelemetry.csproj

Update <Authors>

* PR feedback parser

* PR feedback package versions

* Status code feedback.

* Update preprocessor directives to to Activity Tracing instead of OpenTelemetry. Is more descriptive.

* Add tests

* Improve tests

---------

Co-authored-by: Stef Heyenrath <Stef.Heyenrath@gmail.com>
2026-01-18 17:22:36 +01:00

45 lines
1.4 KiB
C#

// Copyright © WireMock.Net
using System.Collections;
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, out OpenTelemetryOptions? options)
{
Guard.HasNoNulls(args);
var parser = new SimpleSettingsParser();
parser.Parse(args, environment);
if (!parser.GetBoolValue($"{Prefix}Enabled"))
{
options = null;
return true;
}
options = new OpenTelemetryOptions
{
ExcludeAdminRequests = parser.GetBoolValue($"{Prefix}ExcludeAdminRequests", defaultValue: true),
OtlpExporterEndpoint = parser.GetStringValue($"{Prefix}OtlpExporterEndpoint")
};
return true;
}
}