Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* Updated OpenTelemetry core component version(s) to `1.15.2`.
([#4080](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4080))

* Ensure that `TransportSettings` configuration is applied to created
instances of `IServiceRemotingClientFactory`.
([#TODO](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/TODO))
Comment thread
martincostello marked this conversation as resolved.
Resolved

## 1.15.0-beta.1

Released 2026-Jan-21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace OpenTelemetry.Instrumentation.ServiceFabricRemoting;
public sealed class TraceContextEnrichedServiceRemotingProviderAttribute : FabricTransportServiceRemotingProviderAttribute
{
private const string DefaultV2listenerName = "V2Listener";
private const string DefaultTransportSettingsSectionName = "TransportSettings";

/// <summary>
/// Initializes a new instance of the <see cref="TraceContextEnrichedServiceRemotingProviderAttribute"/> class.
Expand All @@ -30,6 +31,10 @@ public TraceContextEnrichedServiceRemotingProviderAttribute()
this.RemotingListenerVersion = RemotingListenerVersion.V2;
}

internal static Func<FabricTransportRemotingSettings?> RemotingSettingsLoader { get; set; } = LoadRemotingSettings;

internal static Func<FabricTransportRemotingListenerSettings?> ListenerSettingsLoader { get; set; } = LoadListenerSettings;

/// <summary>
/// Creates a V2 service remoting listener for remoting the service interface.
/// </summary>
Expand Down Expand Up @@ -66,11 +71,7 @@ public override Dictionary<string, Func<ServiceContext, IService, IServiceRemoti
/// </returns>
public override IServiceRemotingClientFactory CreateServiceRemotingClientFactoryV2(IServiceRemotingCallbackMessageHandler? callbackMessageHandler)
{
var fabricTransportRemotingSettings = new FabricTransportRemotingSettings();
fabricTransportRemotingSettings.MaxMessageSize = this.GetAndValidateMaxMessageSize(fabricTransportRemotingSettings.MaxMessageSize);
fabricTransportRemotingSettings.OperationTimeout = this.GetAndValidateOperationTimeout(fabricTransportRemotingSettings.OperationTimeout);
fabricTransportRemotingSettings.KeepAliveTimeout = this.GetAndValidateKeepAliveTimeout(fabricTransportRemotingSettings.KeepAliveTimeout);
fabricTransportRemotingSettings.ConnectTimeout = this.GetConnectTimeout(fabricTransportRemotingSettings.ConnectTimeout);
var fabricTransportRemotingSettings = this.GetRemotingSettings();

var fabricTransportServiceRemotingClientFactory = new FabricTransportServiceRemotingClientFactory(
fabricTransportRemotingSettings,
Expand All @@ -82,15 +83,56 @@ public override IServiceRemotingClientFactory CreateServiceRemotingClientFactory
return new TraceContextEnrichedServiceRemotingClientFactoryAdapter(fabricTransportServiceRemotingClientFactory);
}

private FabricTransportRemotingListenerSettings GetListenerSettings()
internal FabricTransportRemotingListenerSettings GetListenerSettings()
{
var settings = ListenerSettingsLoader() ?? new FabricTransportRemotingListenerSettings();

settings.MaxMessageSize = this.GetAndValidateMaxMessageSize(settings.MaxMessageSize);
settings.OperationTimeout = this.GetAndValidateOperationTimeout(settings.OperationTimeout);
settings.KeepAliveTimeout = this.GetAndValidateKeepAliveTimeout(settings.KeepAliveTimeout);

return settings;
}

internal FabricTransportRemotingSettings GetRemotingSettings()
{
var listenerSettings = new FabricTransportRemotingListenerSettings();
var settings = RemotingSettingsLoader() ?? new FabricTransportRemotingSettings();

listenerSettings.MaxMessageSize = this.GetAndValidateMaxMessageSize(listenerSettings.MaxMessageSize);
listenerSettings.OperationTimeout = this.GetAndValidateOperationTimeout(listenerSettings.OperationTimeout);
listenerSettings.KeepAliveTimeout = this.GetAndValidateKeepAliveTimeout(listenerSettings.KeepAliveTimeout);
settings.MaxMessageSize = this.GetAndValidateMaxMessageSize(settings.MaxMessageSize);
settings.OperationTimeout = this.GetAndValidateOperationTimeout(settings.OperationTimeout);
settings.KeepAliveTimeout = this.GetAndValidateKeepAliveTimeout(settings.KeepAliveTimeout);
settings.ConnectTimeout = this.GetConnectTimeout(settings.ConnectTimeout);

return listenerSettings;
return settings;
}

private static FabricTransportRemotingSettings? LoadRemotingSettings() =>
TryLoadSettings(() =>
FabricTransportRemotingSettings.TryLoadFrom(DefaultTransportSettingsSectionName, out var settings, filepath: null, configPackageName: null)
? settings
: null);

private static FabricTransportRemotingListenerSettings? LoadListenerSettings() =>
TryLoadSettings(() =>
FabricTransportRemotingListenerSettings.TryLoadFrom(DefaultTransportSettingsSectionName, out var settings, configPackageName: null)
? settings
: null);

private static T? TryLoadSettings<T>(Func<T?> loader)
where T : class
{
try
{
return loader();
}
catch (DllNotFoundException)
{
return null;
}
catch (TypeInitializationException ex) when (ex.InnerException is DllNotFoundException)
{
return null;
}
}

private long GetAndValidateMaxMessageSize(long maxMessageSizeDefault)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<ProjectReference Include="..\..\src\OpenTelemetry.Instrumentation.ServiceFabricRemoting\OpenTelemetry.Instrumentation.ServiceFabricRemoting.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\src\Shared\Lock.cs" Link="Includes\Lock.cs" />
</ItemGroup>

<ItemGroup>
<!-- Include must be the fully qualified .NET type name of the Attribute to create. -->
<AssemblyAttribute Include="OpenTelemetry.Instrumentation.ServiceFabricRemoting.TraceContextEnrichedServiceRemotingProviderAttribute" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;
using System.Fabric;
using System.Text;
using Microsoft.ServiceFabric.Actors;
using Microsoft.ServiceFabric.Actors.Runtime;
using Microsoft.ServiceFabric.Services.Remoting.FabricTransport;
using Microsoft.ServiceFabric.Services.Remoting.FabricTransport.Runtime;
using Microsoft.ServiceFabric.Services.Remoting.V2;
using Microsoft.ServiceFabric.Services.Remoting.V2.Runtime;
using OpenTelemetry.Context.Propagation;
Expand All @@ -22,6 +25,7 @@ public class ServiceFabricRemotingTests
private const string BaggageKey = "SomeBaggageKey";
private const string BaggageValue = "SomeBaggageValue";
private static readonly ActivitySource ActivitySource = new("ServiceFabricRemotingTests");
private static readonly Lock TransportSettingsLock = new();
Comment thread
martincostello marked this conversation as resolved.
Resolved

[Fact]
public async Task TestStatefulServiceContextPropagation_ShouldExtractActivityContextAndBaggage()
Expand Down Expand Up @@ -144,6 +148,74 @@ public async Task TestServiceRemotingClientContextPropagation_ShouldInjectActivi
Assert.Equal(BaggageValue, propagationContext.Baggage.GetBaggage(BaggageKey));
}

[Fact]
public void ServiceRemotingProviderListenerSettings_LoadConfiguredTransportDefaults()
{
lock (TransportSettingsLock)
{
var originalLoader = TraceContextEnrichedServiceRemotingProviderAttribute.ListenerSettingsLoader;

try
{
TraceContextEnrichedServiceRemotingProviderAttribute.ListenerSettingsLoader = () => new FabricTransportRemotingListenerSettings
{
MaxQueueSize = 35,
SecurityCredentials = new X509Credentials(),
};

var provider = new TraceContextEnrichedServiceRemotingProviderAttribute
{
MaxMessageSize = 17,
};

var actual = provider.GetListenerSettings();

Assert.Equal(35, actual.MaxQueueSize);
Assert.Equal(CredentialType.X509, actual.SecurityCredentials.CredentialType);
Assert.Equal(17, actual.MaxMessageSize);
}
finally
{
TraceContextEnrichedServiceRemotingProviderAttribute.ListenerSettingsLoader = originalLoader;
}
}
}

[Fact]
public void ServiceRemotingProviderClientFactory_LoadsConfiguredTransportDefaults()
Comment thread
martincostello marked this conversation as resolved.
Resolved
Comment thread
martincostello marked this conversation as resolved.
Resolved
{
lock (TransportSettingsLock)
{
var originalLoader = TraceContextEnrichedServiceRemotingProviderAttribute.RemotingSettingsLoader;

try
{
TraceContextEnrichedServiceRemotingProviderAttribute.RemotingSettingsLoader = () => new FabricTransportRemotingSettings
{
MaxQueueSize = 35,
ConnectTimeout = TimeSpan.FromMilliseconds(7),
SecurityCredentials = new X509Credentials(),
};

var provider = new TraceContextEnrichedServiceRemotingProviderAttribute
{
MaxMessageSize = 17,
};

var actual = provider.GetRemotingSettings();

Assert.Equal(35, actual.MaxQueueSize);
Assert.Equal(CredentialType.X509, actual.SecurityCredentials.CredentialType);
Assert.Equal(TimeSpan.FromMilliseconds(7), actual.ConnectTimeout);
Assert.Equal(17, actual.MaxMessageSize);
}
finally
{
TraceContextEnrichedServiceRemotingProviderAttribute.RemotingSettingsLoader = originalLoader;
}
}
}

private ServiceRemotingRequestMessageHeaderMock CreateServiceRemotingRequestMessageHeader(Type interfaceType, string methodName)
{
var interfaceId = ServiceFabricUtils.GetInterfaceId(interfaceType);
Expand Down
Loading