Skip to content

Commit fc094e0

Browse files
committed
Merge branch 'main' into fidelity-20230110-102534
* main: fixed all instances of @tracer.start_as_current_span("name"): to @tracer.start_as_current_span("name") as decorators do not have colons (open-telemetry#3127) Add attribute name to type warning message. (open-telemetry#3124) Fix requirements file for example (open-telemetry#3126) Add db metric name to semantic conventions (open-telemetry#3115) Adds environment variables for log exporter (open-telemetry#3037) Fix bug in example (open-telemetry#3111)
2 parents 08990d1 + 5a996fd commit fc094e0

File tree

12 files changed

+207
-17
lines changed

12 files changed

+207
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## Unreleased
9+
- Adds environment variables for log exporter
10+
([#3037](https://github.com/open-telemetry/opentelemetry-python/pull/3037))
11+
- Add attribute name to type warning message.
12+
([3124](https://github.com/open-telemetry/opentelemetry-python/pull/3124))
13+
- Add db metric name to semantic conventions
14+
([#3115](https://github.com/open-telemetry/opentelemetry-python/pull/3115))
915

1016
- Remove spaces from example exporter User-Agent header to conform to RFC7231 & RFC7230.
1117

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Deprecated==1.2.13
2-
opentelemetry-api==1.12.0
3-
opentelemetry-sdk==1.12.0
4-
opentelemetry-semantic-conventions==0.33b0
2+
opentelemetry-api==1.15.0
3+
opentelemetry-sdk==1.15.0
4+
opentelemetry-semantic-conventions==0.36b0
55
typing_extensions==4.3.0
66
wrapt==1.14.1

exporter/opentelemetry-exporter-otlp-proto-grpc/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies = [
3131
"grpcio >= 1.0.0, < 2.0.0",
3232
"opentelemetry-api ~= 1.12",
3333
"opentelemetry-proto == 1.16.0.dev",
34-
"opentelemetry-sdk ~= 1.12",
34+
"opentelemetry-sdk ~= 1.16.0.dev",
3535
]
3636

3737
[project.optional-dependencies]

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
from os import environ
1415
from typing import Optional, Sequence
1516
from grpc import ChannelCredentials, Compression
1617
from opentelemetry.exporter.otlp.proto.grpc.exporter import (
1718
OTLPExporterMixin,
1819
get_resource_data,
20+
_get_credentials,
1921
_translate_value,
22+
environ_to_compression,
2023
)
2124
from opentelemetry.proto.collector.logs.v1.logs_service_pb2 import (
2225
ExportLogsServiceRequest,
@@ -34,6 +37,15 @@
3437
from opentelemetry.sdk._logs import LogData
3538
from opentelemetry.sdk._logs.export import LogExporter, LogExportResult
3639

40+
from opentelemetry.sdk.environment_variables import (
41+
OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE,
42+
OTEL_EXPORTER_OTLP_LOGS_COMPRESSION,
43+
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT,
44+
OTEL_EXPORTER_OTLP_LOGS_HEADERS,
45+
OTEL_EXPORTER_OTLP_LOGS_INSECURE,
46+
OTEL_EXPORTER_OTLP_LOGS_TIMEOUT,
47+
)
48+
3749

3850
class OTLPLogExporter(
3951
LogExporter,
@@ -52,13 +64,40 @@ def __init__(
5264
timeout: Optional[int] = None,
5365
compression: Optional[Compression] = None,
5466
):
67+
if insecure is None:
68+
insecure = environ.get(OTEL_EXPORTER_OTLP_LOGS_INSECURE)
69+
if insecure is not None:
70+
insecure = insecure.lower() == "true"
71+
72+
if (
73+
not insecure
74+
and environ.get(OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE) is not None
75+
):
76+
credentials = _get_credentials(
77+
credentials, OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE
78+
)
79+
80+
environ_timeout = environ.get(OTEL_EXPORTER_OTLP_LOGS_TIMEOUT)
81+
environ_timeout = (
82+
int(environ_timeout) if environ_timeout is not None else None
83+
)
84+
85+
compression = (
86+
environ_to_compression(OTEL_EXPORTER_OTLP_LOGS_COMPRESSION)
87+
if compression is None
88+
else compression
89+
)
90+
endpoint = endpoint or environ.get(OTEL_EXPORTER_OTLP_LOGS_ENDPOINT)
91+
92+
headers = headers or environ.get(OTEL_EXPORTER_OTLP_LOGS_HEADERS)
93+
5594
super().__init__(
5695
**{
5796
"endpoint": endpoint,
5897
"insecure": insecure,
5998
"credentials": credentials,
6099
"headers": headers,
61-
"timeout": timeout,
100+
"timeout": timeout or environ_timeout,
62101
"compression": compression,
63102
}
64103
)

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414

1515
import time
1616
from concurrent.futures import ThreadPoolExecutor
17+
from os.path import dirname
1718
from unittest import TestCase
1819
from unittest.mock import patch
1920

2021
from google.protobuf.duration_pb2 import Duration
2122
from google.rpc.error_details_pb2 import RetryInfo
22-
from grpc import StatusCode, server
23+
from grpc import ChannelCredentials, Compression, StatusCode, server
2324

2425
from opentelemetry._logs import SeverityNumber
2526
from opentelemetry.exporter.otlp.proto.grpc._log_exporter import (
@@ -47,10 +48,19 @@
4748
)
4849
from opentelemetry.sdk._logs import LogData, LogRecord
4950
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+
)
5058
from opentelemetry.sdk.resources import Resource as SDKResource
5159
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
5260
from opentelemetry.trace import TraceFlags
5361

62+
THIS_DIR = dirname(__file__)
63+
5464

5565
class LogsServiceServicerUNAVAILABLEDelay(LogsServiceServicer):
5666
# pylint: disable=invalid-name,unused-argument,no-self-use
@@ -100,7 +110,6 @@ def Export(self, request, context):
100110

101111
class TestOTLPLogExporter(TestCase):
102112
def setUp(self):
103-
104113
self.exporter = OTLPLogExporter()
105114

106115
self.server = server(ThreadPoolExecutor(max_workers=10))
@@ -164,6 +173,32 @@ def test_exporting(self):
164173
# pylint: disable=protected-access
165174
self.assertEqual(self.exporter._exporting, "logs")
166175

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+
167202
@patch(
168203
"opentelemetry.exporter.otlp.proto.grpc.exporter.ssl_channel_credentials"
169204
)

exporter/opentelemetry-exporter-otlp-proto-http/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies = [
3030
"googleapis-common-protos ~= 1.52",
3131
"opentelemetry-api ~= 1.12",
3232
"opentelemetry-proto == 1.16.0.dev",
33-
"opentelemetry-sdk ~= 1.12",
33+
"opentelemetry-sdk ~= 1.16.0.dev",
3434
"requests ~= 2.7",
3535
]
3636

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
OTEL_EXPORTER_OTLP_ENDPOINT,
3030
OTEL_EXPORTER_OTLP_HEADERS,
3131
OTEL_EXPORTER_OTLP_TIMEOUT,
32+
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT,
33+
OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE,
34+
OTEL_EXPORTER_OTLP_LOGS_HEADERS,
35+
OTEL_EXPORTER_OTLP_LOGS_TIMEOUT,
36+
OTEL_EXPORTER_OTLP_LOGS_COMPRESSION,
3237
)
3338
from opentelemetry.sdk._logs import LogData
3439
from opentelemetry.sdk._logs.export import (
@@ -79,16 +84,26 @@ def __init__(
7984
compression: Optional[Compression] = None,
8085
session: Optional[requests.Session] = None,
8186
):
82-
self._endpoint = endpoint or _append_logs_path(
83-
environ.get(OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_ENDPOINT)
87+
self._endpoint = endpoint or environ.get(
88+
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT,
89+
_append_logs_path(
90+
environ.get(OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_ENDPOINT)
91+
),
8492
)
8593
self._certificate_file = certificate_file or environ.get(
86-
OTEL_EXPORTER_OTLP_CERTIFICATE, True
94+
OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE,
95+
environ.get(OTEL_EXPORTER_OTLP_CERTIFICATE, True),
96+
)
97+
headers_string = environ.get(
98+
OTEL_EXPORTER_OTLP_LOGS_HEADERS,
99+
environ.get(OTEL_EXPORTER_OTLP_HEADERS, ""),
87100
)
88-
headers_string = environ.get(OTEL_EXPORTER_OTLP_HEADERS, "")
89101
self._headers = headers or parse_env_headers(headers_string)
90102
self._timeout = timeout or int(
91-
environ.get(OTEL_EXPORTER_OTLP_TIMEOUT, DEFAULT_TIMEOUT)
103+
environ.get(
104+
OTEL_EXPORTER_OTLP_LOGS_TIMEOUT,
105+
environ.get(OTEL_EXPORTER_OTLP_TIMEOUT, DEFAULT_TIMEOUT),
106+
)
92107
)
93108
self._compression = compression or _compression_from_env()
94109
self._session = session or requests.Session()
@@ -170,7 +185,12 @@ def shutdown(self):
170185

171186
def _compression_from_env() -> Compression:
172187
compression = (
173-
environ.get(OTEL_EXPORTER_OTLP_COMPRESSION, "none").lower().strip()
188+
environ.get(
189+
OTEL_EXPORTER_OTLP_LOGS_COMPRESSION,
190+
environ.get(OTEL_EXPORTER_OTLP_COMPRESSION, "none"),
191+
)
192+
.lower()
193+
.strip()
174194
)
175195
return Compression(compression)
176196

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
OTEL_EXPORTER_OTLP_COMPRESSION,
6363
OTEL_EXPORTER_OTLP_ENDPOINT,
6464
OTEL_EXPORTER_OTLP_HEADERS,
65+
OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE,
66+
OTEL_EXPORTER_OTLP_LOGS_COMPRESSION,
67+
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT,
68+
OTEL_EXPORTER_OTLP_LOGS_HEADERS,
69+
OTEL_EXPORTER_OTLP_LOGS_TIMEOUT,
6570
OTEL_EXPORTER_OTLP_TIMEOUT,
6671
)
6772
from opentelemetry.sdk.resources import Resource as SDKResource
@@ -97,6 +102,38 @@ def test_constructor_default(self):
97102
"OTel-OTLP-Exporter-Python/" + __version__,
98103
)
99104

105+
@patch.dict(
106+
"os.environ",
107+
{
108+
OTEL_EXPORTER_OTLP_CERTIFICATE: ENV_CERTIFICATE,
109+
OTEL_EXPORTER_OTLP_COMPRESSION: Compression.Gzip.value,
110+
OTEL_EXPORTER_OTLP_ENDPOINT: ENV_ENDPOINT,
111+
OTEL_EXPORTER_OTLP_HEADERS: ENV_HEADERS,
112+
OTEL_EXPORTER_OTLP_TIMEOUT: ENV_TIMEOUT,
113+
OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE: "logs/certificate.env",
114+
OTEL_EXPORTER_OTLP_LOGS_COMPRESSION: Compression.Deflate.value,
115+
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: "https://logs.endpoint.env",
116+
OTEL_EXPORTER_OTLP_LOGS_HEADERS: "logsEnv1=val1,logsEnv2=val2,logsEnv3===val3==",
117+
OTEL_EXPORTER_OTLP_LOGS_TIMEOUT: "40",
118+
},
119+
)
120+
def test_exporter_metrics_env_take_priority(self):
121+
exporter = OTLPLogExporter()
122+
123+
self.assertEqual(exporter._endpoint, "https://logs.endpoint.env")
124+
self.assertEqual(exporter._certificate_file, "logs/certificate.env")
125+
self.assertEqual(exporter._timeout, 40)
126+
self.assertIs(exporter._compression, Compression.Deflate)
127+
self.assertEqual(
128+
exporter._headers,
129+
{
130+
"logsenv1": "val1",
131+
"logsenv2": "val2",
132+
"logsenv3": "==val3==",
133+
},
134+
)
135+
self.assertIsInstance(exporter._session, requests.Session)
136+
100137
@patch.dict(
101138
"os.environ",
102139
{

opentelemetry-api/src/opentelemetry/attributes/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ def _clean_attribute(
9797
return tuple(cleaned_seq)
9898

9999
_logger.warning(
100-
"Invalid type %s for attribute value. Expected one of %s or a "
100+
"Invalid type %s for attribute '%s' value. Expected one of %s or a "
101101
"sequence of those types",
102102
type(value).__name__,
103+
key,
103104
[valid_type.__name__ for valid_type in _VALID_ATTR_VALUE_TYPES],
104105
)
105106
return None

opentelemetry-api/src/opentelemetry/trace/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def start_as_current_span(
352352
353353
with tracer.start_as_current_span("one") as parent:
354354
parent.add_event("parent's event")
355-
with trace.start_as_current_span("two") as child:
355+
with tracer.start_as_current_span("two") as child:
356356
child.add_event("child's event")
357357
trace.get_current_span() # returns child
358358
trace.get_current_span() # returns parent
@@ -373,7 +373,7 @@ def start_as_current_span(
373373
374374
This can also be used as a decorator::
375375
376-
@tracer.start_as_current_span("name"):
376+
@tracer.start_as_current_span("name")
377377
def function():
378378
...
379379

0 commit comments

Comments
 (0)