Skip to content

Commit

Permalink
implement rollbar
Browse files Browse the repository at this point in the history
  • Loading branch information
beiciliang committed Feb 28, 2023
1 parent a5a476e commit 126dab3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
34 changes: 31 additions & 3 deletions backend-flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
import logging
from time import strftime

# rollbar
import rollbar
import rollbar.contrib.flask
from flask import got_request_exception

# # Configuring Logger to Use CloudWatch
# # Comment for saving AWS budget
# LOGGER = logging.getLogger(__name__)
Expand All @@ -52,9 +57,9 @@
provider = TracerProvider()
processor = BatchSpanProcessor(OTLPSpanExporter())
provider.add_span_processor(processor)
# Show this in the logs within the backend-flask app (STDOUT)
simple_processor = SimpleSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(simple_processor)
# # Show this in the logs within the backend-flask app (STDOUT)
# simple_processor = SimpleSpanProcessor(ConsoleSpanExporter())
# provider.add_span_processor(simple_processor)
trace.set_tracer_provider(provider)
tracer = trace.get_tracer(__name__)

Expand Down Expand Up @@ -85,6 +90,29 @@
# LOGGER.error('%s %s %s %s %s %s', timestamp, request.remote_addr, request.method, request.scheme, request.full_path, response.status)
# return response

# rollbar
rollbar_access_token = os.getenv('ROLLBAR_ACCESS_TOKEN')
@app.before_first_request
def init_rollbar():
"""init rollbar module"""
rollbar.init(
# access token
rollbar_access_token,
# environment name
'production',
# server root directory, makes tracebacks prettier
root=os.path.dirname(os.path.realpath(__file__)),
# flask already sets up logging
allow_logging_basic_config=False)

# send exceptions from `app` to rollbar, using flask's signal system.
got_request_exception.connect(rollbar.contrib.flask.report_exception, app)

@app.route('/rollbar/test')
def rollbar_test():
rollbar.report_message('Hello World!', 'warning')
return "Hello World!"

@app.route("/api/message_groups", methods=['GET'])
def data_message_groups():
user_handle = 'andrewbrown'
Expand Down
2 changes: 2 additions & 0 deletions backend-flask/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ opentelemetry-instrumentation-flask
opentelemetry-instrumentation-requests
aws-xray-sdk
watchtower
blinker
rollbar
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
AWS_DEFAULT_REGION: "${AWS_DEFAULT_REGION}"
AWS_ACCESS_KEY_ID: "${AWS_ACCESS_KEY_ID}"
AWS_SECRET_ACCESS_KEY: "${AWS_SECRET_ACCESS_KEY}"
ROLLBAR_ACCESS_TOKEN: "${ROLLBAR_ACCESS_TOKEN}"
build: ./backend-flask
ports:
- "4567:4567"
Expand Down

0 comments on commit 126dab3

Please # to comment.