|
| 1 | +# Copyright 2022 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from unittest import TestCase |
| 16 | +from unittest.mock import patch |
| 17 | + |
| 18 | +from opentelemetry.environment_variables import OTEL_PROPAGATORS |
| 19 | +from opentelemetry.propagators.cloud_trace_propagator import ( |
| 20 | + CloudTraceFormatPropagator, |
| 21 | +) |
| 22 | + |
| 23 | + |
| 24 | +class TestCloudTracePropagatorAutoInstrument(TestCase): |
| 25 | + @patch.dict("os.environ", {OTEL_PROPAGATORS: "gcp_trace"}) |
| 26 | + def test_loads_cloud_trace_propagator(self): |
| 27 | + # This test is a bit fragile as the propagator entry points are loaded on the first |
| 28 | + # import of opentelemetry.propagate and saved in a global variable. If another tests |
| 29 | + # imports that before this one, it can fail. |
| 30 | + # pylint: disable=import-outside-toplevel |
| 31 | + from opentelemetry.propagate import propagators |
| 32 | + |
| 33 | + self.assertEqual(len(propagators), 1) |
| 34 | + self.assertIsInstance(propagators[0], CloudTraceFormatPropagator) |
0 commit comments