mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-26 03:11:56 +01:00
mm
This commit is contained in:
@@ -10,6 +10,9 @@ using WireMock.Exceptions;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
#if OPENTELEMETRY_SUPPORTED
|
||||
using WireMock.OpenTelemetry;
|
||||
#endif
|
||||
|
||||
namespace WireMock.Net.StandAlone;
|
||||
|
||||
@@ -37,6 +40,39 @@ public static class StandAloneApp
|
||||
return server;
|
||||
}
|
||||
|
||||
#if OPENTELEMETRY_SUPPORTED
|
||||
/// <summary>
|
||||
/// Start WireMock.Net standalone Server based on the WireMockServerSettings with OpenTelemetry tracing.
|
||||
/// </summary>
|
||||
/// <param name="settings">The WireMockServerSettings</param>
|
||||
/// <param name="openTelemetryOptions">The OpenTelemetry options for exporting traces.</param>
|
||||
[PublicAPI]
|
||||
public static WireMockServer Start(WireMockServerSettings settings, OpenTelemetryOptions? openTelemetryOptions)
|
||||
{
|
||||
Guard.NotNull(settings);
|
||||
|
||||
// Wire up OpenTelemetry OTLP exporter if options are provided
|
||||
if (openTelemetryOptions is not null)
|
||||
{
|
||||
// Enable activity tracing in settings so middleware creates activities
|
||||
// Only set ExcludeAdminRequests if not already configured
|
||||
settings.ActivityTracingOptions ??= new ActivityTracingOptions
|
||||
{
|
||||
ExcludeAdminRequests = openTelemetryOptions.ExcludeAdminRequests
|
||||
};
|
||||
|
||||
var existingRegistration = settings.AdditionalServiceRegistration;
|
||||
settings.AdditionalServiceRegistration = services =>
|
||||
{
|
||||
existingRegistration?.Invoke(services);
|
||||
services.AddWireMockOpenTelemetry(openTelemetryOptions);
|
||||
};
|
||||
}
|
||||
|
||||
return Start(settings);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Start WireMock.Net standalone Server based on the commandline arguments.
|
||||
/// </summary>
|
||||
@@ -71,7 +107,13 @@ public static class StandAloneApp
|
||||
settings.Logger?.Info("Version [{0}]", Version);
|
||||
settings.Logger?.Debug("Server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
||||
|
||||
#if OPENTELEMETRY_SUPPORTED
|
||||
// Parse OpenTelemetry options separately using the OTEL project parser
|
||||
OpenTelemetryOptionsParser.TryParseArguments(args, Environment.GetEnvironmentVariables(), out var openTelemetryOptions);
|
||||
server = Start(settings, openTelemetryOptions);
|
||||
#else
|
||||
server = Start(settings);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,12 @@
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<!-- Enable OpenTelemetry exporter support for .NET 6+ -->
|
||||
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' or '$(TargetFramework)' == 'net8.0'">
|
||||
<DefineConstants>$(DefineConstants);OPENTELEMETRY_SUPPORTED</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Nullable" Version="1.3.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
@@ -38,4 +44,9 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- OpenTelemetry exporter for .NET 6+ -->
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' or '$(TargetFramework)' == 'net8.0'">
|
||||
<ProjectReference Include="..\WireMock.Net.OpenTelemetry\WireMock.Net.OpenTelemetry.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user