Skip to content

Commit

Permalink
use object instead of string as config in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspimentel committed Jun 18, 2024
1 parent 77ee92e commit 318055f
Showing 1 changed file with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,21 @@ public void SetSamplingRules()
// sampling rules is null by default
TracerManager.Instance.Settings.RemoteSamplingRules.Should().BeNull();

var traceSampler = TracerManager.Instance.PerTraceSettings.TraceSampler as TraceSampler;
traceSampler!.GetRules().Should().ContainSingle().And.AllBeOfType<AgentSamplingRule>();

const string samplingRulesJson = """
[{
"sample_rate": 0.5,
"provenance": "customer",
"service": "Service1",
"resource": "Resource1"
},
{
"sample_rate": 0.1,
"provenance": "dynamic",
"service": "Service2",
"resource": "Resource2"
}]
""";
var singleAgentRuleOnly = ((TraceSampler)TracerManager.Instance.PerTraceSettings.TraceSampler)!.GetRules();
singleAgentRuleOnly.Should().ContainSingle().And.AllBeOfType<AgentSamplingRule>();

var samplingRulesConfig = new[]
{
new { sample_rate = 0.5, provenance = "customer", service = "Service1", resource = "Resource1", },
new { sample_rate = 0.1, provenance = "dynamic", service = "Service2", resource = "Resource2", }
};

var samplingRulesJson = JsonConvert.SerializeObject(samplingRulesConfig);

// set sampling rules "remotely"
DynamicConfigurationManager.OnlyForTests_ApplyConfiguration(CreateConfig(("tracing_sampling_rules", samplingRulesJson)));
DynamicConfigurationManager.OnlyForTests_ApplyConfiguration(CreateConfig(("tracing_sampling_rules", samplingRulesConfig)));
TracerManager.Instance.Settings.RemoteSamplingRules.Should().Be(samplingRulesJson);

traceSampler = TracerManager.Instance.PerTraceSettings.TraceSampler as TraceSampler;
var rules = traceSampler!.GetRules();
var rules = ((TraceSampler)TracerManager.Instance.PerTraceSettings.TraceSampler)!.GetRules();

rules.Should()
.BeEquivalentTo(
Expand Down

0 comments on commit 318055f

Please sign in to comment.