Skip to content

Latest commit

 

History

History
233 lines (170 loc) · 4.77 KB

File metadata and controls

233 lines (170 loc) · 4.77 KB

Python package

raven

A rather opinionated tool to raise alerts and report data.

She is watching your application with great concern

Table of Contents

Introduction

Installation

pip install git+http://git@github.com/tapway/raven.git

What it produces

This is what you get from the default settings, you can also choose to extend this with the barebone API.

Basic Example

from raven.utils import alert

@alert(
    config_path="raven_config.yaml"
)
def division(a, b):
    x = a / b

division(1, 0)

Documentation

Using with configuration file

With AWS Secrets Manager

  1. Create a secret in AWS secret manager with BOT_TOKEN variable in the secret
  2. Make sure the machine/pod/container has appropriate permissions to get secrets from AWS Secrets Manager
  3. You have your config yaml file in correct directory

Example yaml file,

channels:
  alert_channel: CXXXXXXXXXX # can be obtained from slack channel settings
cloudwatch: <IF YOU HAVE A CLOUDWATH PREFIX URL | OPTIONAL>
service: <YOUR SERVICE NAME | OPTIONAL>
params: <IF YOU WISH TO HAVE INPUT PARAMS | OPTIONAL>
aws_sm_secret: <YOUR SECRET NAME>
aws_region: <YOUR AWS REGION>

Note: For cloudwatch link to work, your app should be running in a kubernetes cluster, otherwise, it will skip sending the cloudwatch link.

Automatic alert

Sends alert to the first channel in the yaml file,

from raven.utils import alert

@alert(
    config_path="raven_config.yaml"
)
def division(**kwargs):
    x = kwargs.get("a") / kwargs.get("b")

division(a=1, b=0)

Sends alert to specified channel in the yaml file,

from raven.utils import alert

@alert(
    config_path="raven_config.yaml",
    channel="alert_channel"
)
def division(**kwargs):
    x = kwargs.get("a") / kwargs.get("b")

division(a=1, b=0)

In try-catch

from raven.utils import send_alert

def division(**kwargs):
    try:
        x = kwargs.get("a") / kwargs.get("b")
    except Exception:
        # for raven to catch this error
        send_alert_with_config(
            config_path="raven_config.yaml"
        )

division(a=1, b=0)

With token

Example yaml file,

channels:
  alert_channel: CXXXXXXXXXX # can be obtained from slack channel settings
cloudwatch: <IF YOU HAVE A CLOUDWATH PREFIX URL | OPTIONAL>
service: <YOUR SERVICE NAME | OPTIONAL>
params: <IF YOU WISH TO HAVE INPUT PARAMS | OPTIONAL>

Note: For cloudwatch link to work, your app should be running in a kubernetes cluster, otherwise, it will skip sending the cloudwatch link.

Automatic alert

Sends alert to the first channel in the yaml file,

from raven.utils import alert

@alert(
    config_path="raven_config.yaml",
    token=<BOT_TOKEN>
)
def division(**kwargs):
    x = kwargs.get("a") / kwargs.get("b")

division(a=1, b=0)

Sends alert to specified channel in the yaml file,

from raven.utils import alert

@alert(
    config_path="raven_config.yaml",
    token=<BOT_TOKEN>,
    channel="alert_channel"
)
def division(**kwargs):
    x = kwargs.get("a") / kwargs.get("b")

division(a=1, b=0)

In try-catch

from raven.utils import send_alert

def division(**kwargs):
    try:
        x = kwargs.get("a") / kwargs.get("b")
    except Exception:
        # for raven to catch this error
        send_alert_with_config(
            config_path="raven_config.yaml",
            token=<BOT_TOKEN>
        )

division(a=1, b=0)

Using barebone API

Automatic alert

from raven.utils import alert

@alert(
    token=<YOUR SLACK TOKEN>,
    channel_id=<YOUR SLACK CHANNEL ID>,
)
def division(**kwargs):
    x = kwargs.get("a") / kwargs.get("b")

division(a=1, b=0)

In try-catch

from raven.utils import send_alert

def division(**kwargs):
    try:
        x = kwargs.get("a") / kwargs.get("b")
    except Exception:
        # for raven to catch this error
        send_alert(
            token=<YOUR SLACK TOKEN>,
            channel_id=<YOUR SLACK CHANNEL ID>,
        )

Optional parameters

environment can be passed as an optional param in all options
callbacks can be passed as an optional param in all options

Contributions

Contributions are welcomed. View CONTRIBUTING.md