Skip to content

Commit

Permalink
refactor(zipkin-exporter): simplify success status check and add test…
Browse files Browse the repository at this point in the history
… for 204 response
  • Loading branch information
slyapustin committed Dec 5, 2024
1 parent 415c94f commit 7e41524
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
from opentelemetry.trace import Span

DEFAULT_ENDPOINT = "http://localhost:9411/api/v2/spans"
REQUESTS_SUCCESS_STATUS_CODES = (200, 202)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -171,7 +170,7 @@ def export(self, spans: Sequence[Span]) -> SpanExportResult:
timeout=self.timeout,
)

if result.status_code not in REQUESTS_SUCCESS_STATUS_CODES:
if not result.ok:
logger.error(
"Traces cannot be uploaded; status code: %s, message %s",
result.status_code,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ def test_export_success(self, mock_post):
status = exporter.export(spans)
self.assertEqual(SpanExportResult.SUCCESS, status)

@patch("requests.Session.post")
def test_export_success_no_content(self, mock_post):
mock_post.return_value = MockResponse(204)
spans = []
exporter = ZipkinExporter()
status = exporter.export(spans)
self.assertEqual(SpanExportResult.SUCCESS, status)

@patch("requests.Session.post")
def test_export_invalid_response(self, mock_post):
mock_post.return_value = MockResponse(404)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
from opentelemetry.trace import Span

DEFAULT_ENDPOINT = "http://localhost:9411/api/v2/spans"
REQUESTS_SUCCESS_STATUS_CODES = (200, 202)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -163,7 +162,7 @@ def export(self, spans: Sequence[Span]) -> SpanExportResult:
timeout=self.timeout,
)

if result.status_code not in REQUESTS_SUCCESS_STATUS_CODES:
if not result.ok:
logger.error(
"Traces cannot be uploaded; status code: %s, message %s",
result.status_code,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ def test_export_success(self, mock_post):
status = exporter.export(spans)
self.assertEqual(SpanExportResult.SUCCESS, status)

@patch("requests.Session.post")
def test_export_success_no_content(self, mock_post):
mock_post.return_value = MockResponse(204)
spans = []
exporter = ZipkinExporter()
status = exporter.export(spans)
self.assertEqual(SpanExportResult.SUCCESS, status)

@patch("requests.Session.post")
def test_export_invalid_response(self, mock_post):
mock_post.return_value = MockResponse(404)
Expand Down

0 comments on commit 7e41524

Please sign in to comment.