@@ -20,6 +20,7 @@ namespace OpenTelemetry.Instrumentation.ServiceFabricRemoting;
2020public sealed class TraceContextEnrichedServiceRemotingProviderAttribute : FabricTransportServiceRemotingProviderAttribute
2121{
2222 private const string DefaultV2listenerName = "V2Listener" ;
23+ private const string DefaultTransportSettingsSectionName = "TransportSettings" ;
2324
2425 /// <summary>
2526 /// Initializes a new instance of the <see cref="TraceContextEnrichedServiceRemotingProviderAttribute"/> class.
@@ -30,6 +31,10 @@ public TraceContextEnrichedServiceRemotingProviderAttribute()
3031 this . RemotingListenerVersion = RemotingListenerVersion . V2 ;
3132 }
3233
34+ internal static Func < FabricTransportRemotingSettings ? > RemotingSettingsLoader { get ; set ; } = LoadRemotingSettings ;
35+
36+ internal static Func < FabricTransportRemotingListenerSettings ? > ListenerSettingsLoader { get ; set ; } = LoadListenerSettings ;
37+
3338 /// <summary>
3439 /// Creates a V2 service remoting listener for remoting the service interface.
3540 /// </summary>
@@ -66,11 +71,7 @@ public override Dictionary<string, Func<ServiceContext, IService, IServiceRemoti
6671 /// </returns>
6772 public override IServiceRemotingClientFactory CreateServiceRemotingClientFactoryV2 ( IServiceRemotingCallbackMessageHandler ? callbackMessageHandler )
6873 {
69- var fabricTransportRemotingSettings = new FabricTransportRemotingSettings ( ) ;
70- fabricTransportRemotingSettings . MaxMessageSize = this . GetAndValidateMaxMessageSize ( fabricTransportRemotingSettings . MaxMessageSize ) ;
71- fabricTransportRemotingSettings . OperationTimeout = this . GetAndValidateOperationTimeout ( fabricTransportRemotingSettings . OperationTimeout ) ;
72- fabricTransportRemotingSettings . KeepAliveTimeout = this . GetAndValidateKeepAliveTimeout ( fabricTransportRemotingSettings . KeepAliveTimeout ) ;
73- fabricTransportRemotingSettings . ConnectTimeout = this . GetConnectTimeout ( fabricTransportRemotingSettings . ConnectTimeout ) ;
74+ var fabricTransportRemotingSettings = this . GetRemotingSettings ( ) ;
7475
7576 var fabricTransportServiceRemotingClientFactory = new FabricTransportServiceRemotingClientFactory (
7677 fabricTransportRemotingSettings ,
@@ -82,15 +83,56 @@ public override IServiceRemotingClientFactory CreateServiceRemotingClientFactory
8283 return new TraceContextEnrichedServiceRemotingClientFactoryAdapter ( fabricTransportServiceRemotingClientFactory ) ;
8384 }
8485
85- private FabricTransportRemotingListenerSettings GetListenerSettings ( )
86+ internal FabricTransportRemotingListenerSettings GetListenerSettings ( )
87+ {
88+ var settings = ListenerSettingsLoader ( ) ?? new FabricTransportRemotingListenerSettings ( ) ;
89+
90+ settings . MaxMessageSize = this . GetAndValidateMaxMessageSize ( settings . MaxMessageSize ) ;
91+ settings . OperationTimeout = this . GetAndValidateOperationTimeout ( settings . OperationTimeout ) ;
92+ settings . KeepAliveTimeout = this . GetAndValidateKeepAliveTimeout ( settings . KeepAliveTimeout ) ;
93+
94+ return settings ;
95+ }
96+
97+ internal FabricTransportRemotingSettings GetRemotingSettings ( )
8698 {
87- var listenerSettings = new FabricTransportRemotingListenerSettings ( ) ;
99+ var settings = RemotingSettingsLoader ( ) ?? new FabricTransportRemotingSettings ( ) ;
88100
89- listenerSettings . MaxMessageSize = this . GetAndValidateMaxMessageSize ( listenerSettings . MaxMessageSize ) ;
90- listenerSettings . OperationTimeout = this . GetAndValidateOperationTimeout ( listenerSettings . OperationTimeout ) ;
91- listenerSettings . KeepAliveTimeout = this . GetAndValidateKeepAliveTimeout ( listenerSettings . KeepAliveTimeout ) ;
101+ settings . MaxMessageSize = this . GetAndValidateMaxMessageSize ( settings . MaxMessageSize ) ;
102+ settings . OperationTimeout = this . GetAndValidateOperationTimeout ( settings . OperationTimeout ) ;
103+ settings . KeepAliveTimeout = this . GetAndValidateKeepAliveTimeout ( settings . KeepAliveTimeout ) ;
104+ settings . ConnectTimeout = this . GetConnectTimeout ( settings . ConnectTimeout ) ;
92105
93- return listenerSettings ;
106+ return settings ;
107+ }
108+
109+ private static FabricTransportRemotingSettings ? LoadRemotingSettings ( ) =>
110+ TryLoadSettings ( ( ) =>
111+ FabricTransportRemotingSettings . TryLoadFrom ( DefaultTransportSettingsSectionName , out var settings , filepath : null , configPackageName : null )
112+ ? settings
113+ : null ) ;
114+
115+ private static FabricTransportRemotingListenerSettings ? LoadListenerSettings ( ) =>
116+ TryLoadSettings ( ( ) =>
117+ FabricTransportRemotingListenerSettings . TryLoadFrom ( DefaultTransportSettingsSectionName , out var settings , configPackageName : null )
118+ ? settings
119+ : null ) ;
120+
121+ private static T ? TryLoadSettings < T > ( Func < T ? > loader )
122+ where T : class
123+ {
124+ try
125+ {
126+ return loader ( ) ;
127+ }
128+ catch ( DllNotFoundException )
129+ {
130+ return null ;
131+ }
132+ catch ( TypeInitializationException ex ) when ( ex . InnerException is DllNotFoundException )
133+ {
134+ return null ;
135+ }
94136 }
95137
96138 private long GetAndValidateMaxMessageSize ( long maxMessageSizeDefault )
0 commit comments