Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce AppInsights verbosity #202

Merged
merged 1 commit into from May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions opwen_email_server/integration/wsgi.py
Expand Up @@ -21,6 +21,7 @@ def build_app(apis, host=_host, port=_port, ui=_ui):

app.app.config['APPINSIGHTS_INSTRUMENTATIONKEY'] = config.APPINSIGHTS_KEY
app.app.config['APPINSIGHTS_ENDPOINT_URI'] = config.APPINSIGHTS_HOST
app.app.config['APPINSIGHTS_DISABLE_TRACE_LOGGING'] = True
AppInsights(app.app)

return app
Expand Down
11 changes: 3 additions & 8 deletions opwen_email_server/utils/log.py
Expand Up @@ -6,6 +6,7 @@
from logging import Handler
from logging import Logger
from logging import StreamHandler
from logging import getLevelName
from logging import getLogger
from typing import Any
from typing import Iterable
Expand All @@ -16,7 +17,6 @@
from applicationinsights.channel import AsynchronousSender
from applicationinsights.channel import NullSender
from applicationinsights.channel import TelemetryChannel
from applicationinsights.logging import LoggingHandler
from cached_property import cached_property

from opwen_email_server.config import APPINSIGHTS_HOST
Expand Down Expand Up @@ -51,10 +51,6 @@ def _default_log_handlers(self) -> Iterable[Handler]:
stderr.setFormatter(Formatter(STDERR))
handlers.append(stderr)

handlers.append(LoggingHandler(
self._telemetry_key,
telemetry_channel=self._telemetry_channel))

return handlers

@cached_property
Expand Down Expand Up @@ -98,9 +94,8 @@ def _log(self, level: int, log_message: str, log_args: Iterable[Any]):
args.extend(log_args)
message = SEPARATOR.join(message_parts)
self._logger.log(level, message, *args)
self._telemetry_client.track_trace(message % tuple(args), severity=getLevelName(level))

def log_event(self, event_name: str, properties: Optional[dict] = None):
self.log_info('%s%s%s', event_name, SEPARATOR, properties)

self._logger.info('%s%s%s', event_name, SEPARATOR, properties)
self._telemetry_client.track_event(event_name, properties)
self._telemetry_channel.flush()