Skip to content

Commit

Permalink
add debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
seemk committed Oct 30, 2023
1 parent a335ce4 commit aca9fa0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
8 changes: 2 additions & 6 deletions splunk_otel/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
from typing import Any, Dict

Expand All @@ -24,12 +23,9 @@
from splunk_otel.profiling import _start_profiling
from splunk_otel.profiling.options import _Options as ProfilingOptions
from splunk_otel.tracing import _configure_tracing
from splunk_otel.util import _is_truthy
from splunk_otel.util import _get_logger, _is_truthy

otel_log_level = os.environ.get("OTEL_LOG_LEVEL", logging.INFO)

logger = logging.getLogger(__file__)
logger.setLevel(otel_log_level)
logger = _get_logger(__name__)


class _SplunkDistro(BaseDistro):
Expand Down
8 changes: 2 additions & 6 deletions splunk_otel/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os

from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter
Expand All @@ -21,12 +20,9 @@
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader

from splunk_otel.util import _is_truthy
from splunk_otel.util import _get_logger, _is_truthy

otel_log_level = os.environ.get("OTEL_LOG_LEVEL", logging.INFO)

logger = logging.getLogger(__file__)
logger.setLevel(otel_log_level)
logger = _get_logger(__name__)


def start_metrics() -> MeterProvider:
Expand Down
9 changes: 9 additions & 0 deletions splunk_otel/profiling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import base64
import gzip
import os
import sys
import threading
import time
Expand All @@ -35,8 +36,11 @@
import splunk_otel
from splunk_otel.profiling import profile_pb2
from splunk_otel.profiling.options import _Options
from splunk_otel.util import _get_logger
from splunk_otel.version import __version__

logger = _get_logger(__name__)

thread_states = {}
batch_processor = None

Expand Down Expand Up @@ -247,6 +251,11 @@ def _force_flush():


def _start_profiling(options):
logger.debug(
"starting profiling call_stack_interval=%s endpoint=%s",
options.call_stack_interval,
options.endpoint,
)
wrapt.wrap_function_wrapper(
"opentelemetry.context", "attach", _wrapped_context_attach
)
Expand Down
8 changes: 2 additions & 6 deletions splunk_otel/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
import sys
from typing import Collection, Dict, Optional, Union
Expand All @@ -27,12 +26,9 @@
from pkg_resources import iter_entry_points

from splunk_otel.options import _Options, _SpanExporterFactory
from splunk_otel.util import _is_truthy
from splunk_otel.util import _get_logger, _is_truthy

otel_log_level = os.environ.get("OTEL_LOG_LEVEL", logging.INFO)

logger = logging.getLogger(__file__)
logger.setLevel(otel_log_level)
logger = _get_logger(__name__)


def start_tracing(
Expand Down
24 changes: 24 additions & 0 deletions splunk_otel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
from typing import Any


def _is_truthy(value: Any) -> bool:
if isinstance(value, str):
value = value.lower().strip()
return value in [True, 1, "true", "yes"]


def _get_log_level(level):
levels = {
"none": logging.NOTSET,
"debug": logging.DEBUG,
"info": logging.INFO,
"warn": logging.WARNING,
"error": logging.ERROR,
"fatal": logging.CRITICAL,
}

return levels[level.lower()]


def _get_logger(name):
level = _get_log_level(os.environ.get("OTEL_LOG_LEVEL", "info"))
logger = logging.getLogger(name)
logger.setLevel(level)
logger.addHandler(logging.StreamHandler())

return logger

0 comments on commit aca9fa0

Please sign in to comment.