@@ -66,9 +66,8 @@ def test_trace_id_ratio_sampler(self):
66
66
@patch .object (AwsXRayRemoteSampler , "_AwsXRayRemoteSampler__start_sampling_rule_poller" , lambda x : None )
67
67
@patch .object (AwsXRayRemoteSampler , "_AwsXRayRemoteSampler__start_sampling_target_poller" , lambda x : None )
68
68
def test_import_xray_sampler_without_environment_arguments (self ):
69
- os .environ .pop (OTEL_TRACES_SAMPLER_ARG )
69
+ os .environ .pop (OTEL_TRACES_SAMPLER_ARG , None )
70
70
71
- # May log http request error as xray sampler will attempt to fetch rules
72
71
xray_sampler : Sampler = _custom_import_sampler ("xray" , resource = None )
73
72
xray_client : _AwsXRaySamplingClient = xray_sampler ._AwsXRayRemoteSampler__xray_client
74
73
self .assertEqual (xray_sampler ._AwsXRayRemoteSampler__polling_interval , 300 )
@@ -79,32 +78,29 @@ def test_import_xray_sampler_without_environment_arguments(self):
79
78
@patch .object (AwsXRayRemoteSampler , "_AwsXRayRemoteSampler__start_sampling_rule_poller" , lambda x : None )
80
79
@patch .object (AwsXRayRemoteSampler , "_AwsXRayRemoteSampler__start_sampling_target_poller" , lambda x : None )
81
80
def test_import_xray_sampler_with_valid_environment_arguments (self ):
82
- os .environ .pop (OTEL_TRACES_SAMPLER_ARG )
81
+ os .environ .pop (OTEL_TRACES_SAMPLER_ARG , None )
83
82
os .environ .setdefault (OTEL_TRACES_SAMPLER_ARG , "endpoint=http://localhost:2000,polling_interval=600" )
84
83
85
- # May log http request error as xray sampler will attempt to fetch rules
86
84
xray_sampler : Sampler = _custom_import_sampler ("xray" , resource = None )
87
85
xray_client : _AwsXRaySamplingClient = xray_sampler ._AwsXRayRemoteSampler__xray_client
88
86
self .assertEqual (xray_sampler ._AwsXRayRemoteSampler__polling_interval , 600 )
89
87
self .assertEqual (
90
88
xray_client ._AwsXRaySamplingClient__get_sampling_rules_endpoint , "http://localhost:2000/GetSamplingRules"
91
89
)
92
90
93
- os .environ .pop (OTEL_TRACES_SAMPLER_ARG )
91
+ os .environ .pop (OTEL_TRACES_SAMPLER_ARG , None )
94
92
os .environ .setdefault (OTEL_TRACES_SAMPLER_ARG , "polling_interval=123" )
95
93
96
- # May log http request error as xray sampler will attempt to fetch rules
97
94
xray_sampler : Sampler = _custom_import_sampler ("xray" , resource = None )
98
95
xray_client : _AwsXRaySamplingClient = xray_sampler ._AwsXRayRemoteSampler__xray_client
99
96
self .assertEqual (xray_sampler ._AwsXRayRemoteSampler__polling_interval , 123 )
100
97
self .assertEqual (
101
98
xray_client ._AwsXRaySamplingClient__get_sampling_rules_endpoint , "http://127.0.0.1:2000/GetSamplingRules"
102
99
)
103
100
104
- os .environ .pop (OTEL_TRACES_SAMPLER_ARG )
101
+ os .environ .pop (OTEL_TRACES_SAMPLER_ARG , None )
105
102
os .environ .setdefault (OTEL_TRACES_SAMPLER_ARG , "endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000" )
106
103
107
- # May log http request error as xray sampler will attempt to fetch rules
108
104
xray_sampler : Sampler = _custom_import_sampler ("xray" , resource = None )
109
105
xray_client : _AwsXRaySamplingClient = xray_sampler ._AwsXRayRemoteSampler__xray_client
110
106
self .assertEqual (xray_sampler ._AwsXRayRemoteSampler__polling_interval , 300 )
@@ -116,10 +112,9 @@ def test_import_xray_sampler_with_valid_environment_arguments(self):
116
112
@patch .object (AwsXRayRemoteSampler , "_AwsXRayRemoteSampler__start_sampling_rule_poller" , lambda x : None )
117
113
@patch .object (AwsXRayRemoteSampler , "_AwsXRayRemoteSampler__start_sampling_target_poller" , lambda x : None )
118
114
def test_import_xray_sampler_with_invalid_environment_arguments (self ):
119
- os .environ .pop (OTEL_TRACES_SAMPLER_ARG )
115
+ os .environ .pop (OTEL_TRACES_SAMPLER_ARG , None )
120
116
os .environ .setdefault (OTEL_TRACES_SAMPLER_ARG , "endpoint=h=tt=p://=loca=lho=st:2000,polling_interval=FOOBAR" )
121
117
122
- # May log http request error as xray sampler will attempt to fetch rules
123
118
xray_sampler : Sampler = _custom_import_sampler ("xray" , resource = None )
124
119
xray_client : _AwsXRaySamplingClient = xray_sampler ._AwsXRayRemoteSampler__xray_client
125
120
self .assertEqual (xray_sampler ._AwsXRayRemoteSampler__polling_interval , 300 )
@@ -128,24 +123,63 @@ def test_import_xray_sampler_with_invalid_environment_arguments(self):
128
123
"h=tt=p://=loca=lho=st:2000/GetSamplingRules" ,
129
124
)
130
125
131
- os .environ .pop (OTEL_TRACES_SAMPLER_ARG )
126
+ os .environ .pop (OTEL_TRACES_SAMPLER_ARG , None )
132
127
os .environ .setdefault (OTEL_TRACES_SAMPLER_ARG , ",,=,==,,===," )
133
128
134
- # May log http request error as xray sampler will attempt to fetch rules
135
129
xray_sampler : Sampler = _custom_import_sampler ("xray" , resource = None )
136
130
xray_client : _AwsXRaySamplingClient = xray_sampler ._AwsXRayRemoteSampler__xray_client
137
131
self .assertEqual (xray_sampler ._AwsXRayRemoteSampler__polling_interval , 300 )
138
132
self .assertEqual (
139
133
xray_client ._AwsXRaySamplingClient__get_sampling_rules_endpoint , "http://127.0.0.1:2000/GetSamplingRules"
140
134
)
141
135
142
- os .environ .pop (OTEL_TRACES_SAMPLER_ARG )
136
+ os .environ .pop (OTEL_TRACES_SAMPLER_ARG , None )
143
137
os .environ .setdefault (OTEL_TRACES_SAMPLER_ARG , "endpoint,polling_interval" )
144
138
145
- # May log http request error as xray sampler will attempt to fetch rules
146
139
xray_sampler : Sampler = _custom_import_sampler ("xray" , resource = None )
147
140
xray_client : _AwsXRaySamplingClient = xray_sampler ._AwsXRayRemoteSampler__xray_client
148
141
self .assertEqual (xray_sampler ._AwsXRayRemoteSampler__polling_interval , 300 )
149
142
self .assertEqual (
150
143
xray_client ._AwsXRaySamplingClient__get_sampling_rules_endpoint , "http://127.0.0.1:2000/GetSamplingRules"
151
144
)
145
+
146
+ def test_using_xray_sampler_sets_url_exclusion_env_vars (self ):
147
+ targets_to_exclude = "SamplingTargets,GetSamplingRules"
148
+ os .environ .pop ("OTEL_PYTHON_REQUESTS_EXCLUDED_URLS" , None )
149
+ os .environ .pop ("OTEL_PYTHON_URLLIB3_EXCLUDED_URLS" , None )
150
+ self .assertEqual (os .environ .get ("OTEL_PYTHON_REQUESTS_EXCLUDED_URLS" , None ), None )
151
+ self .assertEqual (os .environ .get ("OTEL_PYTHON_URLLIB3_EXCLUDED_URLS" , None ), None )
152
+
153
+ _ : Sampler = _custom_import_sampler ("xray" , resource = None )
154
+ self .assertEqual (os .environ .get ("OTEL_PYTHON_REQUESTS_EXCLUDED_URLS" , None ), targets_to_exclude )
155
+ self .assertEqual (os .environ .get ("OTEL_PYTHON_URLLIB3_EXCLUDED_URLS" , None ), targets_to_exclude )
156
+
157
+ def test_using_xray_sampler_appends_url_exclusion_env_vars (self ):
158
+ targets_to_exclude = "SamplingTargets,GetSamplingRules"
159
+ os .environ .pop ("OTEL_PYTHON_REQUESTS_EXCLUDED_URLS" , None )
160
+ os .environ .pop ("OTEL_PYTHON_URLLIB3_EXCLUDED_URLS" , None )
161
+ self .assertEqual (os .environ .get ("OTEL_PYTHON_REQUESTS_EXCLUDED_URLS" , None ), None )
162
+ self .assertEqual (os .environ .get ("OTEL_PYTHON_URLLIB3_EXCLUDED_URLS" , None ), None )
163
+ os .environ .setdefault ("OTEL_PYTHON_REQUESTS_EXCLUDED_URLS" , ",,,target_A,target_B,,," )
164
+ os .environ .setdefault ("OTEL_PYTHON_URLLIB3_EXCLUDED_URLS" , "target_C,target_D" )
165
+
166
+ _ : Sampler = _custom_import_sampler ("xray" , resource = None )
167
+ self .assertTrue (targets_to_exclude in os .environ .get ("OTEL_PYTHON_REQUESTS_EXCLUDED_URLS" , None ))
168
+ self .assertTrue (targets_to_exclude in os .environ .get ("OTEL_PYTHON_URLLIB3_EXCLUDED_URLS" , None ))
169
+
170
+ def test_not_using_xray_sampler_does_not_modify_url_exclusion_env_vars (self ):
171
+ os .environ .pop ("OTEL_PYTHON_REQUESTS_EXCLUDED_URLS" , None )
172
+ os .environ .pop ("OTEL_PYTHON_URLLIB3_EXCLUDED_URLS" , None )
173
+ self .assertEqual (os .environ .get ("OTEL_PYTHON_REQUESTS_EXCLUDED_URLS" , None ), None )
174
+ self .assertEqual (os .environ .get ("OTEL_PYTHON_URLLIB3_EXCLUDED_URLS" , None ), None )
175
+
176
+ _ : Sampler = _custom_import_sampler ("traceidratio" , resource = None )
177
+ self .assertEqual (os .environ .get ("OTEL_PYTHON_REQUESTS_EXCLUDED_URLS" , None ), None )
178
+ self .assertEqual (os .environ .get ("OTEL_PYTHON_URLLIB3_EXCLUDED_URLS" , None ), None )
179
+
180
+ os .environ .setdefault ("OTEL_PYTHON_REQUESTS_EXCLUDED_URLS" , ",,,target_A,target_B,,," )
181
+ os .environ .setdefault ("OTEL_PYTHON_URLLIB3_EXCLUDED_URLS" , "target_C,target_D" )
182
+
183
+ _ : Sampler = _custom_import_sampler ("traceidratio" , resource = None )
184
+ self .assertEqual (os .environ .get ("OTEL_PYTHON_REQUESTS_EXCLUDED_URLS" , None ), ",,,target_A,target_B,,," )
185
+ self .assertEqual (os .environ .get ("OTEL_PYTHON_URLLIB3_EXCLUDED_URLS" , None ), "target_C,target_D" )
0 commit comments