Skip to content

Commit d8c07a0

Browse files
chore: added telemetry constants
1 parent 2619b3c commit d8c07a0

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/sap_cloud_sdk/core/telemetry/auto_instrument.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from sap_cloud_sdk.core.telemetry import Module, Operation
1717
from sap_cloud_sdk.core.telemetry.config import (
1818
create_resource_attributes_from_env,
19-
_get_app_name,
19+
_get_app_name, ENV_OTLP_ENDPOINT, ENV_TRACES_EXPORTER, ENV_OTLP_PROTOCOL,
2020
)
2121
from sap_cloud_sdk.core.telemetry.genai_attribute_transformer import (
2222
GenAIAttributeTransformer,
@@ -34,8 +34,8 @@ def auto_instrument():
3434
Traces are exported to the OTEL collector endpoint configured in environment with
3535
OTEL_EXPORTER_OTLP_ENDPOINT, or printed to console when OTEL_TRACES_EXPORTER=console.
3636
"""
37-
otel_endpoint = os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT", "")
38-
console_traces = os.getenv("OTEL_TRACES_EXPORTER", "").lower() == "console"
37+
otel_endpoint = os.getenv(ENV_OTLP_ENDPOINT, "")
38+
console_traces = os.getenv(ENV_TRACES_EXPORTER, "").lower() == "console"
3939

4040
if not otel_endpoint and not console_traces:
4141
logger.warning(
@@ -60,12 +60,12 @@ def auto_instrument():
6060

6161

6262
def _create_exporter() -> SpanExporter:
63-
if os.getenv("OTEL_TRACES_EXPORTER", "").lower() == "console":
63+
if os.getenv(ENV_TRACES_EXPORTER, "").lower() == "console":
6464
logger.info("Initializing auto instrumentation with console exporter")
6565
return ConsoleSpanExporter()
6666

67-
endpoint = os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT", "")
68-
protocol = os.getenv("OTEL_EXPORTER_OTLP_PROTOCOL", "grpc").lower()
67+
endpoint = os.getenv(ENV_OTLP_ENDPOINT, "")
68+
protocol = os.getenv(ENV_OTLP_PROTOCOL, "grpc").lower()
6969
exporters = {"grpc": GRPCSpanExporter, "http/protobuf": HTTPSpanExporter}
7070
if protocol not in exporters:
7171
raise ValueError(

src/sap_cloud_sdk/core/telemetry/config.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
ENV_HOSTNAME = "HOSTNAME"
3030
ENV_SYSTEM_ROLE = "APPFND_CONHOS_SYSTEM_ROLE"
3131

32+
#OTEL environment variable keys
33+
ENV_OTLP_ENDPOINT = "OTEL_EXPORTER_OTLP_ENDPOINT"
34+
ENV_TRACES_EXPORTER = "OTEL_TRACES_EXPORTER"
35+
ENV_OTLP_PROTOCOL = "OTEL_EXPORTER_OTLP_PROTOCOL"
36+
ENV_OTEL_DISABLED = "CLOUD_SDK_OTEL_DISABLED"
37+
3238

3339
def _get_region() -> str:
3440
"""Get region from environment or return default."""
@@ -134,13 +140,13 @@ def from_env(cls) -> "InstrumentationConfig":
134140
InstrumentationConfig instance with values from environment or defaults.
135141
"""
136142
# Get OTLP endpoint - if not set, telemetry is disabled
137-
otlp_endpoint = os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT", "")
143+
otlp_endpoint = os.getenv(ENV_OTLP_ENDPOINT, "")
138144

139145
# Enable telemetry only if endpoint is configured
140146
# Can be explicitly disabled with CLOUD_SDK_OTEL_DISABLED=true
141147
enabled = (
142148
bool(otlp_endpoint)
143-
and os.getenv("CLOUD_SDK_OTEL_DISABLED", "false").lower() != "true"
149+
and os.getenv(ENV_OTEL_DISABLED, "false").lower() != "true"
144150
)
145151

146152
return cls(

0 commit comments

Comments
 (0)