Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(zipkin-exporter): simplify success status check and add test for 204 response #4339

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading