Skip to content
Tracing library for Python 2.7, 3.6 and 3.7 ⚡️
Python Shell
Branch: master
Clone or download
enoodle feat(trace.py): removing max events per type limitation (#135)
fixing some pylints to create a commit
Latest commit bd55104 Aug 21, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
acceptance Urllib3 support (#87) May 23, 2019
epsagon removing max event per type limitation (#134) Aug 21, 2019
examples feat(gcp_function.py): support Google Cloud Functions Feb 21, 2019
scripts feat(release): working (#64) Mar 5, 2019
tests
.gitignore Avoid double lambda wrapping Jul 21, 2019
.pylintrc feat(handler.py): support general wrapper (#21) Jan 2, 2019
.releaserc feat(release): Moving to semantic release (#60) Mar 5, 2019
.travis.yml feat(release): working on release (#61) Mar 5, 2019
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md (#18) Nov 14, 2018
LICENSE Initial commit. Sep 30, 2018
MANIFEST.in Initial commit. Sep 30, 2018
README.md fix(README): re-publish package Aug 8, 2019
package-lock.json fix(deps): bump lodash from 4.17.11 to 4.17.14 (#107) Jul 14, 2019
package.json fix(http_filters.py): ignore aws urls only on requests (#98) Jun 11, 2019
requirements-dev.txt Avoid double lambda wrapping Jul 21, 2019
requirements.txt fix(requirements): open requirements for libs (#51) Feb 22, 2019
setup.cfg feat(release): Moving to semantic release (#60) Mar 5, 2019
setup.py fix(tox): add support for python 3.7 (#20) Dec 2, 2018
tox.ini Improve packaging (#1) Oct 4, 2018

README.md

Epsagon Instrumentation for Python

Build Status Pyversions PypiVersions

This package provides an instrumentation to Python code running on functions for collection of distributed tracing and performance monitoring.

Installation

From your project directory:

$ pip install epsagon

More details about lambda deployments are available in the AWS documentation.

Usage

AWS Lambda

Simply use our decorator to report metrics:

import epsagon
epsagon.init(
    token='my-secret-token',
    app_name='my-app-name',
    metadata_only=False,  # Optional, send more trace data
)

@epsagon.lambda_wrapper
def handler(event, context):
  pass

Django Application

Add the following code to the settings.py file:

import epsagon
epsagon.init(
    token='my-secret-token',
    app_name='my-app-name',
    metadata_only=False,  # Optional, send more trace data
)

Add Epsagon middleware to the application's middleware list (located in settings.py)

MIDDLEWARE = [
    '....',
    'epsagon.wrappers.django.DjangoMiddleware',
]

Flask Application

Use the example snippet:

from flask import Flask
import epsagon

epsagon.init(
    token='my-secret-token',
    app_name='my-app-name',
    metadata_only=False
)

app = Flask(__name__)
epsagon.flask_wrapper(app)

@app.route('/')
def hello():
    return "Hello World!"

app.run()

Tornado Application

Use the example snippet:

import tornado.ioloop
import tornado.web
import epsagon

epsagon.init(
    token='my-secret-token',
    app_name='my-app-name',
    metadata_only=False
)


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write('Hello, world')


def make_app():
    return tornado.web.Application([
        (r'/', MainHandler),
    ])


if __name__ == '__main__':
    app = make_app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()

Generic Python

Use the example snippet:

import epsagon
epsagon.init(
    token='my-secret-token',
    app_name='my-app-name',
    metadata_only=False
)


@epsagon.python_wrapper
def main():
    return 'It worked!'
  
main()

Custom Data

Custom Labels

You can add custom labels to your traces. Filters can later be used for filtering traces that contains specific labels:

@epsagon.lambda_wrapper
def handler(event, context):
  epsagon.label('label', 'something_to_filter_afterwards')
  epsagon.label('number_of_records_parsed_successfully', 42)
  pass

Custom Errors

Set a custom error, maybe without even failing the function:

@epsagon.lambda_wrapper
def handler(event, context):
  if 'my_param' not in event:
      epsagon.error(ValueError('event missing my_param'))
  pass

Ignore keys

You can prevent data from being sent to epsagon by filtering specific keys in initialization.

import epsagon
epsagon.init(
    token='my-secret-token',
    app_name='my-app-name',
    metadata_only=False,
    keys_to_ignore=['Request Data', 'Status_Code']
)

Frameworks Integration

Serverless

Using Epsagon with Serverless is simple, by using the serverless-plugin-epsagon.

Chalice

Using Epsagon with Chalice is simple, follow this example:

from chalice import Chalice
import epsagon
epsagon.init(
    token='my-secret-token',
    app_name='my-app-name',
    metadata_only=False
)
app = Chalice(app_name="hello-world")


@app.route("/")
def index():
    return {"hello": "world"}

app = epsagon.chalice_wrapper(app)

or In S3 trigger example:

from chalice import Chalice

app = Chalice(app_name="helloworld")

import epsagon
epsagon.init(
    token='my-secret-token',
    app_name='my-app-name',
    metadata_only=False
)
# Whenever an object is uploaded to 'mybucket'
# this lambda function will be invoked.

@epsagon.lambda_wrapper
@app.on_s3_event(bucket='mybucket')
def handler(event):
    print("Object uploaded for bucket: %s, key: %s"
          % (event.bucket, event.key))

Zappa

Using Epsagon with Zappa is simple, follow this example:

from flask import Flask
from zappa.handler import lambda_handler
import epsagon

epsagon.init(
    token='my-secret-token',
    app_name='my-app-name',
    metadata_only=False
)
app = Flask(__name__)


@app.route('/')
def hello_world():
    return 'Hello, World!'


epsagon_handler = epsagon.lambda_wrapper(lambda_handler)

And in your zappa_settings.json file include the following:

{
  "lambda_handler": "module.path_to.epsagon_handler"
}

Copyright

Provided under the MIT license. See LICENSE for details.

Copyright 2019, Epsagon.

You can’t perform that action at this time.