Skip to content

Commit

Permalink
Fix warning message for OTLP gRPC exporter mixin
Browse files Browse the repository at this point in the history
Fixes #2780
  • Loading branch information
ocelotl committed Jun 24, 2022
1 parent 25771ec commit b09fe25
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,17 @@ def _export(self, data: TypingSequence[SDKDataT]) -> ExportResultT:
)

logger.warning(
"Transient error %s encountered while exporting span batch, retrying in %ss.",
"Transient error %s encountered while exporting %s, retrying in %ss.",
error.code(),
data.__class__.__name__,
delay,
)
sleep(delay)
continue
else:
logger.error(
"Failed to export span batch, error code: %s",
"Failed to export %s, error code: %s",
data.__class__.__name__,
error.code(),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from logging import WARNING
from types import MethodType
from typing import Sequence
from unittest import TestCase
from unittest.mock import patch
from unittest.mock import Mock, patch

from grpc import Compression

from opentelemetry.exporter.otlp.proto.grpc.exporter import (
ExportServiceRequestT,
InvalidCompressionValueException,
OTLPExporterMixin,
RpcError,
SDKDataT,
StatusCode,
environ_to_compression,
)

Expand Down Expand Up @@ -47,3 +55,57 @@ def test_environ_to_compression(self):
)
with self.assertRaises(InvalidCompressionValueException):
environ_to_compression("test_invalid")

@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.expo")
def test_export_warning(self, mock_expo):

mock_expo.configure_mock(**{"return_value": [0]})

rpc_error = RpcError()

def code(self):
return None

rpc_error.code = MethodType(code, rpc_error)

class OTLPMockExporter(OTLPExporterMixin):

_result = Mock()
_stub = Mock(
**{"return_value": Mock(**{"Export.side_effect": rpc_error})}
)

def _translate_data(
self, data: Sequence[SDKDataT]
) -> ExportServiceRequestT:
pass

otlp_mock_exporter = OTLPMockExporter()

with self.assertLogs(level=WARNING) as warning:
# pylint: disable=protected-access
otlp_mock_exporter._export(Mock())
self.assertEqual(
warning.records[0].message,
"Failed to export Mock, error code: None",
)

def code(self): # pylint: disable=function-redefined
return StatusCode.CANCELLED

def trailing_metadata(self):
return {}

rpc_error.code = MethodType(code, rpc_error)
rpc_error.trailing_metadata = MethodType(trailing_metadata, rpc_error)

with self.assertLogs(level=WARNING) as warning:
# pylint: disable=protected-access
otlp_mock_exporter._export(Mock())
self.assertEqual(
warning.records[0].message,
(
"Transient error StatusCode.CANCELLED encountered "
"while exporting Mock, retrying in 0s."
),
)

0 comments on commit b09fe25

Please sign in to comment.