From 8dcaba7937a4e228d0e67e523e21a241d8d7c4be Mon Sep 17 00:00:00 2001 From: jjllee Date: Tue, 6 Feb 2024 09:47:31 -0800 Subject: [PATCH] fix sampling_rule default values --- .../opentelemetry/distro/sampler/_sampling_rule.py | 9 +++++---- .../distro/sampler/test_aws_xray_sampling_client.py | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/sampler/_sampling_rule.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/sampler/_sampling_rule.py index 40b463934..fe8f4f60b 100644 --- a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/sampler/_sampling_rule.py +++ b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/sampler/_sampling_rule.py @@ -22,15 +22,16 @@ def __init__( Version=None, ): self.Attributes = Attributes if Attributes is not None else {} - self.FixedRate = FixedRate if FixedRate is not None else "" + self.FixedRate = FixedRate if FixedRate is not None else 0.0 self.HTTPMethod = HTTPMethod if HTTPMethod is not None else "" self.Host = Host if Host is not None else "" - self.Priority = Priority if Priority is not None else "" - self.ReservoirSize = ReservoirSize if ReservoirSize is not None else "" + # Default to value with lower priority than default rule + self.Priority = Priority if Priority is not None else 10001 + self.ReservoirSize = ReservoirSize if ReservoirSize is not None else 0 self.ResourceARN = ResourceARN if ResourceARN is not None else "" self.RuleARN = RuleARN if RuleARN is not None else "" self.RuleName = RuleName if RuleName is not None else "" self.ServiceName = ServiceName if ServiceName is not None else "" self.ServiceType = ServiceType if ServiceType is not None else "" self.URLPath = URLPath if URLPath is not None else "" - self.Version = Version if Version is not None else "" + self.Version = Version if Version is not None else 0 diff --git a/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/sampler/test_aws_xray_sampling_client.py b/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/sampler/test_aws_xray_sampling_client.py index bff47599a..637e4545a 100644 --- a/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/sampler/test_aws_xray_sampling_client.py +++ b/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/sampler/test_aws_xray_sampling_client.py @@ -48,18 +48,18 @@ def test_default_values_used_when_missing_properties_in_sampling_rule(self, mock sampling_rule = sampling_rules[0] self.assertEqual(sampling_rule.Attributes, {}) - self.assertEqual(sampling_rule.FixedRate, "") + self.assertEqual(sampling_rule.FixedRate, 0.0) self.assertEqual(sampling_rule.HTTPMethod, "") self.assertEqual(sampling_rule.Host, "") - self.assertEqual(sampling_rule.Priority, "") - self.assertEqual(sampling_rule.ReservoirSize, "") + self.assertEqual(sampling_rule.Priority, 10001) + self.assertEqual(sampling_rule.ReservoirSize, 0) self.assertEqual(sampling_rule.ResourceARN, "") self.assertEqual(sampling_rule.RuleARN, "") self.assertEqual(sampling_rule.RuleName, "") self.assertEqual(sampling_rule.ServiceName, "") self.assertEqual(sampling_rule.ServiceType, "") self.assertEqual(sampling_rule.URLPath, "") - self.assertEqual(sampling_rule.Version, "") + self.assertEqual(sampling_rule.Version, 0) @patch("requests.post") def test_get_three_sampling_rules(self, mock_post=None):