File tree Expand file tree Collapse file tree 7 files changed +55
-5
lines changed
opentelemetry-exporter-otlp-proto-grpc
src/opentelemetry/exporter/otlp/proto/grpc
opentelemetry-exporter-otlp-proto-http
src/opentelemetry/exporter/otlp/proto/http/_common Expand file tree Collapse file tree 7 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,11 @@ def _get_credentials(
196196 )
197197 if isinstance (maybe_channel_creds , ChannelCredentials ):
198198 return maybe_channel_creds
199+ else :
200+ raise RuntimeError (
201+ f"Requested component '{ credential_env } ' is of type { type (maybe_channel_creds )} "
202+ f" must be of type `grpc.ChannelCredentials`."
203+ )
199204
200205 certificate_file = environ .get (certificate_file_env_key )
201206 if certificate_file :
Original file line number Diff line number Diff line change @@ -294,7 +294,7 @@ def test_otlp_exporter_otlp_compression_unspecified(
294294 def test_that_credential_gets_passed_to_exporter (self , mock_entry_points ):
295295 credential = ChannelCredentials (None )
296296
297- def f (_ ):
297+ def f ():
298298 return credential
299299
300300 mock_entry_points .configure_mock (
@@ -304,6 +304,29 @@ def f(_):
304304 # pylint: disable=protected-access
305305 assert exporter ._credentials is credential
306306
307+ @patch .dict (
308+ "os.environ" ,
309+ {OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER : "credential_provider" },
310+ )
311+ def test_that_missing_entry_point_raises_exception (self ):
312+ with self .assertRaises (RuntimeError ):
313+ OTLPSpanExporterForTesting (insecure = False )
314+
315+ @patch .dict (
316+ "os.environ" ,
317+ {OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER : "credential_provider" },
318+ )
319+ @patch ("opentelemetry.exporter.otlp.proto.grpc.exporter.entry_points" )
320+ def test_that_entry_point_returning_bad_type_raises_exception (self , mock_entry_points ):
321+ def f ():
322+ return 1
323+
324+ mock_entry_points .configure_mock (
325+ return_value = [IterEntryPoint ("custom_credential" , f )]
326+ )
327+ with self .assertRaises (RuntimeError ):
328+ OTLPSpanExporterForTesting (insecure = False )
329+
307330 # pylint: disable=no-self-use, disable=unused-argument
308331 @patch (
309332 "opentelemetry.exporter.otlp.proto.grpc.exporter.ssl_channel_credentials"
Original file line number Diff line number Diff line change @@ -61,4 +61,9 @@ def _load_session_from_envvar(
6161 )
6262 if isinstance (maybe_session , requests .Session ):
6363 return maybe_session
64+ else :
65+ raise RuntimeError (
66+ f"Requested component '{ credential_env } ' is of type { type (maybe_session )} "
67+ f" must be of type `requests.Session`."
68+ )
6469 return None
Original file line number Diff line number Diff line change @@ -163,7 +163,7 @@ def test_constructor_default(self):
163163 def test_exporter_metrics_env_take_priority (self , mock_entry_points ):
164164 credential = Session ()
165165
166- def f (_ ):
166+ def f ():
167167 return credential
168168
169169 mock_entry_points .configure_mock (
Original file line number Diff line number Diff line change @@ -126,7 +126,7 @@ def test_constructor_default(self):
126126 def test_exporter_logs_env_take_priority (self , mock_entry_points ):
127127 credential = Session ()
128128
129- def f (_ ):
129+ def f ():
130130 return credential
131131
132132 mock_entry_points .configure_mock (
@@ -162,6 +162,23 @@ def f(_):
162162 "application/x-protobuf" ,
163163 )
164164
165+
166+ @patch .dict (
167+ "os.environ" ,
168+ {
169+ OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER : "provider_without_entry_point" ,
170+ },
171+ )
172+ @patch ("opentelemetry.exporter.otlp.proto.http._common.entry_points" )
173+ def test_exception_raised_when_entrypoint_returns_wrong_type (self , mock_entry_points ):
174+ def f ():
175+ return 1
176+ mock_entry_points .configure_mock (
177+ return_value = [IterEntryPoint ("custom_credential" , f )]
178+ )
179+ with self .assertRaises (RuntimeError ):
180+ OTLPLogExporter ()
181+
165182 @patch .dict (
166183 "os.environ" ,
167184 {
Original file line number Diff line number Diff line change @@ -120,7 +120,7 @@ def test_constructor_default(self):
120120 def test_exporter_traces_env_take_priority (self , mock_entry_point ):
121121 credential = Session ()
122122
123- def f (_ ):
123+ def f ():
124124 return credential
125125
126126 mock_entry_point .configure_mock (
Original file line number Diff line number Diff line change @@ -153,7 +153,7 @@ deps =
153153 getting-started: {env:CONTRIB_REPO}\# egg=opentelemetry-instrumentation-wsgi&subdirectory=instrumentation/opentelemetry-instrumentation-wsgi
154154 getting-started: {env:CONTRIB_REPO}\# egg=opentelemetry-instrumentation-flask&subdirectory=instrumentation/opentelemetry-instrumentation-flask
155155
156- allowlist_externals = sh
156+ allowlist_externals = sh, pytest
157157
158158setenv =
159159 ; override CONTRIB_REPO_SHA via env variable when testing other branches/commits than main
You can’t perform that action at this time.
0 commit comments