Skip to content

Commit 48e766b

Browse files
committed
Adds environment variables for log exporter
1 parent 787e499 commit 48e766b

File tree

2 files changed

+92
-0
lines changed
  • exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter
  • opentelemetry-sdk/src/opentelemetry/sdk

2 files changed

+92
-0
lines changed

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

+38
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,14 @@
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+
)
3748

3849
class OTLPLogExporter(
3950
LogExporter,
@@ -52,6 +63,33 @@ def __init__(
5263
timeout: Optional[int] = None,
5364
compression: Optional[Compression] = None,
5465
):
66+
if insecure is None:
67+
insecure = environ.get(OTEL_EXPORTER_OTLP_LOGS_INSECURE)
68+
if insecure is not None:
69+
insecure = insecure.lower() == "true"
70+
71+
if (
72+
not insecure
73+
and environ.get(OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE) is not None
74+
):
75+
credentials = _get_credentials(
76+
credentials, OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE
77+
)
78+
79+
environ_timeout = environ.get(OTEL_EXPORTER_OTLP_LOGS_TIMEOUT)
80+
environ_timeout = (
81+
int(environ_timeout) if environ_timeout is not None else None
82+
)
83+
84+
compression = (
85+
environ_to_compression(OTEL_EXPORTER_OTLP_LOGS_COMPRESSION)
86+
if compression is None
87+
else compression
88+
)
89+
endpoint=endpoint or environ.get(OTEL_EXPORTER_OTLP_LOGS_ENDPOINT),
90+
91+
headers=headers or environ.get(OTEL_EXPORTER_OTLP_LOGS_HEADERS),
92+
5593
super().__init__(
5694
**{
5795
"endpoint": endpoint,

opentelemetry-sdk/src/opentelemetry/sdk/environment_variables.py

+54
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,15 @@
344344
A scheme of https indicates a secure connection and takes precedence over this configuration setting.
345345
"""
346346

347+
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT"
348+
"""
349+
.. envvar:: OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
350+
351+
The :envvar:`OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` target to which the log exporter is going to send logs.
352+
The endpoint MUST be a valid URL host, and MAY contain a scheme (http or https), port and path.
353+
A scheme of https indicates a secure connection and takes precedence over this configuration setting.
354+
"""
355+
347356
OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE = "OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE"
348357
"""
349358
.. envvar:: OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE
@@ -378,6 +387,14 @@
378387
associated with gRPC or HTTP requests.
379388
"""
380389

390+
OTEL_EXPORTER_OTLP_LOGS_HEADERS = "OTEL_EXPORTER_OTLP_LOGS_HEADERS"
391+
"""
392+
.. envvar:: OTEL_EXPORTER_OTLP_LOGS_HEADERS
393+
394+
The :envvar:`OTEL_EXPORTER_OTLP_LOGS_HEADERS` contains the key-value pairs to be used as headers for logs
395+
associated with gRPC or HTTP requests.
396+
"""
397+
381398
OTEL_EXPORTER_OTLP_TRACES_COMPRESSION = "OTEL_EXPORTER_OTLP_TRACES_COMPRESSION"
382399
"""
383400
.. envvar:: OTEL_EXPORTER_OTLP_TRACES_COMPRESSION
@@ -396,6 +413,16 @@
396413
exporter. If both are present, this takes higher precedence.
397414
"""
398415

416+
OTEL_EXPORTER_OTLP_LOGS_COMPRESSION = (
417+
"OTEL_EXPORTER_OTLP_LOGS_COMPRESSION"
418+
)
419+
"""
420+
.. envvar:: OTEL_EXPORTER_OTLP_LOGS_COMPRESSION
421+
422+
Same as :envvar:`OTEL_EXPORTER_OTLP_COMPRESSION` but only for the log
423+
exporter. If both are present, this takes higher precedence.
424+
"""
425+
399426
OTEL_EXPORTER_OTLP_TRACES_TIMEOUT = "OTEL_EXPORTER_OTLP_TRACES_TIMEOUT"
400427
"""
401428
.. envvar:: OTEL_EXPORTER_OTLP_TRACES_TIMEOUT
@@ -421,6 +448,15 @@
421448
Default: False
422449
"""
423450

451+
OTEL_EXPORTER_OTLP_LOGS_INSECURE = "OTEL_EXPORTER_OTLP_LOGS_INSECURE"
452+
"""
453+
.. envvar:: OTEL_EXPORTER_OTLP_LOGS_INSECURE
454+
455+
The :envvar:`OTEL_EXPORTER_OTLP_LOGS_INSECURE` represents whether to enable client transport security
456+
for gRPC requests for metrics. A scheme of https takes precedence over the this configuration setting.
457+
Default: False
458+
"""
459+
424460
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT"
425461
"""
426462
.. envvar:: OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
@@ -440,6 +476,16 @@
440476
TLS credentials of gRPC client for traces. Should only be used for a secure connection for tracing.
441477
"""
442478

479+
OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE = (
480+
"OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE"
481+
)
482+
"""
483+
.. envvar:: OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE
484+
485+
The :envvar:`OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE` stores the path to the certificate file for
486+
TLS credentials of gRPC client for traces. Should only be used for a secure connection for tracing.
487+
"""
488+
443489
OTEL_EXPORTER_OTLP_METRICS_HEADERS = "OTEL_EXPORTER_OTLP_METRICS_HEADERS"
444490
"""
445491
.. envvar:: OTEL_EXPORTER_OTLP_METRICS_HEADERS
@@ -456,6 +502,14 @@
456502
wait for each batch export for metrics.
457503
"""
458504

505+
OTEL_EXPORTER_OTLP_LOGS_TIMEOUT = "OTEL_EXPORTER_OTLP_LOGS_TIMEOUT"
506+
"""
507+
.. envvar:: OTEL_EXPORTER_OTLP_LOGS_TIMEOUT
508+
509+
The :envvar:`OTEL_EXPORTER_OTLP_LOGS_TIMEOUT` is the maximum time the OTLP exporter will
510+
wait for each batch export for logs.
511+
"""
512+
459513
OTEL_EXPORTER_OTLP_METRICS_COMPRESSION = (
460514
"OTEL_EXPORTER_OTLP_METRICS_COMPRESSION"
461515
)

0 commit comments

Comments
 (0)