Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions datareservoirio/_logging.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import logging
import os
from functools import wraps, cache
from functools import cache, wraps

from opencensus.ext.azure.log_exporter import AzureLogHandler
from azure.monitor.opentelemetry import configure_azure_monitor

import datareservoirio as drio

from ._constants import ENV_VAR_ENABLE_APP_INSIGHTS, ENV_VAR_ENGINE_ROOM_APP_ID
from .globalsettings import environment


@cache
def get_exceptions_logger() -> logging.Logger:
exceptions_logger = logging.getLogger(__name__ + "_exception_logger")
Expand All @@ -17,13 +18,15 @@ def get_exceptions_logger() -> logging.Logger:
if os.getenv(ENV_VAR_ENABLE_APP_INSIGHTS) is not None:
enable_app_insights = os.environ[ENV_VAR_ENABLE_APP_INSIGHTS].lower()
if enable_app_insights == "true" or enable_app_insights == "1":
app_insight_handler = AzureLogHandler(
connection_string=environment._application_insight_connectionstring
configure_azure_monitor(
connection_string=environment._application_insight_connectionstring,
logger_name=__name__ + "_exceptions_logger",
)
app_insight_handler.setLevel("WARNING")
exceptions_logger.addHandler(app_insight_handler)
exceptions_logger.setLevel("WARNING")

return exceptions_logger


def log_decorator(log_level):
def decorator(func):
@wraps(func)
Expand Down
11 changes: 7 additions & 4 deletions datareservoirio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from collections import defaultdict
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from functools import wraps, cache
from functools import cache, wraps
from operator import itemgetter
from urllib.parse import urlencode
from uuid import uuid4

import numpy as np
import pandas as pd
import requests
from opencensus.ext.azure.log_exporter import AzureLogHandler
from azure.monitor.opentelemetry import configure_azure_monitor
from tenacity import (
retry,
retry_if_exception_type,
Expand All @@ -29,15 +29,18 @@

log = logging.getLogger(__name__)


@cache
def metric() -> logging.Logger:
logger = logging.getLogger(__name__ + "_metric_appinsight")
logger.setLevel(logging.DEBUG)
logger.addHandler(
AzureLogHandler(connection_string=environment._application_insight_connectionstring)
configure_azure_monitor(
connection_string=environment._application_insight_connectionstring,
logger_name=__name__ + "_metric_appinsight",
)
return logger


# Default values to push as start/end dates. (Limited by numpy.datetime64)
_END_DEFAULT = 9214646400000000000 # 2262-01-01
_START_DEFAULT = -9214560000000000000 # 1678-01-01
Expand Down
45 changes: 22 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,32 @@ build-backend = "setuptools.build_meta"

[project]
name = "datareservoirio"
authors = [
{ name="4Subsea", email="support@4subsea.com" }
]
authors = [{ name = "4Subsea", email = "support@4subsea.com" }]
dynamic = ["version"]
description = "DataReservoir.io Python API"
readme = "README.rst"
license = { file="LICENSE" }
license = { file = "LICENSE" }
requires-python = ">3.10"
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"numpy",
"oauthlib",
"pandas",
"pyarrow",
"requests",
"requests-oauthlib",
"importlib_resources",
"opencensus-ext-azure",
"tenacity<8.5",
"urllib3 > 2",
"tqdm"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

azure-monitor-opentelemetry

"numpy",
"oauthlib",
"pandas",
"pyarrow",
"requests",
"requests-oauthlib",
"importlib_resources",
"tenacity<8.5",
"urllib3 > 2",
"tqdm",
"azure-monitor-opentelemetry",
]

[project.urls]
Expand All @@ -45,7 +43,7 @@ include = ["datareservoirio*"]
namespaces = false

[tool.setuptools.dynamic]
version = {attr = "datareservoirio.__version__"}
version = { attr = "datareservoirio.__version__" }

[tool.pytest.ini_options]
pythonpath = [".", "src"]
Expand Down Expand Up @@ -74,4 +72,5 @@ deps =
sphinx==5.3.0
pydata-sphinx-theme==0.11.0
myst_parser<2.0
"""
"""

4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
@pytest.fixture(autouse=True)
def disable_logging(monkeypatch):
"""Disable logging to Application Insight"""
monkeypatch.setattr("datareservoirio.client.AzureLogHandler", logging.NullHandler())


# monkeypatch.setattr("datareservoirio.client.AzureLogHandler", logging.NullHandler())
Comment thread
bjorn-einar-bjartnes-4ss marked this conversation as resolved.
Outdated


@pytest.fixture
Expand Down
4 changes: 3 additions & 1 deletion tests/test__logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import pytest

from datareservoirio._logging import exceptions_logger, log_decorator
from datareservoirio._logging import get_exceptions_logger, log_decorator

exceptions_logger = get_exceptions_logger()


class my_test_class:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
from tenacity import RetryError

import datareservoirio as drio
from datareservoirio._logging import exceptions_logger
from datareservoirio._logging import get_exceptions_logger
from datareservoirio._utils import DataHandler

TEST_PATH = Path(__file__).parent

exceptions_logger = get_exceptions_logger()


def change_logging(self, msg, *args, exc_info=True, **kwargs):
if kwargs["extra"]:
Expand Down