Skip to content

Commit 0b21293

Browse files
committed
Respond to comments
1 parent ffeb2d2 commit 0b21293

File tree

9 files changed

+43
-25
lines changed

9 files changed

+43
-25
lines changed

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@ def _is_retryable(resp: requests.Response) -> bool:
3535

3636

3737
def _load_session_from_envvar(
38-
exporter_type: Literal["logs", "traces", "metrics"],
38+
cred_envvar: Literal[
39+
OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER,
40+
OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER,
41+
OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER,
42+
],
3943
) -> Optional[requests.Session]:
40-
if exporter_type == "logs":
41-
env_var = OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER
42-
elif exporter_type == "traces":
43-
env_var = OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER
44-
else:
45-
env_var = OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER
4644
credential_env = environ.get(
4745
OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER
48-
) or environ.get(env_var)
46+
) or environ.get(cred_envvar)
4947
if credential_env:
5048
try:
5149
maybe_session = next(
@@ -64,13 +62,3 @@ def _load_session_from_envvar(
6462
if isinstance(maybe_session, requests.Session):
6563
return maybe_session
6664
return None
67-
68-
69-
# For testing
70-
class IterEntryPoint:
71-
def __init__(self, name, class_type):
72-
self.name = name
73-
self.class_type = class_type
74-
75-
def load(self):
76-
return self.class_type

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
OTEL_EXPORTER_OTLP_ENDPOINT,
4949
OTEL_EXPORTER_OTLP_HEADERS,
5050
OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE,
51+
OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER,
5152
OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE,
5253
OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEY,
5354
OTEL_EXPORTER_OTLP_LOGS_COMPRESSION,
@@ -122,7 +123,7 @@ def __init__(
122123
)
123124
self._compression = compression or _compression_from_env()
124125
self._session = (
125-
session or _load_session_from_envvar("logs") or requests.Session()
126+
session or _load_session_from_envvar(OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER) or requests.Session()
126127
)
127128
self._session.headers.update(self._headers)
128129
self._session.headers.update(_OTLP_HTTP_HEADERS)

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE,
7878
OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY,
7979
OTEL_EXPORTER_OTLP_METRICS_COMPRESSION,
80+
OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER
8081
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT,
8182
OTEL_EXPORTER_OTLP_METRICS_HEADERS,
8283
OTEL_EXPORTER_OTLP_METRICS_TIMEOUT,
@@ -162,7 +163,7 @@ def __init__(
162163
self._compression = compression or _compression_from_env()
163164
self._session = (
164165
session
165-
or _load_session_from_envvar("metrics")
166+
or _load_session_from_envvar(OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER)
166167
or requests.Session()
167168
)
168169
self._session.headers.update(self._headers)

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,
5252
OTEL_EXPORTER_OTLP_TRACES_HEADERS,
5353
OTEL_EXPORTER_OTLP_TRACES_TIMEOUT,
54+
OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER,
5455
)
5556
from opentelemetry.sdk.trace import ReadableSpan
5657
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
@@ -118,7 +119,9 @@ def __init__(
118119
self._compression = compression or _compression_from_env()
119120
self._session = (
120121
session
121-
or _load_session_from_envvar("traces")
122+
or _load_session_from_envvar(
123+
OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER
124+
)
122125
or requests.Session()
123126
)
124127
self._session.headers.update(self._headers)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright The OpenTelemetry Authors
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+
# http://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+
# pylint: disable=protected-access
16+
17+
class IterEntryPoint:
18+
def __init__(self, name, class_type):
19+
self.name = name
20+
self.class_type = class_type
21+
22+
def load(self):
23+
return self.class_type

exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
encode_metrics,
2727
)
2828
from opentelemetry.exporter.otlp.proto.http import Compression
29-
from opentelemetry.exporter.otlp.proto.http._common import IterEntryPoint
3029
from opentelemetry.exporter.otlp.proto.http.metric_exporter import (
3130
DEFAULT_COMPRESSION,
3231
DEFAULT_ENDPOINT,
@@ -79,6 +78,8 @@
7978
)
8079
from opentelemetry.test.metrictestutil import _generate_sum
8180

81+
from .._common import IterEntryPoint
82+
8283
OS_ENV_ENDPOINT = "os.env.base"
8384
OS_ENV_CERTIFICATE = "os/env/base.crt"
8485
OS_ENV_CLIENT_CERTIFICATE = "os/env/client-cert.pem"

exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
from opentelemetry._logs import SeverityNumber
3030
from opentelemetry.exporter.otlp.proto.http import Compression
31-
from opentelemetry.exporter.otlp.proto.http._common import IterEntryPoint
3231
from opentelemetry.exporter.otlp.proto.http._log_exporter import (
3332
DEFAULT_COMPRESSION,
3433
DEFAULT_ENDPOINT,
@@ -69,6 +68,8 @@
6968
set_span_in_context,
7069
)
7170

71+
from ._common import IterEntryPoint
72+
7273
ENV_ENDPOINT = "http://localhost.env:8080/"
7374
ENV_CERTIFICATE = "/etc/base.crt"
7475
ENV_CLIENT_CERTIFICATE = "/etc/client-cert.pem"

exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from requests.models import Response
2424

2525
from opentelemetry.exporter.otlp.proto.http import Compression
26-
from opentelemetry.exporter.otlp.proto.http._common import IterEntryPoint
2726
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
2827
DEFAULT_COMPRESSION,
2928
DEFAULT_ENDPOINT,
@@ -52,6 +51,8 @@
5251
from opentelemetry.sdk.trace import _Span
5352
from opentelemetry.sdk.trace.export import SpanExportResult
5453

54+
from ._common import IterEntryPoint
55+
5556
OS_ENV_ENDPOINT = "os.env.base"
5657
OS_ENV_CERTIFICATE = "os/env/base.crt"
5758
OS_ENV_CLIENT_CERTIFICATE = "os/env/client-cert.pem"

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ deps =
346346
-e {toxinidir}/opentelemetry-sdk
347347
-e {toxinidir}/tests/opentelemetry-test-utils
348348
commands =
349-
pip freeze
350349
pyright --version
351350
pyright
352351

0 commit comments

Comments
 (0)