{"action":"created","issue":{"url":"https://api.github.com/repos/rollbar/pyrollbar/issues/281","repository_url":"https://api.github.com/repos/rollbar/pyrollbar","labels_url":"https://api.github.com/repos/rollbar/pyrollbar/issues/281/labels{/name}","comments_url":"https://api.github.com/repos/rollbar/pyrollbar/issues/281/comments","events_url":"https://api.github.com/repos/rollbar/pyrollbar/issues/281/events","html_url":"https://github.com/rollbar/pyrollbar/issues/281","id":352192892,"node_id":"MDU6SXNzdWUzNTIxOTI4OTI=","number":281,"title":"blocking handler doesn't work in rq","user":{"login":"peterbe","id":26739,"node_id":"MDQ6VXNlcjI2NzM5","avatar_url":"https://avatars2.githubusercontent.com/u/26739?v=4","gravatar_id":"","url":"https://api.github.com/users/peterbe","html_url":"https://github.com/peterbe","followers_url":"https://api.github.com/users/peterbe/followers","following_url":"https://api.github.com/users/peterbe/following{/other_user}","gists_url":"https://api.github.com/users/peterbe/gists{/gist_id}","starred_url":"https://api.github.com/users/peterbe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterbe/subscriptions","organizations_url":"https://api.github.com/users/peterbe/orgs","repos_url":"https://api.github.com/users/peterbe/repos","events_url":"https://api.github.com/users/peterbe/events{/privacy}","received_events_url":"https://api.github.com/users/peterbe/received_events","type":"User","site_admin":false},"labels":[{"id":11448255,"node_id":"MDU6TGFiZWwxMTQ0ODI1NQ==","url":"https://api.github.com/repos/rollbar/pyrollbar/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":{"login":"corps","id":593850,"node_id":"MDQ6VXNlcjU5Mzg1MA==","avatar_url":"https://avatars3.githubusercontent.com/u/593850?v=4","gravatar_id":"","url":"https://api.github.com/users/corps","html_url":"https://github.com/corps","followers_url":"https://api.github.com/users/corps/followers","following_url":"https://api.github.com/users/corps/following{/other_user}","gists_url":"https://api.github.com/users/corps/gists{/gist_id}","starred_url":"https://api.github.com/users/corps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/corps/subscriptions","organizations_url":"https://api.github.com/users/corps/orgs","repos_url":"https://api.github.com/users/corps/repos","events_url":"https://api.github.com/users/corps/events{/privacy}","received_events_url":"https://api.github.com/users/corps/received_events","type":"User","site_admin":false},"assignees":[{"login":"corps","id":593850,"node_id":"MDQ6VXNlcjU5Mzg1MA==","avatar_url":"https://avatars3.githubusercontent.com/u/593850?v=4","gravatar_id":"","url":"https://api.github.com/users/corps","html_url":"https://github.com/corps","followers_url":"https://api.github.com/users/corps/followers","following_url":"https://api.github.com/users/corps/following{/other_user}","gists_url":"https://api.github.com/users/corps/gists{/gist_id}","starred_url":"https://api.github.com/users/corps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/corps/subscriptions","organizations_url":"https://api.github.com/users/corps/orgs","repos_url":"https://api.github.com/users/corps/repos","events_url":"https://api.github.com/users/corps/events{/privacy}","received_events_url":"https://api.github.com/users/corps/received_events","type":"User","site_admin":false}],"milestone":null,"comments":4,"created_at":"2018-08-20T15:46:04Z","updated_at":"2018-08-21T01:48:36Z","closed_at":null,"author_association":"NONE","body":"I'm struggling to get rollbar (0.14.2) to work with [rq](http://python-rq.org/). In particular, I'm using [`django-rq`](https://github.com/rq/django-rq) which is just a convenient wrapper. With `django-rq` you can define your own custom exception handler function. I did that, with `settings.RQ_EXCEPTION_HANDLERS = [\"songsearch.rq.peterbe_rollbar_exception_handler\"]`. \r\n\r\nThe function looks like this:\r\n\r\n```python\r\ndef peterbe_rollbar_exception_handler(job, *exc_info):\r\n    print(\"IN peterbe_rollbar_exception_handler\")\r\n    print(\"settings.ROLLBAR_ACCESS_TOKEN\", settings.ROLLBAR[\"access_token\"])\r\n    print(\"JOB\", repr(job))\r\n    print(\"EXC_INFO\", exc_info)\r\n    rollbar.init(\r\n        settings.ROLLBAR[\"access_token\"],\r\n        settings.ROLLBAR[\"environment\"],\r\n        handler=\"blocking\",  # NOTE!!\r\n    )\r\n    job_info = job.to_dict()\r\n    job_info[\"data\"] = repr(job_info[\"data\"])\r\n    extra_data = {\"job\": job_info}\r\n    payload_data = {\r\n        \"framework\": \"rq\",\r\n        \"exception_handler\": \"peterbe_rollbar_exception_handler\",\r\n    }\r\n    R = rollbar.report_exc_info(\r\n        exc_info, extra_data=extra_data, payload_data=payload_data\r\n    )\r\n    print(\"R...\")\r\n    print(repr(R))\r\n```\r\n\r\nThe details aren't particularly important. I can clean this up later. The messages just aren't sent. I put some print statements into [`rollbar/__init__.py`'s `_post_api` function](https://github.com/rollbar/pyrollbar/blob/18b40e6b8c94864dc0832c8f617aa42f829fa2da/rollbar/__init__.py#L1365)\r\nIt now looks like this (the print statements are my only addition):\r\n\r\n```python\r\ndef _post_api(path, payload_str, access_token=None):\r\n    headers = {'Content-Type': 'application/json'}\r\n\r\n    if access_token is not None:\r\n        headers['X-Rollbar-Access-Token'] = access_token\r\n\r\n    url = urljoin(SETTINGS['endpoint'], path)\r\n    print(\"About to call transport.post\", repr(transport))\r\n    resp = transport.post(url,\r\n                         data=payload_str,\r\n                         headers=headers,\r\n                         timeout=SETTINGS.get('timeout', DEFAULT_TIMEOUT),\r\n                         verify=SETTINGS.get('verify_https', True))\r\n    print(\"RESP:\", repr(resp))\r\n\r\n    return _parse_response(path, SETTINGS['access_token'], payload_str, resp)\r\n```\r\n\r\nI get, in my `stdout`:\r\n```\r\nAbout to call transport.post <module 'rollbar.lib.transport' from '/Users/peterbe/virtualenvs/songsearch/lib/python3.5/site-packages/rollbar/lib/transport.py'>\r\n```\r\nBut it never prints the line `print(\"RESP:\", repr(resp))` because it just hangs on the call to `transport.post()`. \r\n\r\nI wonder if it's because, even with `handler=\"blocking\"` it uses the threading code here: https://github.com/rollbar/pyrollbar/blob/18b40e6b8c94864dc0832c8f617aa42f829fa2da/rollbar/lib/transport.py#L5 which doesn't work in `rq`, because, I don't know, threads. \r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/rollbar/pyrollbar/issues/comments/414522934","html_url":"https://github.com/rollbar/pyrollbar/issues/281#issuecomment-414522934","issue_url":"https://api.github.com/repos/rollbar/pyrollbar/issues/281","id":414522934,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNDUyMjkzNA==","user":{"login":"peterbe","id":26739,"node_id":"MDQ6VXNlcjI2NzM5","avatar_url":"https://avatars2.githubusercontent.com/u/26739?v=4","gravatar_id":"","url":"https://api.github.com/users/peterbe","html_url":"https://github.com/peterbe","followers_url":"https://api.github.com/users/peterbe/followers","following_url":"https://api.github.com/users/peterbe/following{/other_user}","gists_url":"https://api.github.com/users/peterbe/gists{/gist_id}","starred_url":"https://api.github.com/users/peterbe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterbe/subscriptions","organizations_url":"https://api.github.com/users/peterbe/orgs","repos_url":"https://api.github.com/users/peterbe/repos","events_url":"https://api.github.com/users/peterbe/events{/privacy}","received_events_url":"https://api.github.com/users/peterbe/received_events","type":"User","site_admin":false},"created_at":"2018-08-21T01:48:36Z","updated_at":"2018-08-21T01:48:36Z","author_association":"NONE","body":"No dice :(\r\n\r\nFirst I butchered it like this:\r\n\r\n```python\r\n    print(\"ABOUT TO CALL....\")\r\n    try:\r\n        R = rollbar.report_exc_info(\r\n            exc_info, extra_data=extra_data, payload_data=payload_data\r\n        )\r\n    except:\r\n        print(\"EXCEPTION!!!!!\")\r\n        import traceback\r\n\r\n        traceback.print_exc()\r\n        raise\r\n```\r\nThat's in my own exception handler function. No luck. Same as before. \r\n\r\nThen, I edited the `rollbar/lib/transport.py` right inside the virtualenv. So now it looks like this:\r\n\r\n```python\r\ndef post(*args, **kw):\r\n    import q\r\n    print(\"ABOUT TO POST...\")\r\n    q(\"About to post...\")\r\n    print(\"_session()\", _session())\r\n    try:\r\n        print(\"args\", args)\r\n        print(\"kw\", kw)\r\n        q(\"Before post...\")\r\n        r= _session().post(*args, **kw)\r\n        q(\"After post...\")\r\n    except:\r\n        print(\"EXCEPTION in ROLLBAR!!!!! \")\r\n        q(\"Exception happened\")\r\n        import traceback\r\n\r\n        traceback.print_exc()\r\n        raise\r\n    print(\"Response from post()\", repr(r))\r\n    return r\r\n```\r\n\r\nIn `$TMPDIR/q` all I get is this:\r\n\r\n```\r\n 0.2s post: \"About to post...\"='About to post...'\r\n 0.2s post: \"Before post...\"='Before post...'\r\n```\r\n\r\nNote how I printed out a bunch of other stuff there inside the `post` function. It looks like this (printing `args` and `kw`):\r\n\r\n```\r\nargs ('https://api.rollbar.com/api/1/item/',)\r\nkw {'timeout': 3, 'data': '{\"access_token\": \"b0__REDACTED__8\", \"data\": {\"uuid\": \"4c08017d-5f18-42bc-ba88-2833d5e109bf\", \"exception_handler\": \"peterbe_rollbar_exception_handler\", \"framework\": \"rq\", \"level\": \"error\", \"timestamp\": 1534815576, \"notifier\": {\"name\": \"pyrollbar\", \"version\": \"0.14.2\"}, \"server\": {\"host\": \"MacBook-Pro-131.local\", \"pid\": 86084, \"argv\": [\"./manage.py\", \"rqworker\", \"high\", \"default\", \"low\"]}, \"custom\": {\"job\": {\"created_at\": \"2018-08-21T01:39:36.197744Z\", \"data\": \"b\\'x\\\\\\\\x9ck`\\\\\\\\x99\\\\\\\\xea\\\\\\\\xc9\\\\\\\\x00\\\\\\\\x01\\\\\\\\x1a=\\\\\\\\xda\\\\\\\\xc5\\\\\\\\xf9y\\\\\\\\xe9\\\\\\\\xc5\\\\\\\\xa9\\\\\\\\x89E\\\\\\\\xc9\\\\\\\\x19z\\\\\\\\x89\\\\\\\\x05\\\\\\\\x99ze\\\\\\\\x99\\\\\\\\xa9\\\\\\\\xe5\\\\\\\\xc5`VqbnANj|Qa|Zi^rIf~\\\\\\\\xde\\\\\\\\x14?\\\\\\\\xaf9\\\\\\\\xff\\\\\\\\xff\\\\\\\\xff\\\\\\\\xf7>\\\\\\\\xd16\\\\\\\\xa5vJ\\\\\\\\x0fkqNjj\\\\\\\\xc1\\\\\\\\x14o\\\\\\\\xe6\\\\\\\\xe2\\\\\\\\x92)z\\\\\\\\x00\\\\\\\\xc0i \\\\\\\\x8a\\'\", \"origin\": \"default\", \"description\": \"songsearch.api.views.api.sample_rq_function(-100, 200, sleep=3)\", \"status\": \"failed\", \"enqueued_at\": \"2018-08-21T01:39:36.197859Z\", \"started_at\": \"2018-08-21T01:39:36.216081Z\", \"ended_at\": \"2018-08-21T01:39:36.216789Z\", \"timeout\": 180}}, \"body\": {\"trace\": {\"exception\": {\"message\": \"\\'a\\' is less than 0\", \"class\": \"RQTestError\"}, \"frames\": [{\"method\": \"perform_job\", \"locals\": {\"started_job_registry\": \"<class \\'rq.registry.StartedJobRegistry\\'>\", \"self\": \"<class \\'rq.worker.Worker\\'>\", \"queue\": \"<class \\'django_rq.queues.DjangoRQ\\'>\", \"job\": \"<class \\'rq.job.Job\\'>\", \"timeout\": 180}, \"code\": \"rv = job.perform()\", \"lineno\": 793, \"filename\": \"/Users/peterbe/virtualenvs/songsearch/lib/python3.5/site-packages/rq/worker.py\", \"argspec\": [\"self\", \"job\", \"queue\"]}, {\"method\": \"perform\", \"locals\": {\"self\": \"<class \\'rq.job.Job\\'>\"}, \"code\": \"self._result = self._execute()\", \"lineno\": 599, \"filename\": \"/Users/peterbe/virtualenvs/songsearch/lib/python3.5/site-packages/rq/job.py\", \"argspec\": [\"self\"]}, {\"method\": \"_execute\", \"locals\": {\"self\": \"<class \\'rq.job.Job\\'>\"}, \"code\": \"return self.func(*self.args, **self.kwargs)\", \"lineno\": 605, \"filename\": \"/Users/peterbe/virtualenvs/songsearch/lib/python3.5/site-packages/rq/job.py\", \"argspec\": [\"self\"]}, {\"method\": \"sample_rq_function\", \"locals\": {\"b\": 200, \"sleep\": 3, \"a\": -100}, \"code\": \"raise RQTestError(\\\\\"\\'a\\' is less than 0\\\\\")\", \"lineno\": 129, \"filename\": \"/Users/peterbe/dev/SONGSEARCH/songsearch/songsearch/api/views/api.py\", \"argspec\": [\"a\", \"b\", \"sleep\"]}]}}, \"environment\": \"development\", \"language\": \"python 3.5.1\"}}', 'verify': True, 'headers': {'Content-Type': 'application/json'}}\r\n```\r\n\r\nFor what it's worth, I copied that output verbatim into a `oneoff.py` file and ran it, with `session = requests.Session().post(*args, **kw)` the post did work and the error appears on Rollbar.com. So the arguments being sent to `session.post()` are working. "}}
{"actor":{"display_login":"peterbe"}}