|
14 | 14 |
|
15 | 15 | import time
|
16 | 16 | from concurrent.futures import ThreadPoolExecutor
|
| 17 | +from os.path import dirname |
17 | 18 | from unittest import TestCase
|
18 | 19 | from unittest.mock import patch
|
19 | 20 |
|
20 | 21 | from google.protobuf.duration_pb2 import Duration
|
21 | 22 | from google.rpc.error_details_pb2 import RetryInfo
|
22 |
| -from grpc import StatusCode, server |
| 23 | +from grpc import ChannelCredentials, Compression, StatusCode, server |
23 | 24 |
|
24 | 25 | from opentelemetry._logs import SeverityNumber
|
25 | 26 | from opentelemetry.exporter.otlp.proto.grpc._log_exporter import (
|
|
47 | 48 | )
|
48 | 49 | from opentelemetry.sdk._logs import LogData, LogRecord
|
49 | 50 | from opentelemetry.sdk._logs.export import LogExportResult
|
| 51 | +from opentelemetry.sdk.environment_variables import ( |
| 52 | + OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE, |
| 53 | + OTEL_EXPORTER_OTLP_LOGS_COMPRESSION, |
| 54 | + OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, |
| 55 | + OTEL_EXPORTER_OTLP_LOGS_HEADERS, |
| 56 | + OTEL_EXPORTER_OTLP_LOGS_TIMEOUT, |
| 57 | +) |
50 | 58 | from opentelemetry.sdk.resources import Resource as SDKResource
|
51 | 59 | from opentelemetry.sdk.util.instrumentation import InstrumentationScope
|
52 | 60 | from opentelemetry.trace import TraceFlags
|
53 | 61 |
|
| 62 | +THIS_DIR = dirname(__file__) |
| 63 | + |
54 | 64 |
|
55 | 65 | class LogsServiceServicerUNAVAILABLEDelay(LogsServiceServicer):
|
56 | 66 | # pylint: disable=invalid-name,unused-argument,no-self-use
|
@@ -100,7 +110,6 @@ def Export(self, request, context):
|
100 | 110 |
|
101 | 111 | class TestOTLPLogExporter(TestCase):
|
102 | 112 | def setUp(self):
|
103 |
| - |
104 | 113 | self.exporter = OTLPLogExporter()
|
105 | 114 |
|
106 | 115 | self.server = server(ThreadPoolExecutor(max_workers=10))
|
@@ -164,6 +173,32 @@ def test_exporting(self):
|
164 | 173 | # pylint: disable=protected-access
|
165 | 174 | self.assertEqual(self.exporter._exporting, "logs")
|
166 | 175 |
|
| 176 | + @patch.dict( |
| 177 | + "os.environ", |
| 178 | + { |
| 179 | + OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: "logs:4317", |
| 180 | + OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE: THIS_DIR |
| 181 | + + "/../fixtures/test.cert", |
| 182 | + OTEL_EXPORTER_OTLP_LOGS_HEADERS: " key1=value1,KEY2 = VALUE=2", |
| 183 | + OTEL_EXPORTER_OTLP_LOGS_TIMEOUT: "10", |
| 184 | + OTEL_EXPORTER_OTLP_LOGS_COMPRESSION: "gzip", |
| 185 | + }, |
| 186 | + ) |
| 187 | + @patch( |
| 188 | + "opentelemetry.exporter.otlp.proto.grpc.exporter.OTLPExporterMixin.__init__" |
| 189 | + ) |
| 190 | + def test_env_variables(self, mock_exporter_mixin): |
| 191 | + OTLPLogExporter() |
| 192 | + |
| 193 | + self.assertTrue(len(mock_exporter_mixin.call_args_list) == 1) |
| 194 | + _, kwargs = mock_exporter_mixin.call_args_list[0] |
| 195 | + self.assertEqual(kwargs["endpoint"], "logs:4317") |
| 196 | + self.assertEqual(kwargs["headers"], " key1=value1,KEY2 = VALUE=2") |
| 197 | + self.assertEqual(kwargs["timeout"], 10) |
| 198 | + self.assertEqual(kwargs["compression"], Compression.Gzip) |
| 199 | + self.assertIsNotNone(kwargs["credentials"]) |
| 200 | + self.assertIsInstance(kwargs["credentials"], ChannelCredentials) |
| 201 | + |
167 | 202 | @patch(
|
168 | 203 | "opentelemetry.exporter.otlp.proto.grpc.exporter.ssl_channel_credentials"
|
169 | 204 | )
|
|
0 commit comments