Skip to content

Commit

Permalink
connection string
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKallekleiv committed Nov 18, 2023
1 parent 10f22b6 commit 75d44df
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
71 changes: 40 additions & 31 deletions backend/src/backend/primary/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,46 @@
logging.getLogger("src.services.sumo_access").setLevel(level=logging.DEBUG)
logging.getLogger("src.backend.primary.routers.surface").setLevel(level=logging.DEBUG)

from logging import INFO, getLogger

from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor(
logger_name="my_application_logger",
)

# Logging calls with this logger will be tracked
logger = getLogger("my_application_logger")
logger.setLevel(INFO)

# Logging calls with any logger that is a child logger will also be tracked
logger_child = getLogger("my-application_logger.module")
logger_child.setLevel(INFO)

# Logging calls with this logger will not be tracked
logger_not_tracked = getLogger("not_my_application_logger")
logger_not_tracked.setLevel(INFO)

logger.info("info log")
logger.warning("warning log")
logger.error("error log")

logger.info("info log")
logger.warning("warning log")
logger.error("error log")

logger_not_tracked.info("info log2")
logger_not_tracked.warning("warning log2")
logger_not_tracked.error("error log2")
from src.config import APPLICATIONINSIGHTS_CONNECTION_STRING

if APPLICATIONINSIGHTS_CONNECTION_STRING:
from azure.monitor.opentelemetry import configure_azure_monitor

from logging import INFO, getLogger

# Test
configure_azure_monitor(
connection_string=APPLICATIONINSIGHTS_CONNECTION_STRING,
logger_name="my_application_logger",
)

logger = getLogger("my_application_logger")
logger.setLevel(INFO)

logger_child = getLogger("my-application_logger.module")
logger_child.setLevel(INFO)

logger_not_tracked = getLogger("not_my_application_logger")
logger_not_tracked.setLevel(INFO)

logger.info("info log")
logger.warning("warning log")
logger.error("error log")

logger.info("info log")
logger.warning("warning log")
logger.error("error log")

logger_not_tracked.info("info log2")
logger_not_tracked.warning("warning log2")
logger_not_tracked.error("error log2")
# Log all
configure_azure_monitor(
connection_string=APPLICATIONINSIGHTS_CONNECTION_STRING,
logger_name="src",
)
else:
print("No APPLICATIONINSIGHTS_CONNECTION_STRING found, skipping telemetry configuration.")


def custom_generate_unique_id(route: APIRoute) -> str:
Expand Down
2 changes: 1 addition & 1 deletion backend/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
SMDA_RESOURCE_SCOPE = os.environ["WEBVIZ_SMDA_RESOURCE_SCOPE"]
SUMO_ENV = os.getenv("WEBVIZ_SUMO_ENV", "prod")
GRAPH_SCOPES = ["User.Read", "User.ReadBasic.All"]

APPLICATIONINSIGHTS_CONNECTION_STRING = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
RESOURCE_SCOPES_DICT = {
"sumo": [f"api://{sumo_app_reg[SUMO_ENV]['RESOURCE_ID']}/access_as_user"],
"smda": [SMDA_RESOURCE_SCOPE],
Expand Down

0 comments on commit 75d44df

Please sign in to comment.