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

Handle HTTP 2XX responses as successful in OTLP exporters #3623

Merged
merged 6 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Handle HTTP 2XX responses as successful in OTLP exporters
([#3623](https://github.com/open-telemetry/opentelemetry-python/pull/3623))

## Version 1.22.0/0.43b0 (2023-12-15)

- Prometheus exporter sanitize info metric ([#3572](https://github.com/open-telemetry/opentelemetry-python/pull/3572))
- Prometheus exporter sanitize info metric
([#3572](https://github.com/open-telemetry/opentelemetry-python/pull/3572))
- Remove Jaeger exporters
([#3554](https://github.com/open-telemetry/opentelemetry-python/pull/3554))
- Log stacktrace on `UNKNOWN` status OTLP export error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def export(self, batch: Sequence[LogData]) -> LogExportResult:

resp = self._export(serialized_data)
# pylint: disable=no-else-return
if resp.status_code in (200, 202):
if resp.ok:
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
return LogExportResult.SUCCESS
elif self._retryable(resp):
_logger.warning(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def export(

resp = self._export(serialized_data.SerializeToString())
# pylint: disable=no-else-return
if resp.status_code in (200, 202):
if resp.ok:
return MetricExportResult.SUCCESS
elif self._retryable(resp):
_logger.warning(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def export(self, spans) -> SpanExportResult:

resp = self._export(serialized_data)
# pylint: disable=no-else-return
if resp.status_code in (200, 202):
if resp.ok:
return SpanExportResult.SUCCESS
elif self._retryable(resp):
_logger.warning(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from logging import WARNING
from os import environ
from unittest import TestCase
from unittest.mock import patch
from unittest.mock import MagicMock, Mock, patch

from requests import Session
from requests.models import Response
Expand Down Expand Up @@ -476,3 +476,14 @@ def test_exponential_explicit_bucket_histogram(self):
OTLPMetricExporter()._preferred_aggregation[Histogram],
ExplicitBucketHistogramAggregation,
)

@patch.object(OTLPMetricExporter, "_export", return_value=Mock(ok=True))
def test_2XX_status_code(self, mock_otlp_metric_exporter):
"""
Test that any HTTP 2XX code returns a successful result
"""

self.assertEqual(
OTLPMetricExporter().export(MagicMock()),
MetricExportResult.SUCCESS,
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import unittest
from typing import List
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock, Mock, patch

import requests
import responses
Expand All @@ -34,6 +34,7 @@
from opentelemetry.exporter.otlp.proto.http.version import __version__
from opentelemetry.sdk._logs import LogData
from opentelemetry.sdk._logs import LogRecord as SDKLogRecord
from opentelemetry.sdk._logs.export import LogExportResult
from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_OTLP_CERTIFICATE,
OTEL_EXPORTER_OTLP_COMPRESSION,
Expand Down Expand Up @@ -262,3 +263,13 @@ def _get_sdk_log_data() -> List[LogData]:
)

return [log1, log2, log3, log4]

@patch.object(OTLPLogExporter, "_export", return_value=Mock(ok=True))
def test_2XX_status_code(self, mock_otlp_metric_exporter):
"""
Test that any HTTP 2XX code returns a successful result
"""

self.assertEqual(
OTLPLogExporter().export(MagicMock()), LogExportResult.SUCCESS
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import unittest
from collections import OrderedDict
from unittest.mock import Mock, patch
from unittest.mock import MagicMock, Mock, patch

import requests
import responses
Expand Down Expand Up @@ -42,6 +42,7 @@
OTEL_EXPORTER_OTLP_TRACES_TIMEOUT,
)
from opentelemetry.sdk.trace import _Span
from opentelemetry.sdk.trace.export import SpanExportResult

OS_ENV_ENDPOINT = "os.env.base"
OS_ENV_CERTIFICATE = "os/env/base.crt"
Expand Down Expand Up @@ -239,3 +240,13 @@ def generate_delays(*args, **kwargs):

exporter.export([span])
mock_sleep.assert_called_once_with(1)

@patch.object(OTLPSpanExporter, "_export", return_value=Mock(ok=True))
def test_2XX_status_code(self, mock_otlp_metric_exporter):
"""
Test that any HTTP 2XX code returns a successful result
"""

self.assertEqual(
OTLPSpanExporter().export(MagicMock()), SpanExportResult.SUCCESS
)
Loading