Skip to content

Commit 22afe4b

Browse files
committed
make sampler implementation internal until completion, update tests to not make http requests
1 parent 95baa3c commit 22afe4b

File tree

5 files changed

+70
-39
lines changed

5 files changed

+70
-39
lines changed

sdk-extension/opentelemetry-sdk-extension-aws/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ Refer to each detectors' docstring to determine any possible requirements for th
7575
detector.
7676

7777

78-
Usage (AWS X-Ray Remote Sampler)
79-
--------------------------------
78+
[WORK IN PROGRESS] Usage (AWS X-Ray Remote Sampler)
79+
---------------------------------------------------
8080

8181

8282
Use the provided AWS X-Ray Remote Sampler by setting this sampler in your instrumented application:

sdk-extension/opentelemetry-sdk-extension-aws/pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ aws_eks = "opentelemetry.sdk.extension.aws.resource.eks:AwsEksResourceDetector"
4242
aws_elastic_beanstalk = "opentelemetry.sdk.extension.aws.resource.beanstalk:AwsBeanstalkResourceDetector"
4343
aws_lambda = "opentelemetry.sdk.extension.aws.resource._lambda:AwsLambdaResourceDetector"
4444

45-
[project.entry-points.opentelemetry_sampler]
46-
aws_xray_remote_sampler = "opentelemetry.sdk.extension.aws.trace.sampler:AwsXRayRemoteSampler"
45+
# TODO: Uncomment this when Sampler implementation is complete
46+
# [project.entry-points.opentelemetry_sampler]
47+
# aws_xray_remote_sampler = "opentelemetry.sdk.extension.aws.trace.sampler:AwsXRayRemoteSampler"
4748

4849
[project.urls]
4950
Homepage = "https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/sdk-extension/opentelemetry-sdk-extension-aws"

sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/sampler/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# pylint: disable=no-name-in-module
1616
from opentelemetry.sdk.extension.aws.trace.sampler.aws_xray_remote_sampler import (
17-
AwsXRayRemoteSampler,
17+
_AwsXRayRemoteSampler,
1818
)
1919

20-
__all__ = ["AwsXRayRemoteSampler"]
20+
__all__ = ["_AwsXRayRemoteSampler"]

sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/sampler/aws_xray_remote_sampler.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747

4848

4949
# WORK IN PROGRESS
50+
# TODO: Rename to AwsXRayRemoteSampler when the implementation is complete and is ready to use
5051
#
51-
# Wrapper class to ensure that all XRay Sampler Functionality in _AwsXRayRemoteSampler
52+
# Wrapper class to ensure that all XRay Sampler Functionality in _InternalAwsXRayRemoteSampler
5253
# uses ParentBased logic to respect the parent span's sampling decision
53-
class AwsXRayRemoteSampler(Sampler):
54+
class _AwsXRayRemoteSampler(Sampler):
5455
def __init__(
5556
self,
5657
resource: Resource,
@@ -59,7 +60,7 @@ def __init__(
5960
log_level: Optional[str] = None,
6061
):
6162
self._root = ParentBased(
62-
_AwsXRayRemoteSampler(
63+
_InternalAwsXRayRemoteSampler(
6364
resource=resource,
6465
endpoint=endpoint,
6566
polling_interval=polling_interval,
@@ -96,10 +97,10 @@ def get_description(self) -> str:
9697

9798
# WORK IN PROGRESS
9899
#
99-
# _AwsXRayRemoteSampler contains all core XRay Sampler Functionality,
100+
# _InternalAwsXRayRemoteSampler contains all core XRay Sampler Functionality,
100101
# however it is NOT Parent-based (e.g. Sample logic runs for each span)
101102
# Not intended for external use, use Parent-based `AwsXRayRemoteSampler` instead.
102-
class _AwsXRayRemoteSampler(Sampler):
103+
class _InternalAwsXRayRemoteSampler(Sampler):
103104
"""
104105
Remote Sampler for OpenTelemetry that gets sampling configurations from AWS X-Ray
105106
@@ -180,7 +181,9 @@ def should_sample(
180181
# pylint: disable=no-self-use
181182
@override
182183
def get_description(self) -> str:
183-
description = "_AwsXRayRemoteSampler{remote sampling with AWS X-Ray}"
184+
description = (
185+
"_InternalAwsXRayRemoteSampler{remote sampling with AWS X-Ray}"
186+
)
184187
return description
185188

186189
def __get_and_update_sampling_rules(self) -> None:

sdk-extension/opentelemetry-sdk-extension-aws/tests/trace/sampler/test_aws_xray_remote_sampler.py

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
import os
2121
from logging import DEBUG
2222
from unittest import TestCase
23+
from unittest.mock import patch
2324

2425
# pylint: disable=no-name-in-module
2526
from opentelemetry.sdk.extension.aws.trace.sampler.aws_xray_remote_sampler import (
26-
AwsXRayRemoteSampler,
27+
_AwsXRayRemoteSampler,
2728
)
2829
from opentelemetry.sdk.resources import Resource
2930
from opentelemetry.sdk.trace.sampling import Decision
@@ -84,24 +85,38 @@ def tearDown(self):
8485
if self.rs is not None:
8586
self.rs._root._root._rules_timer.cancel()
8687

87-
def test_create_remote_sampler_with_empty_resource(self):
88-
self.rs = AwsXRayRemoteSampler(resource=Resource.get_empty())
88+
@patch(
89+
"opentelemetry.sdk.extension.aws.trace.sampler._aws_xray_sampling_client._AwsXRaySamplingClient.get_sampling_rules",
90+
return_value=None,
91+
)
92+
def test_create_remote_sampler_with_empty_resource(
93+
self, mocked_get_sampling_rules
94+
):
95+
self.rs = _AwsXRayRemoteSampler(resource=Resource.get_empty())
8996
self.assertIsNotNone(self.rs._root._root._rules_timer)
9097
self.assertEqual(
91-
self.rs._root._root._AwsXRayRemoteSampler__polling_interval, 300
98+
self.rs._root._root._InternalAwsXRayRemoteSampler__polling_interval,
99+
300,
92100
)
93101
self.assertIsNotNone(
94-
self.rs._root._root._AwsXRayRemoteSampler__xray_client
102+
self.rs._root._root._InternalAwsXRayRemoteSampler__xray_client
95103
)
96104
self.assertIsNotNone(
97-
self.rs._root._root._AwsXRayRemoteSampler__resource
105+
self.rs._root._root._InternalAwsXRayRemoteSampler__resource
98106
)
99107
self.assertTrue(
100-
len(self.rs._root._root._AwsXRayRemoteSampler__client_id), 24
101-
)
102-
103-
def test_create_remote_sampler_with_populated_resource(self):
104-
self.rs = AwsXRayRemoteSampler(
108+
len(self.rs._root._root._InternalAwsXRayRemoteSampler__client_id),
109+
24,
110+
)
111+
112+
@patch(
113+
"opentelemetry.sdk.extension.aws.trace.sampler._aws_xray_sampling_client._AwsXRaySamplingClient.get_sampling_rules",
114+
return_value=None,
115+
)
116+
def test_create_remote_sampler_with_populated_resource(
117+
self, mocked_get_sampling_rules
118+
):
119+
self.rs = _AwsXRayRemoteSampler(
105120
resource=Resource.create(
106121
{
107122
"service.name": "test-service-name",
@@ -111,29 +126,36 @@ def test_create_remote_sampler_with_populated_resource(self):
111126
)
112127
self.assertIsNotNone(self.rs._root._root._rules_timer)
113128
self.assertEqual(
114-
self.rs._root._root._AwsXRayRemoteSampler__polling_interval, 300
129+
self.rs._root._root._InternalAwsXRayRemoteSampler__polling_interval,
130+
300,
115131
)
116132
self.assertIsNotNone(
117-
self.rs._root._root._AwsXRayRemoteSampler__xray_client
133+
self.rs._root._root._InternalAwsXRayRemoteSampler__xray_client
118134
)
119135
self.assertIsNotNone(
120-
self.rs._root._root._AwsXRayRemoteSampler__resource
136+
self.rs._root._root._InternalAwsXRayRemoteSampler__resource
121137
)
122138
self.assertEqual(
123-
self.rs._root._root._AwsXRayRemoteSampler__resource.attributes[
139+
self.rs._root._root._InternalAwsXRayRemoteSampler__resource.attributes[
124140
"service.name"
125141
],
126142
"test-service-name",
127143
)
128144
self.assertEqual(
129-
self.rs._root._root._AwsXRayRemoteSampler__resource.attributes[
145+
self.rs._root._root._InternalAwsXRayRemoteSampler__resource.attributes[
130146
"cloud.platform"
131147
],
132148
"test-cloud-platform",
133149
)
134150

135-
def test_create_remote_sampler_with_all_fields_populated(self):
136-
self.rs = AwsXRayRemoteSampler(
151+
@patch(
152+
"opentelemetry.sdk.extension.aws.trace.sampler._aws_xray_sampling_client._AwsXRaySamplingClient.get_sampling_rules",
153+
return_value=None,
154+
)
155+
def test_create_remote_sampler_with_all_fields_populated(
156+
self, mocked_get_sampling_rules
157+
):
158+
self.rs = _AwsXRayRemoteSampler(
137159
resource=Resource.create(
138160
{
139161
"service.name": "test-service-name",
@@ -146,36 +168,41 @@ def test_create_remote_sampler_with_all_fields_populated(self):
146168
)
147169
self.assertIsNotNone(self.rs._root._root._rules_timer)
148170
self.assertEqual(
149-
self.rs._root._root._AwsXRayRemoteSampler__polling_interval, 120
171+
self.rs._root._root._InternalAwsXRayRemoteSampler__polling_interval,
172+
120,
150173
)
151174
self.assertIsNotNone(
152-
self.rs._root._root._AwsXRayRemoteSampler__xray_client
175+
self.rs._root._root._InternalAwsXRayRemoteSampler__xray_client
153176
)
154177
self.assertIsNotNone(
155-
self.rs._root._root._AwsXRayRemoteSampler__resource
178+
self.rs._root._root._InternalAwsXRayRemoteSampler__resource
156179
)
157180
self.assertEqual(
158-
self.rs._root._root._AwsXRayRemoteSampler__xray_client._AwsXRaySamplingClient__get_sampling_rules_endpoint,
181+
self.rs._root._root._InternalAwsXRayRemoteSampler__xray_client._AwsXRaySamplingClient__get_sampling_rules_endpoint,
159182
"http://abc.com/GetSamplingRules",
160183
)
161184
self.assertEqual(
162-
self.rs._root._root._AwsXRayRemoteSampler__resource.attributes[
185+
self.rs._root._root._InternalAwsXRayRemoteSampler__resource.attributes[
163186
"service.name"
164187
],
165188
"test-service-name",
166189
)
167190
self.assertEqual(
168-
self.rs._root._root._AwsXRayRemoteSampler__resource.attributes[
191+
self.rs._root._root._InternalAwsXRayRemoteSampler__resource.attributes[
169192
"cloud.platform"
170193
],
171194
"test-cloud-platform",
172195
)
173196

174-
def test_get_description(self) -> str:
175-
self.rs: AwsXRayRemoteSampler = AwsXRayRemoteSampler(
197+
@patch(
198+
"opentelemetry.sdk.extension.aws.trace.sampler._aws_xray_sampling_client._AwsXRaySamplingClient.get_sampling_rules",
199+
return_value=None,
200+
)
201+
def test_get_description(self, sdf) -> str:
202+
self.rs: _AwsXRayRemoteSampler = _AwsXRayRemoteSampler(
176203
resource=Resource.create({"service.name": "dummy_name"})
177204
)
178205
self.assertEqual(
179206
self.rs.get_description(),
180-
"AwsXRayRemoteSampler{root:ParentBased{root:_AwsXRayRemoteSampler{remote sampling with AWS X-Ray},remoteParentSampled:AlwaysOnSampler,remoteParentNotSampled:AlwaysOffSampler,localParentSampled:AlwaysOnSampler,localParentNotSampled:AlwaysOffSampler}}", # noqa: E501
207+
"AwsXRayRemoteSampler{root:ParentBased{root:_InternalAwsXRayRemoteSampler{remote sampling with AWS X-Ray},remoteParentSampled:AlwaysOnSampler,remoteParentNotSampled:AlwaysOffSampler,localParentSampled:AlwaysOnSampler,localParentNotSampled:AlwaysOffSampler}}", # noqa: E501
181208
)

0 commit comments

Comments
 (0)