Skip to content

Commit

Permalink
Test CI 2 (#130)
Browse files Browse the repository at this point in the history
* Test CI 2

* Update notify-api-ci.codecov.yaml

* Test CI 2

* Improve logging.

* Test CI 2

* Improve logging.
  • Loading branch information
pwei1018 authored Apr 26, 2024
1 parent 2fee6d1 commit 9a5ba8e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion notify-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ By participating in this project you agree to abide by its terms.
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
13 changes: 10 additions & 3 deletions notify-api/src/notify_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from flask import Flask
from flask_cors import CORS
from flask_migrate import Migrate
from flask_migrate import Migrate, upgrade
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.instrumentation.wsgi import OpenTelemetryMiddleware
Expand All @@ -31,7 +31,7 @@
from notify_api.resources import TRACING_EXCLUED_URLS, v1_endpoint, v2_endpoint
from notify_api.translations import babel
from notify_api.utils.auth import jwt
from notify_api.utils.logging import setup_logging
from notify_api.utils.logging import logger, setup_logging
from notify_api.utils.tracing import init_trace

setup_logging(os.path.join(os.path.abspath(os.path.dirname(__file__)), "logging.yaml")) # important to do this first
Expand All @@ -48,13 +48,20 @@ def create_app(service_environment=APP_RUNNING_ENVIRONMENT, **kwargs):
db.init_app(app)
Migrate(app, db)

logger.info("Running migration upgrade.")
with app.app_context():
upgrade(directory="migrations", revision="head", sql=False, tag=None)
# Alembic has it's own logging config, we'll need to restore our logging here.
setup_logging(os.path.join(os.path.abspath(os.path.dirname(__file__)), "logging.yaml"))
logger.info("Finished migration upgrade.")

if app.config.get("TRACING_ENABLE", None):
init_trace(service_name=APP_NAME, service_environment=service_environment, service_project=APP_RUNNING_PROJECT)
with app.app_context():
app.wsgi_app = OpenTelemetryMiddleware(app.wsgi_app)

FlaskInstrumentor().instrument_app(app, excluded_urls=",".join(TRACING_EXCLUED_URLS))
# RequestsInstrumentor().instrument()
RequestsInstrumentor().instrument()

babel.init_app(app)

Expand Down
5 changes: 5 additions & 0 deletions notify-api/src/notify_api/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@
import logging.config
from datetime import date, datetime
from inspect import getframeinfo, stack
from logging import NullHandler

import yaml
from opentelemetry.instrumentation.logging import LoggingInstrumentor

from notify_api.metadata import APP_RUNNING_PROJECT

LoggingInstrumentor().instrument(set_logging_format=True)


def setup_logging(conf):
"""Create the services logger."""
Expand Down Expand Up @@ -85,6 +89,7 @@ def __init__(self, log_level=logging.INFO):
self.logger.setLevel(log_level)
self.logger.addFilter(CallerFilter())
self.logger.addFilter(LoggingFormatFilter())
self.logger.addHandler(NullHandler())

@caller_reader
def debug(self, msg: str, additional=None):
Expand Down

0 comments on commit 9a5ba8e

Please sign in to comment.