Skip to content

Commit

Permalink
import types
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Nov 15, 2024
1 parent f803a3c commit 2f8d6b2
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions ddtrace/settings/_otel_remapper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import os
import typing
from typing import Callable
from typing import Dict
from typing import List
from typing import Literal
from typing import Optional
from typing import Tuple

from ..constants import ENV_KEY
from ..constants import VERSION_KEY
Expand All @@ -17,14 +22,14 @@
}


def _remap_otel_log_level(otel_value: str) -> typing.Optional[str]:
def _remap_otel_log_level(otel_value: str) -> Optional[str]:
"""Remaps the otel log level to ddtrace log level"""
if otel_value == "debug":
return "True"
return None


def _remap_otel_propagators(otel_value: str) -> typing.Optional[str]:
def _remap_otel_propagators(otel_value: str) -> Optional[str]:
"""Remaps the otel propagators to ddtrace propagators"""
accepted_styles = []
for style in otel_value.split(","):
Expand All @@ -37,7 +42,7 @@ def _remap_otel_propagators(otel_value: str) -> typing.Optional[str]:
return ",".join(accepted_styles)


def _remap_traces_sampler(otel_value: str) -> typing.Optional[str]:
def _remap_traces_sampler(otel_value: str) -> Optional[str]:
"""Remaps the otel trace sampler to ddtrace trace sampler"""
if otel_value in ["always_on", "always_off", "traceidratio"]:
log.warning(
Expand All @@ -55,33 +60,33 @@ def _remap_traces_sampler(otel_value: str) -> typing.Optional[str]:
return None


def _remap_traces_exporter(otel_value: str) -> typing.Optional[str]:
def _remap_traces_exporter(otel_value: str) -> Optional[str]:
"""Remaps the otel trace exporter to ddtrace trace enabled"""
if otel_value == "none":
return "False"
return None


def _remap_metrics_exporter(otel_value: str) -> typing.Optional[str]:
def _remap_metrics_exporter(otel_value: str) -> Optional[str]:
"""Remaps the otel metrics exporter to ddtrace metrics exporter"""
if otel_value == "none":
return "False"
return None


def _validate_logs_exporter(otel_value: str) -> typing.Literal["", None]:
def _validate_logs_exporter(otel_value: str) -> Literal["", None]:
"""Logs warning when OTEL Logs exporter is configured. DDTRACE does not support this configuration."""
if otel_value == "none":
return ""
return None


def _remap_otel_tags(otel_value: str) -> typing.Optional[str]:
def _remap_otel_tags(otel_value: str) -> Optional[str]:
"""Remaps the otel tags to ddtrace tags"""
dd_tags: typing.List[str] = []
dd_tags: List[str] = []

try:
otel_user_tag_dict: typing.Dict[str, str] = dict()
otel_user_tag_dict: Dict[str, str] = dict()
for tag in otel_value.split(","):
key, value = tag.split("=")
otel_user_tag_dict[key] = value
Expand All @@ -106,7 +111,7 @@ def _remap_otel_tags(otel_value: str) -> typing.Optional[str]:
return ",".join(dd_tags)


def _remap_otel_sdk_config(otel_value: str) -> typing.Optional[str]:
def _remap_otel_sdk_config(otel_value: str) -> Optional[str]:
"""Remaps the otel sdk config to ddtrace sdk config"""
if otel_value == "false":
return "True"
Expand All @@ -115,12 +120,12 @@ def _remap_otel_sdk_config(otel_value: str) -> typing.Optional[str]:
return None


def _remap_default(otel_value: str) -> typing.Optional[str]:
def _remap_default(otel_value: str) -> Optional[str]:
"""Remaps the otel default value to ddtrace default value"""
return otel_value


ENV_VAR_MAPPINGS: typing.Dict[str, typing.Tuple[str, typing.Callable[[str], typing.Optional[str]]]] = {
ENV_VAR_MAPPINGS: Dict[str, Tuple[str, Callable[[str], Optional[str]]]] = {
"OTEL_SERVICE_NAME": ("DD_SERVICE", _remap_default),
"OTEL_LOG_LEVEL": ("DD_TRACE_DEBUG", _remap_otel_log_level),
"OTEL_PROPAGATORS": ("DD_TRACE_PROPAGATION_STYLE", _remap_otel_propagators),
Expand Down

0 comments on commit 2f8d6b2

Please sign in to comment.