|
17 | 17 | import time |
18 | 18 | from os.path import dirname |
19 | 19 | from unittest import TestCase |
20 | | -from unittest.mock import patch |
| 20 | +from unittest.mock import Mock, patch |
21 | 21 |
|
22 | 22 | from google.protobuf.json_format import MessageToDict |
23 | 23 | from grpc import ChannelCredentials, Compression |
@@ -266,6 +266,45 @@ def test_env_variables_with_only_certificate( |
266 | 266 |
|
267 | 267 | mock_logger_error.assert_not_called() |
268 | 268 |
|
| 269 | + @patch.dict( |
| 270 | + "os.environ", |
| 271 | + { |
| 272 | + OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: "logs:4317", |
| 273 | + OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE: THIS_DIR |
| 274 | + + "/../fixtures/test.cert", |
| 275 | + OTEL_EXPORTER_OTLP_LOGS_HEADERS: " key1=value1,KEY2 = VALUE=2", |
| 276 | + OTEL_EXPORTER_OTLP_LOGS_TIMEOUT: "10", |
| 277 | + OTEL_EXPORTER_OTLP_LOGS_COMPRESSION: "gzip", |
| 278 | + }, |
| 279 | + ) |
| 280 | + @patch( |
| 281 | + "opentelemetry.exporter.otlp.proto.grpc.exporter.OTLPExporterMixin.__init__" |
| 282 | + ) |
| 283 | + @patch("logging.Logger.error") |
| 284 | + def test_kwargs_have_precedence_over_env_variables( |
| 285 | + self, mock_logger_error, mock_exporter_mixin |
| 286 | + ): |
| 287 | + credentials_mock = Mock() |
| 288 | + OTLPLogExporter( |
| 289 | + endpoint="logs:4318", |
| 290 | + headers=(("an", "header"),), |
| 291 | + timeout=20, |
| 292 | + credentials=credentials_mock, |
| 293 | + compression=Compression.NoCompression, |
| 294 | + channel_options=(("some", "options"),), |
| 295 | + ) |
| 296 | + |
| 297 | + self.assertTrue(len(mock_exporter_mixin.call_args_list) == 1) |
| 298 | + _, kwargs = mock_exporter_mixin.call_args_list[0] |
| 299 | + self.assertEqual(kwargs["endpoint"], "logs:4318") |
| 300 | + self.assertEqual(kwargs["headers"], (("an", "header"),)) |
| 301 | + self.assertEqual(kwargs["timeout"], 20) |
| 302 | + self.assertEqual(kwargs["compression"], Compression.NoCompression) |
| 303 | + self.assertEqual(kwargs["credentials"], credentials_mock) |
| 304 | + self.assertEqual(kwargs["channel_options"], (("some", "options"),)) |
| 305 | + |
| 306 | + mock_logger_error.assert_not_called() |
| 307 | + |
269 | 308 | def export_log_and_deserialize(self, log_data): |
270 | 309 | # pylint: disable=protected-access |
271 | 310 | translated_data = self.exporter._translate_data([log_data]) |
|
0 commit comments