Coder Social home page Coder Social logo

flask-datadog's People

Contributors

brettlangdon avatar cyberdelia avatar monichev avatar volker48 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

flask-datadog's Issues

Add response timing middleware

The first thing I did in my app with this client was to add before_request and after_request handlers to get response time metrics into datadog. Seems like it might be a decent/common functionality people would want?

The gist of it looks like this:

import time

from flask import Flask, g, request
from flask.ext.datadog import StatsD

app = Flask(__name__)
statsd = StatsD(app=app)

def before_request():
    g.request_start_time = time.time()

def after_request(response):
    # Return early if we don't have the start time
    if hasattr(g, 'request_start_time'):
        return response

    # Get elapsed time in milliseconds
    elapsed = time.time() - g.request_start_time
    elapsed = int(round(1000 * elapsed))

    # Collect request/response tags
    tags = [
        'endpoint:{endpoint}'.format(endpoint=request.endpoint),
        'request_method:{method}'.format(method=request.method.lower()),
        'status_code:{status_code}'.format(status_code=response.status_code),
    ]

    # Record our response time metric
    statsd.timing('flask.response.time', elapsed, tags=g.request_tags + tags)

    # Return the original unmodified response
    return response

app.before_request(before_request)
app.after_request(after_request)

This might be something we can do by default when running init_app, or maybe just a method setup_middleware(app) for handling it.

Does this seem like a reasonable thing to try and tackle, or should we leave this middleware stuff as an exercise for the implementer?

Why is host set to statsd.local in the usage example?

Hi,

This is a nice extension. Unfortunately it took me a while to get it working because my dogstatsd server was listening on localhost and this line (app.config['STATSD_HOST'] = 'statsd.local') in the example caused my data to be sent into the void. Statsd's protocol lacks acknowledgements, so I didn't get any error messages from the host setting being incorrect, and it took me a while to realize what was wrong.

So, why is there a line in the example usage that seems to prevent the extension from working with a standard Datadog Agent setup? I noticed that line is also in https://github.com/cyberdelia/flask-statsd. Can it be removed or does it still serve a purpose?

Also the Pypy package is out of date.

Thanks for your work on this.

PyPI package is out of date

The pypi packages out there are unusable due to the (api breaking?) change in the datadog package, fixed in #9 but not yet deployed.

Request metric batching

The idea is to allow people to batch all metrics during a single request and flush at the end of the request.

Something similar to the following:

def before_request():
    statsd.open_buffer(statsd.max_buffer_size)

def after_request():
    statsd.close_buffer()

Similar to #4 we could add this by default, and add a config flag to disable (or enable), and/or add a setup_batching(app) type method.

Add more default metrics

Since we are adding in the middleware for response time, maybe there are some other default metrics we can provide for people?

An initial thought I had was, flask.response.size which is a histogram of response.headers['Content-Type'], which we could also tag with response.mimetype so you can track response body size.

Add support for dogapi

Since they also contain their API client in the datadog package, it might be nice to also have an API class that sets up an API client as well.

from flask.ext.datadog import API

app = Flask(__name__)
app.config['DATADOG_API_KEY'] = ''
app.config['DATADOG_APP_KEY'] = ''
dogapi = API(app=app)
dogapi.Event.create(...)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.