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

Commit b83d6fd

Browse files
authored
Add storage existence checks (#1150)
1 parent c9d2570 commit b83d6fd

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

contrib/opencensus-ext-azure/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Add storage existence checks to storing and transmitting in exporter
6+
([#1150](https://github.com/census-instrumentation/opencensus-python/pull/1150))
7+
58
## 1.1.6
69
Released 2022-08-03
710

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,19 @@ def _export(self, batch, event=None): # pragma: NO COVER
7979
envelopes = self.apply_telemetry_processors(envelopes)
8080
result = self._transmit(envelopes)
8181
# Only store files if local storage enabled
82-
if self.storage and result is TransportStatusCode.RETRY:
83-
self.storage.put(
84-
envelopes,
85-
self.options.minimum_retry_interval,
86-
)
87-
if event:
88-
if isinstance(event, QueueExitEvent):
89-
self._transmit_from_storage() # send files before exit
90-
return
91-
if len(batch) < self.options.max_batch_size:
92-
self._transmit_from_storage()
82+
if self.storage:
83+
if result is TransportStatusCode.RETRY:
84+
self.storage.put(
85+
envelopes,
86+
self.options.minimum_retry_interval,
87+
)
88+
if result is TransportStatusCode.SUCCESS:
89+
if len(batch) < self.options.max_batch_size:
90+
self._transmit_from_storage()
91+
if event:
92+
if isinstance(event, QueueExitEvent):
93+
# send files before exit
94+
self._transmit_from_storage()
9395
finally:
9496
if event:
9597
event.set()

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ def export_metrics(self, metrics):
8181
statsbeat.shutdown_statsbeat_metrics()
8282
return
8383
# Only store files if local storage enabled
84-
if self.storage and result is TransportStatusCode.RETRY:
85-
self.storage.put(batch, self.options.minimum_retry_interval)
86-
87-
# If there is still room to transmit envelopes, transmit from storage
88-
# if available
89-
if len(envelopes) < self.options.max_batch_size:
90-
self._transmit_from_storage()
84+
if self.storage:
85+
if result is TransportStatusCode.RETRY:
86+
self.storage.put(batch, self.options.minimum_retry_interval) # noqa: E501
87+
if result is TransportStatusCode.SUCCESS:
88+
# If there is still room to transmit envelopes,
89+
# transmit from storage if available
90+
if len(envelopes) < self.options.max_batch_size:
91+
self._transmit_from_storage()
9192

9293
def metric_to_envelopes(self, metric):
9394
envelopes = []

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ def emit(self, batch, event=None):
213213
self.options.minimum_retry_interval
214214
)
215215
if event:
216-
if isinstance(event, QueueExitEvent):
216+
if self.storage and isinstance(event, QueueExitEvent):
217217
self._transmit_from_storage() # send files before exit
218218
event.set()
219219
return
220-
if len(batch) < self.options.max_batch_size:
220+
if self.storage and len(batch) < self.options.max_batch_size:
221221
self._transmit_from_storage()
222222
except Exception:
223223
logger.exception('Exception occurred while exporting the data.')

0 commit comments

Comments
 (0)