@@ -87,6 +87,11 @@ public class Configuration
87
87
/// </summary>
88
88
public const string JaegerSamplerManagerHostPort = JaegerPrefix + "SAMPLER_MANAGER_HOST_PORT" ;
89
89
90
+ /// <summary>
91
+ /// The url for the remote sampling conf when using sampler type remote.
92
+ /// </summary>
93
+ public const string JaegerSamplingEndpoint = JaegerPrefix + "SAMPLING_ENDPOINT" ;
94
+
90
95
/// <summary>
91
96
/// The service name.
92
97
/// </summary>
@@ -161,7 +166,7 @@ public static Configuration FromIConfiguration(ILoggerFactory loggerFactory, ICo
161
166
{
162
167
ILogger logger = loggerFactory . CreateLogger < Configuration > ( ) ;
163
168
164
- return new Configuration ( GetProperty ( JaegerServiceName , configuration ) , loggerFactory )
169
+ return new Configuration ( GetProperty ( JaegerServiceName , logger , configuration ) , loggerFactory )
165
170
. WithTracerTags ( TracerTagsFromIConfiguration ( logger , configuration ) )
166
171
. WithTraceId128Bit ( GetPropertyAsBool ( JaegerTraceId128Bit , logger , configuration ) . GetValueOrDefault ( false ) )
167
172
. WithReporter ( ReporterConfiguration . FromIConfiguration ( loggerFactory , configuration ) )
@@ -312,10 +317,16 @@ public class SamplerConfiguration
312
317
313
318
/// <summary>
314
319
/// HTTP host:port of the sampling manager that can provide sampling strategy to this service.
315
- /// Optional.
316
320
/// </summary>
321
+ [ Obsolete ( "Please use SamplingEndpoint instead!" ) ]
317
322
public string ManagerHostPort { get ; private set ; }
318
323
324
+ /// <summary>
325
+ /// The URL of the sampling manager that can provide sampling strategy to this service.
326
+ /// Optional.
327
+ /// </summary>
328
+ public string SamplingEndpoint { get ; private set ; }
329
+
319
330
public SamplerConfiguration ( ILoggerFactory loggerFactory )
320
331
{
321
332
_loggerFactory = loggerFactory ;
@@ -327,11 +338,14 @@ public SamplerConfiguration(ILoggerFactory loggerFactory)
327
338
public static SamplerConfiguration FromIConfiguration ( ILoggerFactory loggerFactory , IConfiguration configuration )
328
339
{
329
340
ILogger logger = loggerFactory . CreateLogger < Configuration > ( ) ;
330
-
341
+
342
+ #pragma warning disable CS0618 // Supress warning on obsolete method: WithManagerHostPort
331
343
return new SamplerConfiguration ( loggerFactory )
332
- . WithType ( GetProperty ( JaegerSamplerType , configuration ) )
344
+ . WithType ( GetProperty ( JaegerSamplerType , logger , configuration ) )
333
345
. WithParam ( GetPropertyAsDouble ( JaegerSamplerParam , logger , configuration ) )
334
- . WithManagerHostPort ( GetProperty ( JaegerSamplerManagerHostPort , configuration ) ) ;
346
+ . WithManagerHostPort ( GetProperty ( JaegerSamplerManagerHostPort , logger , configuration , JaegerSamplingEndpoint ) )
347
+ . WithSamplingEndpoint ( GetProperty ( JaegerSamplingEndpoint , logger , configuration ) ) ;
348
+ #pragma warning restore CS0618 // Supress warning on obsolete method: WithManagerHostPort
335
349
}
336
350
337
351
/// <summary>
@@ -347,9 +361,12 @@ public static SamplerConfiguration FromEnv(ILoggerFactory loggerFactory)
347
361
348
362
public virtual ISampler GetSampler ( string serviceName , IMetrics metrics )
349
363
{
364
+ #pragma warning disable CS0618 // Supress warning on obsolete property: ManagerHostPort
350
365
string samplerType = StringOrDefault ( Type , RemoteControlledSampler . Type ) ;
351
366
double samplerParam = Param . GetValueOrDefault ( ProbabilisticSampler . DefaultSamplingProbability ) ;
352
367
string hostPort = StringOrDefault ( ManagerHostPort , HttpSamplingManager . DefaultHostPort ) ;
368
+ string samplingEndpoint = StringOrDefault ( SamplingEndpoint , "http://" + hostPort ) ;
369
+ #pragma warning disable CS0618 // Supress warning on obsolete property: ManagerHostPort
353
370
354
371
switch ( samplerType )
355
372
{
@@ -362,7 +379,7 @@ public virtual ISampler GetSampler(string serviceName, IMetrics metrics)
362
379
case RemoteControlledSampler . Type :
363
380
return new RemoteControlledSampler . Builder ( serviceName )
364
381
. WithLoggerFactory ( _loggerFactory )
365
- . WithSamplingManager ( new HttpSamplingManager ( hostPort ) )
382
+ . WithSamplingManager ( new HttpSamplingManager ( samplingEndpoint ) )
366
383
. WithInitialSampler ( new ProbabilisticSampler ( samplerParam ) )
367
384
. WithMetrics ( metrics )
368
385
. Build ( ) ;
@@ -383,11 +400,18 @@ public SamplerConfiguration WithParam(double? param)
383
400
return this ;
384
401
}
385
402
403
+ [ Obsolete ( "Use WithSamplingEndpoint instead!" ) ]
386
404
public SamplerConfiguration WithManagerHostPort ( string managerHostPort )
387
405
{
388
406
ManagerHostPort = managerHostPort ;
389
407
return this ;
390
408
}
409
+
410
+ public SamplerConfiguration WithSamplingEndpoint ( string samplingEndpoint )
411
+ {
412
+ SamplingEndpoint = samplingEndpoint ;
413
+ return this ;
414
+ }
391
415
}
392
416
393
417
/// <summary>
@@ -412,7 +436,7 @@ public static CodecConfiguration FromIConfiguration(ILoggerFactory loggerFactory
412
436
ILogger logger = loggerFactory . CreateLogger < Configuration > ( ) ;
413
437
414
438
CodecConfiguration codecConfiguration = new CodecConfiguration ( loggerFactory ) ;
415
- string propagation = GetProperty ( JaegerPropagation , configuration ) ;
439
+ string propagation = GetProperty ( JaegerPropagation , logger , configuration ) ;
416
440
if ( propagation != null )
417
441
{
418
442
foreach ( string format in propagation . Split ( ',' ) )
@@ -706,13 +730,13 @@ public static SenderConfiguration FromIConfiguration(ILoggerFactory loggerFactor
706
730
{
707
731
ILogger logger = loggerFactory . CreateLogger < Configuration > ( ) ;
708
732
709
- string agentHost = GetProperty ( JaegerAgentHost , configuration ) ;
733
+ string agentHost = GetProperty ( JaegerAgentHost , logger , configuration ) ;
710
734
int ? agentPort = GetPropertyAsInt ( JaegerAgentPort , logger , configuration ) ;
711
735
712
- string collectorEndpoint = GetProperty ( JaegerEndpoint , configuration ) ;
713
- string authToken = GetProperty ( JaegerAuthToken , configuration ) ;
714
- string authUsername = GetProperty ( JaegerUser , configuration ) ;
715
- string authPassword = GetProperty ( JaegerPassword , configuration ) ;
736
+ string collectorEndpoint = GetProperty ( JaegerEndpoint , logger , configuration ) ;
737
+ string authToken = GetProperty ( JaegerAuthToken , logger , configuration ) ;
738
+ string authUsername = GetProperty ( JaegerUser , logger , configuration ) ;
739
+ string authPassword = GetProperty ( JaegerPassword , logger , configuration ) ;
716
740
717
741
return new SenderConfiguration ( loggerFactory )
718
742
. WithAgentHost ( agentHost )
@@ -740,14 +764,20 @@ private static string StringOrDefault(string value, string defaultValue)
740
764
return value != null && value . Length > 0 ? value : defaultValue ;
741
765
}
742
766
743
- private static string GetProperty ( string name , IConfiguration configuration )
767
+ private static string GetProperty ( string name , ILogger logger , IConfiguration configuration , string replacedBy = null )
744
768
{
745
- return configuration [ name ] ;
769
+ var value = configuration [ name ] ;
770
+ if ( replacedBy != null && value != null )
771
+ {
772
+ logger . LogWarning ( $ "The entry { name } is obsolete. Use { replacedBy } instead!") ;
773
+ }
774
+
775
+ return value ;
746
776
}
747
777
748
778
private static int ? GetPropertyAsInt ( string name , ILogger logger , IConfiguration configuration )
749
779
{
750
- string value = GetProperty ( name , configuration ) ;
780
+ string value = GetProperty ( name , logger , configuration ) ;
751
781
if ( ! string . IsNullOrEmpty ( value ) )
752
782
{
753
783
if ( int . TryParse ( value , NumberStyles . Integer , CultureInfo . InvariantCulture , out int intValue ) )
@@ -764,7 +794,7 @@ private static string GetProperty(string name, IConfiguration configuration)
764
794
765
795
private static double ? GetPropertyAsDouble ( string name , ILogger logger , IConfiguration configuration )
766
796
{
767
- string value = GetProperty ( name , configuration ) ;
797
+ string value = GetProperty ( name , logger , configuration ) ;
768
798
if ( ! string . IsNullOrEmpty ( value ) )
769
799
{
770
800
if ( double . TryParse ( value , NumberStyles . Float , CultureInfo . InvariantCulture , out double doubleValue ) )
@@ -795,7 +825,7 @@ private static string GetProperty(string name, IConfiguration configuration)
795
825
/// </summary>
796
826
private static bool ? GetPropertyAsBool ( string name , ILogger logger , IConfiguration configuration )
797
827
{
798
- string value = GetProperty ( name , configuration ) ;
828
+ string value = GetProperty ( name , logger , configuration ) ;
799
829
if ( ! string . IsNullOrEmpty ( value ) )
800
830
{
801
831
if ( string . Equals ( value , "1" , StringComparison . Ordinal ) )
@@ -822,7 +852,7 @@ private static string GetProperty(string name, IConfiguration configuration)
822
852
private static Dictionary < string , string > TracerTagsFromIConfiguration ( ILogger logger , IConfiguration configuration )
823
853
{
824
854
Dictionary < string , string > tracerTagMaps = null ;
825
- string tracerTags = GetProperty ( JaegerTags , configuration ) ;
855
+ string tracerTags = GetProperty ( JaegerTags , logger , configuration ) ;
826
856
if ( ! string . IsNullOrEmpty ( tracerTags ) )
827
857
{
828
858
string [ ] tags = tracerTags . Split ( ',' ) ;
@@ -835,7 +865,7 @@ private static Dictionary<string, string> TracerTagsFromIConfiguration(ILogger l
835
865
{
836
866
tracerTagMaps = new Dictionary < string , string > ( ) ;
837
867
}
838
- tracerTagMaps [ tagValue [ 0 ] . Trim ( ) ] = ResolveValue ( tagValue [ 1 ] . Trim ( ) , configuration ) ;
868
+ tracerTagMaps [ tagValue [ 0 ] . Trim ( ) ] = ResolveValue ( tagValue [ 1 ] . Trim ( ) , logger , configuration ) ;
839
869
}
840
870
else
841
871
{
@@ -846,14 +876,14 @@ private static Dictionary<string, string> TracerTagsFromIConfiguration(ILogger l
846
876
return tracerTagMaps ;
847
877
}
848
878
849
- private static string ResolveValue ( string value , IConfiguration configuration )
879
+ private static string ResolveValue ( string value , ILogger logger , IConfiguration configuration )
850
880
{
851
881
if ( value . StartsWith ( "${" ) && value . EndsWith ( "}" ) )
852
882
{
853
883
string [ ] kvp = value . Substring ( 2 , value . Length - 3 ) . Split ( ':' ) ;
854
884
if ( kvp . Length > 0 )
855
885
{
856
- string propertyValue = GetProperty ( kvp [ 0 ] . Trim ( ) , configuration ) ;
886
+ string propertyValue = GetProperty ( kvp [ 0 ] . Trim ( ) , logger , configuration ) ;
857
887
if ( propertyValue == null && kvp . Length > 1 )
858
888
{
859
889
propertyValue = kvp [ 1 ] . Trim ( ) ;
0 commit comments