Skip to content

Commit afb76f2

Browse files
committed
feat(http): add error handling for exporting
1 parent d327927 commit afb76f2

File tree

3 files changed

+15
-3
lines changed
  • exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http

3 files changed

+15
-3
lines changed

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ def export(self, batch: Sequence[LogData]) -> LogExportResult:
171171
serialized_data = encode_logs(batch).SerializeToString()
172172
deadline_sec = time() + self._timeout
173173
for retry_num in range(_MAX_RETRYS):
174-
resp = self._export(serialized_data, deadline_sec - time())
174+
try:
175+
resp = self._export(serialized_data, deadline_sec - time())
176+
except Exception as error:
177+
_logger.error("Failed to export logs batch reason: %s", error)
178+
return LogExportResult.FAILURE
175179
if resp.ok:
176180
return LogExportResult.SUCCESS
177181
# multiplying by a random number between .8 and 1.2 introduces a +/20% jitter to each backoff.

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,11 @@ def export(
221221
serialized_data = encode_metrics(metrics_data).SerializeToString()
222222
deadline_sec = time() + self._timeout
223223
for retry_num in range(_MAX_RETRYS):
224-
resp = self._export(serialized_data, deadline_sec - time())
224+
try:
225+
resp = self._export(serialized_data, deadline_sec - time())
226+
except Exception as error:
227+
_logger.error("Failed to export metrics batch reason: %s", error)
228+
return MetricExportResult.FAILURE
225229
if resp.ok:
226230
return MetricExportResult.SUCCESS
227231
# multiplying by a random number between .8 and 1.2 introduces a +/20% jitter to each backoff.

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
169169
serialized_data = encode_spans(spans).SerializePartialToString()
170170
deadline_sec = time() + self._timeout
171171
for retry_num in range(_MAX_RETRYS):
172-
resp = self._export(serialized_data, deadline_sec - time())
172+
try:
173+
resp = self._export(serialized_data, deadline_sec - time())
174+
except Exception as error:
175+
_logger.error("Failed to export span batch reason: %s", error)
176+
return SpanExportResult.FAILURE
173177
if resp.ok:
174178
return SpanExportResult.SUCCESS
175179
# multiplying by a random number between .8 and 1.2 introduces a +/20% jitter to each backoff.

0 commit comments

Comments
 (0)