Skip to main content

Epsagon Instrumentation for Python

Project description

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

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.lambda_wrapper(app)

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.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

epsagon-1.12.1.tar.gz (39.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

epsagon-1.12.1-py3-none-any.whl (62.2 kB view details)

Uploaded Python 3

File details

Details for the file epsagon-1.12.1.tar.gz.

File metadata

  • Download URL: epsagon-1.12.1.tar.gz
  • Upload date:
  • Size: 39.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3

File hashes

Hashes for epsagon-1.12.1.tar.gz
Algorithm Hash digest
SHA256 13305535ea192aa713881401e602250142cf4d1f3ab87c0b74de0f6fd199ebc4
MD5 08e11e284f096bded519dabc25e70047
BLAKE2b-256 697cd36f1a00ed5b9d9b084daf5893f85e11cd88b48251e8e623f49d947d7c52

See more details on using hashes here.

File details

Details for the file epsagon-1.12.1-py3-none-any.whl.

File metadata

  • Download URL: epsagon-1.12.1-py3-none-any.whl
  • Upload date:
  • Size: 62.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3

File hashes

Hashes for epsagon-1.12.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3795e27ba1032afd55e8f90f82888dbafd6bd5cc6a661539e4b20fedc78da985
MD5 550a199160a9d6c547ff18b25a4b07ce
BLAKE2b-256 3be8429e7fa8f57aa9ef428a0e6de1e9bb2d03e8e99d5ae567504ae910d50f08

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page