Giter VIP home page Giter VIP logo

mixpanel-celery's Introduction

mixpanel-celery

Asynchronous event tracking for Mixpanel

Build Status

mixpanel-celery helps you use Celery to asynchronously track your Mixpanel events. Waiting on HTTP requests to Mixpanel's api to complete every time you want to record something slows you down. Using mixpanel-celery gives you all of the Mixpanel goodness without any of the potential performance impact.

Works wherever Celery works

mixpanel-celery works great with Django, but because Celery works with just python, so does mixpanel-celery.

But how do I do the thing?

I'll tell you how! Have Celery running and want to asynchronously track an event? Is your event called my_event? You're in luck!

from mixpanel.tasks import EventTracker

EventTracker.delay(
    'my_event',
    {'distinct_id': 1},
    token='YOUR_API_TOKEN',
)

Boom. Once your Celery worker gets hold of that bad boy, it's tracked.

Full-on Docs

Would you like to know more? Well then you should read the docs, citizen.

Contributing

We love pull requests! Send us one, and you'll probably make Wes's day.

For details, check out the contribution tips documentation.

We like Mixpanel and Celery

This project isn't affiliated with the Mixpanel company. Just a customer's implementation of a client for their service.

mixpanel-celery's People

Contributors

agriffis avatar antonagestam avatar brad avatar carljm avatar dlo avatar frewsxcv avatar ipmb avatar jlward avatar lambacck avatar nicholasserra avatar sbisker avatar valyagolev avatar winhamwr avatar zpencerq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mixpanel-celery's Issues

PeopleTracker $add event is ignored every time

I can easily send $set commands for the PeopleTracker, but when trying to send $add commands, the parameters are not being updated in mixpanel, and from the logs, I see that they are getting ignored. I have not been able to debug why this is happening yet. Here are what I am seeing in the logs (successful $set followed by unsuccessful $add):

[2014-03-10 15:51:47,760: INFO/MainProcess] Got task from broker: mixpanel.tasks.PeopleTracker[e34973dc-7b1c-495a-bab5-f94a33cb7a12]
[2014-03-10 15:51:47,761: INFO/PoolWorker-2] Recording event: <set>
[2014-03-10 15:51:47,935: INFO/PoolWorker-2] Event recorded/logged: <set>
[2014-03-10 15:51:47,942: INFO/MainProcess] Task mixpanel.tasks.PeopleTracker[e34973dc-7b1c-495a-bab5-f94a33cb7a12] succeeded in 0.181123971939s: True
[2014-03-10 16:28:41,419: INFO/MainProcess] Got task from broker: mixpanel.tasks.PeopleTracker[0fc91179-a563-4988-ad86-18d683d7c18f]
[2014-03-10 16:28:41,450: INFO/PoolWorker-2] Recording event: <add>
[2014-03-10 16:28:41,750: INFO/PoolWorker-2] Event ignored: <add>
[2014-03-10 16:28:41,756: INFO/MainProcess] Task mixpanel.tasks.PeopleTracker[0fc91179-a563-4988-ad86-18d683d7c18f] succeeded in 0.306243181229s: False

Easier customization of JSON encoding.

I have cases where I want to be able to pass some custom objects (which are not JSON serializable by default) as properties of a mixpanel event, from various places in my code. The simplest and most flexible way to deal with this (such that it can automatically handle my object within a list, or standalone) is to create a JSONEncoder subclass that knows how to serialize my class, and then use that encoder class for the json.dumps call.

It's not currently too bad to do this - just requires subclassing EventTracker and overriding the _encode_params method. But this still requires duplicating some things I don't care about customizing - the base64-encoding, and the MIXPANEL_DATA_VARIABLE.

It would be nice if either there were a json_encoder_class class attribute on EventTracker, or a more fine-grained _params_to_json method. (Names up for debate).

Doesn't work with celery version 3.0

Version 3 of celery has broken compatbility with this library. The logger no longer seems to be available:

Traceback (most recent call last):
File "/Users/sendhub-dev/dev/sendhub/project/venv/lib/python2.7/site-packages/celery/task/trace.py", line 224, in trace_task
R = retval = fun(_args, *_kwargs)
File "/Users/sendhub-dev/dev/sendhub/project/venv/lib/python2.7/site-packages/celery/task/trace.py", line 403, in protected_call
return self.run(_args, *_kwargs)
File "/Users/sendhub-dev/dev/sendhub/project/app/api/v1/events.py", line 38, in mixPanelListener
tracker.run(name, properties, token=settings.MIXPANEL_API_KEY)
File "/Users/sendhub-dev/dev/sendhub/project/venv/lib/python2.7/site-packages/mixpanel/tasks.py", line 42, in run
if l.logger.getEffectiveLevel() == logging.DEBUG:
AttributeError: 'ProcessAwareLogger' object has no attribute 'logger'

Allow toggling mixpanel reporting off.

At the moment there's no convenient way that I can see to insert EventTracker.delay(...) calls into your code but turn it into a no-op under certain circumstances (e.g. when running tests, or even generally in local development).

I see MIXPANEL_TEST_ONLY, but that still goes out and talks to mixpanel with {test: 1}. I don't see any reason for my test suite to be hammering mixpanel with requests and would prefer to just have a setting to make the whole thing a no-op.

One option is to just have EventTracker do nothing if it can't find an API token (i.e. none was given explicitly, and none is given in settings). That's easy and doesn't require a new setting. Or a new setting could be added.

I can supply a pull request if I get some feedback on the approach you like.

Deprecate and then remove the FunnelEventTracker

For a while now, Mixpanel has supported ad-hoc funneling based on arbitrary events. It's no longer necessary to use a separate task. Add a deprecation warning and remove it before a 1.0 release.

Unable to add EventTracker task to the celery event queue

Our Django server already uses celery to manage all kinds of async tasks. As a python newbie, I am trying to add mixpanel metrics to our backend.

Here is the code I use to track events:

@receiver(post_save, sender=Message)
def track_post_message(sender, instance, created, raw, **kwargs):
    logger.info('sending mixpanel event')
    et = EventTracker()
    logger.info('tracker' + repr(et))
    et.run('post_message', {'distinct_id': instance.creator.id}, token='XXX')

The server logs:

INFO sending mixpanel event
INFO tracker<@task: mixpanel.tasks.EventTracker>

And here is what celery logs:

-------------- [email protected] v2.5.5
---- **** -----
--- * ***  * -- [Configuration]
-- * - **** ---   . broker:      amqp://[email protected]:5672//
- ** ----------   . loader:      djcelery.loaders.DjangoLoader
- ** ----------   . logfile:     [stderr]@INFO
- ** ----------   . concurrency: 2
- ** ----------   . events:      OFF
- *** --- * ---   . beat:        OFF
-- ******* ----
--- ***** ----- [Queues]
 --------------   . celery:      exchange:celery (direct) binding:celery


[Tasks]
  . mixpanel.tasks.EventTracker
  . mixpanel.tasks.FunnelEventTracker
  . myapp.search.add
  . myapp.search.remove
  . myapp.tasks.create_connection
  . myapp.tasks.create_invitation_code
  . myapp.tasks.email_notify_people
  . myapp.tasks.email_reply_unknown
  . myapp.tasks.notify_group_created
  . myapp.tasks.notify_group_deleted
  . myapp.tasks.notify_invitation_accepted
  . myapp.tasks.notify_membership_created
  . myapp.tasks.notify_membership_deleted
  . myapp.tasks.push_notify_people
  . myapp.tasks.send_invitation
  . myapp.tasks.update_twitter_connections
  . myapp.tasks.user_logged_out
  . raven.contrib.celery.send_raw

[2012-07-04 10:48:19,130: INFO/PoolWorker-1] child process calling self.run()
[2012-07-04 10:48:19,133: INFO/PoolWorker-2] child process calling self.run()
[2012-07-04 10:48:19,167: WARNING/MainProcess] [email protected] has started.
[2012-07-04 10:50:26,172: INFO/MainProcess] Got task from broker: mopedapp.tasks.push_notify_people[eb24e519-a522-430a-91a9-ca7cca34aef6]
[2012-07-04 10:50:26,176: INFO/MainProcess] Got task from broker: mopedapp.search.add[4f284be0-f0f3-4a5e-a62e-c95f5a8d29cd]
[2012-07-04 10:50:26,232: INFO/MainProcess] Task mopedapp.tasks.push_notify_people[eb24e519-a522-430a-91a9-ca7cca34aef6] succeeded in 0.0457792282104s: None
[2012-07-04 10:50:26,917: INFO/MainProcess] Task mopedapp.search.add[4f284be0-f0f3-4a5e-a62e-c95f5a8d29cd] succeeded in 0.723988056183s: None

Thanks in advance for any hints.

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.