Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions Azure/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## 2026-02-13 - 2.9.3

### Added

- Add the ability to set log level for any loggers in the Azure EventHub connector

## 2025-12-10 - 2.9.2

### Fixed
Expand Down
4 changes: 4 additions & 0 deletions Azure/connectors/azure_eventhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
from sekoia_automation.aio.connector import AsyncConnector
from sekoia_automation.connector import Connector, DefaultConnectorConfiguration

from .logging import set_log_level_from_env
from .metrics import EVENTS_LAG, FORWARD_EVENTS_DURATION, INCOMING_MESSAGES, MESSAGES_AGE, OUTCOMING_EVENTS

# Initialize log level from environment variables
set_log_level_from_env()

Comment on lines +17 to +22
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

Calling set_log_level_from_env() at module import introduces a global side effect and can make simply importing this module fail depending on environment variables. Prefer invoking this during connector startup (e.g., in AzureEventsHubTrigger.__init__/run) after logging is configured, so behavior is deterministic and easier to test.

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +22
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

This new env-driven logging behavior isn’t covered by tests. Since Azure/tests/connector/test_azure_eventhub.py already exists, add unit tests that verify: (1) valid values change the expected logger levels, (2) AZURE_LOGGERS selection works, and (3) invalid AZURE_LOG_LEVEL values don’t crash startup.

Copilot uses AI. Check for mistakes.

class AzureEventsHubConfiguration(DefaultConnectorConfiguration):
hub_connection_string: str
Expand Down
38 changes: 38 additions & 0 deletions Azure/connectors/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import logging
import os


def set_log_level(loggers: set[str], log_level: int) -> None:
"""
Set the log level for the specified loggers.

:param loggers: A set of logger names to set the log level for.
:param log_level: The log level to set for the specified loggers.
"""
for logger in loggers:
logging.getLogger(logger.strip()).setLevel(log_level)


def set_log_level_from_env() -> None:
"""
Set the log level for the specified loggers based on the AZURE_LOG_LEVEL and AZURE_LOGGERS environment variables.

AZURE_LOG_LEVEL should be set to the desired log level (e.g., 10 for DEBUG, 20 for INFO, etc.).
AZURE_LOGGERS should be a comma-separated list of logger names to set the log level for. If AZURE_LOGGERS is not set, the log level will be set for all loggers.
"""
# If AZURE_LOG_LEVEL is not set, do not change the log level for any loggers.
if os.environ.get("AZURE_LOG_LEVEL") is None:
return

loggers = None

# If AZURE_LOGGERS is set, use the specified loggers. Otherwise, use all loggers.
if os.environ.get("AZURE_LOGGERS") is not None:
loggers = set(os.environ["AZURE_LOGGERS"].split(","))

# If AZURE_LOGGERS is not set, use all loggers.
if loggers is None:
Comment on lines +27 to +34
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

loggers = None is later reassigned to a set, which is a type inconsistency and will trip strict type-checking; annotate it as set[str] | None (or avoid the sentinel by initializing to an empty set). Also, when AZURE_LOGGERS is an empty string, split(",") yields "" and ends up modifying the root logger unintentionally—filter out empty names.

Suggested change
loggers = None
# If AZURE_LOGGERS is set, use the specified loggers. Otherwise, use all loggers.
if os.environ.get("AZURE_LOGGERS") is not None:
loggers = set(os.environ.get("AZURE_LOGGERS").split(","))
# If AZURE_LOGGERS is not set, use all loggers.
if loggers is None:
loggers_env = os.environ.get("AZURE_LOGGERS")
# If AZURE_LOGGERS is set and non-empty, use the specified loggers (excluding empty names).
if loggers_env:
loggers: set[str] = {name.strip() for name in loggers_env.split(",") if name.strip()}
else:
# If AZURE_LOGGERS is not set or empty, use all loggers.

Copilot uses AI. Check for mistakes.
loggers = set(logging.root.manager.loggerDict.keys())

# Set the log level for the specified loggers.
set_log_level(loggers, int(os.environ["AZURE_LOG_LEVEL"]))
6 changes: 2 additions & 4 deletions Azure/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"name": "Microsoft Azure",
"uuid": "525eecc0-9eee-484d-92bd-039117cf4dac",
"slug": "azure",
"version": "2.9.2",
"categories": [
"Cloud Providers"
]
"version": "2.9.3",
"categories": ["Cloud Providers"]
}