{"action":"created","comment":{"url":"https://api.github.com/repos/DataDog/dd-trace-py/pulls/comments/225301548","pull_request_review_id":164871982,"id":225301548,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNTMwMTU0OA==","diff_hunk":"@@ -0,0 +1,80 @@\n+import jinja2\n+from wrapt import wrap_function_wrapper as _w\n+\n+from ddtrace import tracer\n+\n+from ...ext import http\n+from ...utils.wrappers import unwrap as _u\n+\n+DEFAULT_TEMPLATE_NAME = \"<template>\"\n+\n+\n+def patch():\n+    if getattr(jinja2, \"__datadog_patch\", False):\n+        # already patched\n+        return\n+    setattr(jinja2, \"__datadog_patch\", True)\n+    _w(jinja2, \"environment.Template.render\", _wrap_render)\n+    _w(jinja2, \"environment.Template.generate\", _wrap_generate)\n+    _w(jinja2, \"environment.Environment.compile\", _wrap_compile)\n+    _w(jinja2, \"environment.Environment._load_template\", _wrap_load_template)\n+\n+\n+def unpatch():\n+    if not getattr(jinja2, \"__datadog_patch\", False):\n+        return\n+    setattr(jinja2, \"__datadog_patch\", False)\n+    _u(jinja2.Template, \"render\")\n+    _u(jinja2.Template, \"generate\")\n+    _u(jinja2.Environment, \"compile\")\n+    _u(jinja2.Environment, \"_load_template\")\n+\n+\n+def _wrap_generate(func, instance, args, kwargs):\n+    template_name = instance.name or DEFAULT_TEMPLATE_NAME\n+    with tracer.trace(\"jinja2.generate\", span_type=http.TEMPLATE) as span:\n+        try:\n+            for s in func(*args, **kwargs):\n+                yield s\n+        finally:\n+            span.resource = template_name\n+            span.set_tag(\"jinja2.template_name\", template_name)\n+\n+\n+def _wrap_render(func, instance, args, kwargs):\n+    template_name = instance.name or DEFAULT_TEMPLATE_NAME\n+    with tracer.trace(\"jinja2.render\", span_type=http.TEMPLATE) as span:\n+        try:\n+            return func(*args, **kwargs)\n+        finally:\n+            span.resource = template_name\n+            span.set_tag(\"jinja2.template_name\", template_name)\n+\n+\n+def _wrap_compile(func, instance, args, kwargs):\n+    if len(args) > 1:\n+        template_name = args[1]\n+    else:\n+        template_name = kwargs.get(\"name\", DEFAULT_TEMPLATE_NAME)\n+\n+    with tracer.trace(\"jinja2.compile\", span_type=http.TEMPLATE) as span:\n+        try:\n+            return func(*args, **kwargs)\n+        finally:\n+            span.resource = template_name\n+            span.set_tag(\"jinja2.template_name\", template_name)\n+\n+\n+def _wrap_load_template(func, instance, args, kwargs):\n+    template_name = kwargs.get(\"name\", args[0])\n+    with tracer.trace(\"jinja2.load\", span_type=http.TEMPLATE) as span:\n+        template = None\n+        try:\n+            template = func(*args, **kwargs)\n+        finally:\n+            span.resource = template_name\n+            span.set_tag(\"jinja2.template_name\", template_name)\n+            loader = instance.loader.__class__.__name__\n+            span.set_tag(\"jinja2.loader\", loader)\n+            span.set_tag(\"jinja2.template_path\", template.filename)","path":"ddtrace/contrib/jinja2/patch.py","position":79,"original_position":79,"commit_id":"3a873cac85b9bcc2af01eeba2fafabc422baf710","original_commit_id":"3a873cac85b9bcc2af01eeba2fafabc422baf710","user":{"login":"brettlangdon","id":1320353,"node_id":"MDQ6VXNlcjEzMjAzNTM=","avatar_url":"https://avatars0.githubusercontent.com/u/1320353?v=4","gravatar_id":"","url":"https://api.github.com/users/brettlangdon","html_url":"https://github.com/brettlangdon","followers_url":"https://api.github.com/users/brettlangdon/followers","following_url":"https://api.github.com/users/brettlangdon/following{/other_user}","gists_url":"https://api.github.com/users/brettlangdon/gists{/gist_id}","starred_url":"https://api.github.com/users/brettlangdon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brettlangdon/subscriptions","organizations_url":"https://api.github.com/users/brettlangdon/orgs","repos_url":"https://api.github.com/users/brettlangdon/repos","events_url":"https://api.github.com/users/brettlangdon/events{/privacy}","received_events_url":"https://api.github.com/users/brettlangdon/received_events","type":"User","site_admin":false},"body":"`template` could be `None` here if a `jinja2.exceptions.TemplateNotFound` was raised.\r\n\r\nAlso, do all templates have a `filename`?","created_at":"2018-10-15T20:15:39Z","updated_at":"2018-10-15T20:20:08Z","html_url":"https://github.com/DataDog/dd-trace-py/pull/649#discussion_r225301548","pull_request_url":"https://api.github.com/repos/DataDog/dd-trace-py/pulls/649","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/DataDog/dd-trace-py/pulls/comments/225301548"},"html":{"href":"https://github.com/DataDog/dd-trace-py/pull/649#discussion_r225301548"},"pull_request":{"href":"https://api.github.com/repos/DataDog/dd-trace-py/pulls/649"}}},"pull_request":{"url":"https://api.github.com/repos/DataDog/dd-trace-py/pulls/649","id":222942979,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIyOTQyOTc5","html_url":"https://github.com/DataDog/dd-trace-py/pull/649","diff_url":"https://github.com/DataDog/dd-trace-py/pull/649.diff","patch_url":"https://github.com/DataDog/dd-trace-py/pull/649.patch","issue_url":"https://api.github.com/repos/DataDog/dd-trace-py/issues/649","number":649,"state":"open","locked":false,"title":"[WIP] add jinja2 support","user":{"login":"mgu","id":91013,"node_id":"MDQ6VXNlcjkxMDEz","avatar_url":"https://avatars2.githubusercontent.com/u/91013?v=4","gravatar_id":"","url":"https://api.github.com/users/mgu","html_url":"https://github.com/mgu","followers_url":"https://api.github.com/users/mgu/followers","following_url":"https://api.github.com/users/mgu/following{/other_user}","gists_url":"https://api.github.com/users/mgu/gists{/gist_id}","starred_url":"https://api.github.com/users/mgu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgu/subscriptions","organizations_url":"https://api.github.com/users/mgu/orgs","repos_url":"https://api.github.com/users/mgu/repos","events_url":"https://api.github.com/users/mgu/events{/privacy}","received_events_url":"https://api.github.com/users/mgu/received_events","type":"User","site_admin":false},"body":"Add support for tracing jinja2 templates operations.\r\n\r\nI open the PR in order to receive comments, it's not complete !\r\ntests are not ready :)\r\n","created_at":"2018-10-15T15:13:06Z","updated_at":"2018-10-15T20:20:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7fdd6169a0a72951a96814adec199a57302a5676","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":810431530,"node_id":"MDU6TGFiZWw4MTA0MzE1MzA=","url":"https://api.github.com/repos/DataDog/dd-trace-py/labels/community","name":"community","color":"0e8a16","default":false},{"id":443002993,"node_id":"MDU6TGFiZWw0NDMwMDI5OTM=","url":"https://api.github.com/repos/DataDog/dd-trace-py/labels/integrations","name":"integrations","color":"c2e0c6","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/DataDog/dd-trace-py/pulls/649/commits","review_comments_url":"https://api.github.com/repos/DataDog/dd-trace-py/pulls/649/comments","review_comment_url":"https://api.github.com/repos/DataDog/dd-trace-py/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DataDog/dd-trace-py/issues/649/comments","statuses_url":"https://api.github.com/repos/DataDog/dd-trace-py/statuses/3a873cac85b9bcc2af01eeba2fafabc422baf710","head":{"label":"mgu:jinja2","ref":"jinja2","sha":"3a873cac85b9bcc2af01eeba2fafabc422baf710","user":{"login":"mgu","id":91013,"node_id":"MDQ6VXNlcjkxMDEz","avatar_url":"https://avatars2.githubusercontent.com/u/91013?v=4","gravatar_id":"","url":"https://api.github.com/users/mgu","html_url":"https://github.com/mgu","followers_url":"https://api.github.com/users/mgu/followers","following_url":"https://api.github.com/users/mgu/following{/other_user}","gists_url":"https://api.github.com/users/mgu/gists{/gist_id}","starred_url":"https://api.github.com/users/mgu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgu/subscriptions","organizations_url":"https://api.github.com/users/mgu/orgs","repos_url":"https://api.github.com/users/mgu/repos","events_url":"https://api.github.com/users/mgu/events{/privacy}","received_events_url":"https://api.github.com/users/mgu/received_events","type":"User","site_admin":false},"repo":{"id":152992344,"node_id":"MDEwOlJlcG9zaXRvcnkxNTI5OTIzNDQ=","name":"dd-trace-py","full_name":"mgu/dd-trace-py","private":false,"owner":{"login":"mgu","id":91013,"node_id":"MDQ6VXNlcjkxMDEz","avatar_url":"https://avatars2.githubusercontent.com/u/91013?v=4","gravatar_id":"","url":"https://api.github.com/users/mgu","html_url":"https://github.com/mgu","followers_url":"https://api.github.com/users/mgu/followers","following_url":"https://api.github.com/users/mgu/following{/other_user}","gists_url":"https://api.github.com/users/mgu/gists{/gist_id}","starred_url":"https://api.github.com/users/mgu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgu/subscriptions","organizations_url":"https://api.github.com/users/mgu/orgs","repos_url":"https://api.github.com/users/mgu/repos","events_url":"https://api.github.com/users/mgu/events{/privacy}","received_events_url":"https://api.github.com/users/mgu/received_events","type":"User","site_admin":false},"html_url":"https://github.com/mgu/dd-trace-py","description":"Datadog Tracing Python Client","fork":true,"url":"https://api.github.com/repos/mgu/dd-trace-py","forks_url":"https://api.github.com/repos/mgu/dd-trace-py/forks","keys_url":"https://api.github.com/repos/mgu/dd-trace-py/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mgu/dd-trace-py/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mgu/dd-trace-py/teams","hooks_url":"https://api.github.com/repos/mgu/dd-trace-py/hooks","issue_events_url":"https://api.github.com/repos/mgu/dd-trace-py/issues/events{/number}","events_url":"https://api.github.com/repos/mgu/dd-trace-py/events","assignees_url":"https://api.github.com/repos/mgu/dd-trace-py/assignees{/user}","branches_url":"https://api.github.com/repos/mgu/dd-trace-py/branches{/branch}","tags_url":"https://api.github.com/repos/mgu/dd-trace-py/tags","blobs_url":"https://api.github.com/repos/mgu/dd-trace-py/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mgu/dd-trace-py/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mgu/dd-trace-py/git/refs{/sha}","trees_url":"https://api.github.com/repos/mgu/dd-trace-py/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mgu/dd-trace-py/statuses/{sha}","languages_url":"https://api.github.com/repos/mgu/dd-trace-py/languages","stargazers_url":"https://api.github.com/repos/mgu/dd-trace-py/stargazers","contributors_url":"https://api.github.com/repos/mgu/dd-trace-py/contributors","subscribers_url":"https://api.github.com/repos/mgu/dd-trace-py/subscribers","subscription_url":"https://api.github.com/repos/mgu/dd-trace-py/subscription","commits_url":"https://api.github.com/repos/mgu/dd-trace-py/commits{/sha}","git_commits_url":"https://api.github.com/repos/mgu/dd-trace-py/git/commits{/sha}","comments_url":"https://api.github.com/repos/mgu/dd-trace-py/comments{/number}","issue_comment_url":"https://api.github.com/repos/mgu/dd-trace-py/issues/comments{/number}","contents_url":"https://api.github.com/repos/mgu/dd-trace-py/contents/{+path}","compare_url":"https://api.github.com/repos/mgu/dd-trace-py/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mgu/dd-trace-py/merges","archive_url":"https://api.github.com/repos/mgu/dd-trace-py/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mgu/dd-trace-py/downloads","issues_url":"https://api.github.com/repos/mgu/dd-trace-py/issues{/number}","pulls_url":"https://api.github.com/repos/mgu/dd-trace-py/pulls{/number}","milestones_url":"https://api.github.com/repos/mgu/dd-trace-py/milestones{/number}","notifications_url":"https://api.github.com/repos/mgu/dd-trace-py/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mgu/dd-trace-py/labels{/name}","releases_url":"https://api.github.com/repos/mgu/dd-trace-py/releases{/id}","deployments_url":"https://api.github.com/repos/mgu/dd-trace-py/deployments","created_at":"2018-10-14T16:02:56Z","updated_at":"2018-10-14T16:02:59Z","pushed_at":"2018-10-14T20:39:27Z","git_url":"git://github.com/mgu/dd-trace-py.git","ssh_url":"git@github.com:mgu/dd-trace-py.git","clone_url":"https://github.com/mgu/dd-trace-py.git","svn_url":"https://github.com/mgu/dd-trace-py","homepage":"http://pypi.datadoghq.com/trace/docs/","size":2184,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"DataDog:master","ref":"master","sha":"87b9ff74509fab917c7341f34ffabbbf14b74578","user":{"login":"DataDog","id":365230,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2NTIzMA==","avatar_url":"https://avatars1.githubusercontent.com/u/365230?v=4","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"repo":{"id":61572326,"node_id":"MDEwOlJlcG9zaXRvcnk2MTU3MjMyNg==","name":"dd-trace-py","full_name":"DataDog/dd-trace-py","private":false,"owner":{"login":"DataDog","id":365230,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2NTIzMA==","avatar_url":"https://avatars1.githubusercontent.com/u/365230?v=4","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/DataDog/dd-trace-py","description":"Datadog Tracing Python Client","fork":false,"url":"https://api.github.com/repos/DataDog/dd-trace-py","forks_url":"https://api.github.com/repos/DataDog/dd-trace-py/forks","keys_url":"https://api.github.com/repos/DataDog/dd-trace-py/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DataDog/dd-trace-py/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DataDog/dd-trace-py/teams","hooks_url":"https://api.github.com/repos/DataDog/dd-trace-py/hooks","issue_events_url":"https://api.github.com/repos/DataDog/dd-trace-py/issues/events{/number}","events_url":"https://api.github.com/repos/DataDog/dd-trace-py/events","assignees_url":"https://api.github.com/repos/DataDog/dd-trace-py/assignees{/user}","branches_url":"https://api.github.com/repos/DataDog/dd-trace-py/branches{/branch}","tags_url":"https://api.github.com/repos/DataDog/dd-trace-py/tags","blobs_url":"https://api.github.com/repos/DataDog/dd-trace-py/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DataDog/dd-trace-py/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DataDog/dd-trace-py/git/refs{/sha}","trees_url":"https://api.github.com/repos/DataDog/dd-trace-py/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DataDog/dd-trace-py/statuses/{sha}","languages_url":"https://api.github.com/repos/DataDog/dd-trace-py/languages","stargazers_url":"https://api.github.com/repos/DataDog/dd-trace-py/stargazers","contributors_url":"https://api.github.com/repos/DataDog/dd-trace-py/contributors","subscribers_url":"https://api.github.com/repos/DataDog/dd-trace-py/subscribers","subscription_url":"https://api.github.com/repos/DataDog/dd-trace-py/subscription","commits_url":"https://api.github.com/repos/DataDog/dd-trace-py/commits{/sha}","git_commits_url":"https://api.github.com/repos/DataDog/dd-trace-py/git/commits{/sha}","comments_url":"https://api.github.com/repos/DataDog/dd-trace-py/comments{/number}","issue_comment_url":"https://api.github.com/repos/DataDog/dd-trace-py/issues/comments{/number}","contents_url":"https://api.github.com/repos/DataDog/dd-trace-py/contents/{+path}","compare_url":"https://api.github.com/repos/DataDog/dd-trace-py/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DataDog/dd-trace-py/merges","archive_url":"https://api.github.com/repos/DataDog/dd-trace-py/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DataDog/dd-trace-py/downloads","issues_url":"https://api.github.com/repos/DataDog/dd-trace-py/issues{/number}","pulls_url":"https://api.github.com/repos/DataDog/dd-trace-py/pulls{/number}","milestones_url":"https://api.github.com/repos/DataDog/dd-trace-py/milestones{/number}","notifications_url":"https://api.github.com/repos/DataDog/dd-trace-py/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DataDog/dd-trace-py/labels{/name}","releases_url":"https://api.github.com/repos/DataDog/dd-trace-py/releases{/id}","deployments_url":"https://api.github.com/repos/DataDog/dd-trace-py/deployments","created_at":"2016-06-20T18:52:23Z","updated_at":"2018-10-12T00:05:25Z","pushed_at":"2018-10-15T18:27:26Z","git_url":"git://github.com/DataDog/dd-trace-py.git","ssh_url":"git@github.com:DataDog/dd-trace-py.git","clone_url":"https://github.com/DataDog/dd-trace-py.git","svn_url":"https://github.com/DataDog/dd-trace-py","homepage":"http://pypi.datadoghq.com/trace/docs/","size":2193,"stargazers_count":81,"watchers_count":81,"language":"Python","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":90,"mirror_url":null,"archived":false,"open_issues_count":60,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":90,"open_issues":60,"watchers":81,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/DataDog/dd-trace-py/pulls/649"},"html":{"href":"https://github.com/DataDog/dd-trace-py/pull/649"},"issue":{"href":"https://api.github.com/repos/DataDog/dd-trace-py/issues/649"},"comments":{"href":"https://api.github.com/repos/DataDog/dd-trace-py/issues/649/comments"},"review_comments":{"href":"https://api.github.com/repos/DataDog/dd-trace-py/pulls/649/comments"},"review_comment":{"href":"https://api.github.com/repos/DataDog/dd-trace-py/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DataDog/dd-trace-py/pulls/649/commits"},"statuses":{"href":"https://api.github.com/repos/DataDog/dd-trace-py/statuses/3a873cac85b9bcc2af01eeba2fafabc422baf710"}},"author_association":"NONE"}}
{"actor":{"display_login":"brettlangdon"}}