Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 08c34fc

Browse files
authored
Add support to initialize azure exporters with proxies (#902)
1 parent 7ec4ff6 commit 08c34fc

File tree

6 files changed

+47
-1
lines changed

6 files changed

+47
-1
lines changed

contrib/opencensus-ext-azure/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- Change default path of local storage
66
([#903](https://github.com/census-instrumentation/opencensus-python/pull/903))
7+
- Add support to initialize azure exporters with proxies
8+
([#902](https://github.com/census-instrumentation/opencensus-python/pull/902))
79

810
## 1.0.1
911
Released 2019-11-26

contrib/opencensus-ext-azure/opencensus/ext/azure/common/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ def process_options(options):
5656
TEMPDIR_PREFIX + TEMPDIR_SUFFIX
5757
)
5858

59+
if options.proxies is None:
60+
options.proxies = '{}'
61+
5962

6063
def parse_connection_string(connection_string):
6164
if connection_string is None:
@@ -105,7 +108,7 @@ def __init__(self, *args, **kwargs):
105108
logging_sampling_rate=1.0,
106109
max_batch_size=100,
107110
minimum_retry_interval=60, # minimum retry interval in seconds
108-
proxy=None,
111+
proxies=None, # string maps url schemes to the url of the proxies
109112
storage_maintenance_period=60,
110113
storage_max_size=50*1024*1024, # 50MiB
111114
storage_path=None,

contrib/opencensus-ext-azure/opencensus/ext/azure/common/transport.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def _transmit(self, envelopes):
5252
'Content-Type': 'application/json; charset=utf-8',
5353
},
5454
timeout=self.options.timeout,
55+
proxies=json.loads(self.options.proxies),
5556
)
5657
except requests.Timeout:
5758
logger.warning(

contrib/opencensus-ext-azure/tests/test_azure_log_exporter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ def test_invalid_sampling_rate(self):
8585
logging_sampling_rate=4.0,
8686
)
8787

88+
def test_init_handler_with_proxies(self):
89+
handler = log_exporter.AzureLogHandler(
90+
instrumentation_key='12345678-1234-5678-abcd-12345678abcd',
91+
proxies='{"https":"https://test-proxy.com"}',
92+
)
93+
94+
self.assertEqual(
95+
handler.options.proxies,
96+
'{"https":"https://test-proxy.com"}',
97+
)
98+
8899
@mock.patch('requests.post', return_value=mock.Mock())
89100
def test_exception(self, requests_mock):
90101
logger = logging.getLogger(self.id())

contrib/opencensus-ext-azure/tests/test_azure_trace_exporter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ def test_ctor(self):
4545
self.assertRaises(ValueError, lambda: trace_exporter.AzureExporter())
4646
Options._default.instrumentation_key = instrumentation_key
4747

48+
def test_init_exporter_with_proxies(self):
49+
exporter = trace_exporter.AzureExporter(
50+
instrumentation_key='12345678-1234-5678-abcd-12345678abcd',
51+
proxies='{"https":"https://test-proxy.com"}',
52+
)
53+
54+
self.assertEqual(
55+
exporter.options.proxies,
56+
'{"https":"https://test-proxy.com"}',
57+
)
58+
4859
@mock.patch('requests.post', return_value=mock.Mock())
4960
def test_emit_empty(self, request_mock):
5061
exporter = trace_exporter.AzureExporter(

contrib/opencensus-ext-azure/tests/test_options.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ def test_process_options_endpoint_default(self):
9090
self.assertEqual(options.endpoint,
9191
'https://dc.services.visualstudio.com/v2/track')
9292

93+
def test_process_options_proxies_default(self):
94+
options = common.Options()
95+
options.proxies = "{}"
96+
common.process_options(options)
97+
98+
self.assertEqual(options.proxies, "{}")
99+
100+
def test_process_options_proxies_set_proxies(self):
101+
options = common.Options()
102+
options.connection_string = None
103+
options.proxies = '{"https": "https://test-proxy.com"}'
104+
common.process_options(options)
105+
106+
self.assertEqual(
107+
options.proxies,
108+
'{"https": "https://test-proxy.com"}'
109+
)
110+
93111
def test_parse_connection_string_none(self):
94112
cs = None
95113
result = common.parse_connection_string(cs)

0 commit comments

Comments
 (0)