|
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.exporter.otlp.proto.grpc._log_exporter import (
|
25 | 26 | OTLPLogExporter,
|
|
43 | 44 | from opentelemetry.proto.resource.v1.resource_pb2 import (
|
44 | 45 | Resource as OTLPResource,
|
45 | 46 | )
|
| 47 | +from opentelemetry.sdk.environment_variables import ( |
| 48 | + OTEL_EXPORTER_OTLP_COMPRESSION, |
| 49 | + OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE, |
| 50 | + OTEL_EXPORTER_OTLP_LOGS_COMPRESSION, |
| 51 | + OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, |
| 52 | + OTEL_EXPORTER_OTLP_LOGS_HEADERS, |
| 53 | + OTEL_EXPORTER_OTLP_LOGS_INSECURE, |
| 54 | + OTEL_EXPORTER_OTLP_LOGS_TIMEOUT, |
| 55 | +) |
46 | 56 | from opentelemetry.sdk._logs import LogData, LogRecord
|
47 | 57 | from opentelemetry.sdk._logs.export import LogExportResult
|
48 | 58 | from opentelemetry.sdk._logs.severity import (
|
|
52 | 62 | from opentelemetry.sdk.util.instrumentation import InstrumentationScope
|
53 | 63 | from opentelemetry.trace import TraceFlags
|
54 | 64 |
|
| 65 | +THIS_DIR = dirname(__file__) |
| 66 | + |
55 | 67 |
|
56 | 68 | class LogsServiceServicerUNAVAILABLEDelay(LogsServiceServicer):
|
57 | 69 | # pylint: disable=invalid-name,unused-argument,no-self-use
|
@@ -165,6 +177,33 @@ def test_exporting(self):
|
165 | 177 | # pylint: disable=protected-access
|
166 | 178 | self.assertEqual(self.exporter._exporting, "logs")
|
167 | 179 |
|
| 180 | + @patch.dict( |
| 181 | + "os.environ", |
| 182 | + { |
| 183 | + OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: "logs:4317", |
| 184 | + OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE: THIS_DIR |
| 185 | + + "/fixtures/test.cert", |
| 186 | + OTEL_EXPORTER_OTLP_LOGS_HEADERS: " key1=value1,KEY2 = value=2", |
| 187 | + OTEL_EXPORTER_OTLP_LOGS_TIMEOUT: "10", |
| 188 | + OTEL_EXPORTER_OTLP_LOGS_COMPRESSION: "gzip", |
| 189 | + }, |
| 190 | + ) |
| 191 | + @patch( |
| 192 | + "opentelemetry.exporter.otlp.proto.grpc.exporter.OTLPExporterMixin.__init__" |
| 193 | + ) |
| 194 | + def test_env_variables(self, mock_exporter_mixin): |
| 195 | + OTLPLogExporter() |
| 196 | + |
| 197 | + self.assertTrue(len(mock_exporter_mixin.call_args_list) == 1) |
| 198 | + _, kwargs = mock_exporter_mixin.call_args_list[0] |
| 199 | + |
| 200 | + self.assertEqual(kwargs["endpoint"], "log:4317") |
| 201 | + self.assertEqual(kwargs["headers"], " key1=value1,KEY2 = value=2") |
| 202 | + self.assertEqual(kwargs["timeout"], 10) |
| 203 | + self.assertEqual(kwargs["compression"], Compression.Gzip) |
| 204 | + self.assertIsNotNone(kwargs["credentials"]) |
| 205 | + self.assertIsInstance(kwargs["credentials"], ChannelCredentials) |
| 206 | + |
168 | 207 | @patch(
|
169 | 208 | "opentelemetry.exporter.otlp.proto.grpc.exporter.ssl_channel_credentials"
|
170 | 209 | )
|
|
0 commit comments