Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switches from sentry's push_scope #6341

Merged
merged 1 commit into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions posthog/api/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.utils import timezone
from django.views.decorators.csrf import csrf_exempt
from rest_framework import status
from sentry_sdk import capture_exception, push_scope
from sentry_sdk import capture_exception, configure_scope
from statshog.defaults.django import statsd

from posthog.api.utils import get_token
Expand Down Expand Up @@ -249,7 +249,8 @@ def get_event(request):

library = event["properties"].get("$lib", "unknown")
library_version = event["properties"].get("$lib_version", "unknown")
with push_scope() as scope:

with configure_scope() as scope:
scope.set_tag("library", library)
scope.set_tag("library.version", library_version)

Expand Down
4 changes: 2 additions & 2 deletions posthog/api/test/mock_sentry.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from unittest.mock import Mock


def mock_sentry_context_for_tagging(patched_push_scope):
def mock_sentry_context_for_tagging(patched_scope):
mock_scope = Mock()
mock_set_tag = Mock()
mock_scope.set_context = Mock()
mock_scope.set_tag = mock_set_tag
mock_context_manager = Mock()
mock_context_manager.__enter__ = Mock(return_value=mock_scope)
mock_context_manager.__exit__ = Mock(return_value=None)
patched_push_scope.return_value = mock_context_manager
patched_scope.return_value = mock_context_manager
return mock_set_tag
14 changes: 7 additions & 7 deletions posthog/api/test/test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
from datetime import timedelta
from typing import Any, Dict, List, Union
from unittest.mock import MagicMock, Mock, call, patch
from unittest.mock import MagicMock, call, patch
from urllib.parse import quote

import lzstring
Expand Down Expand Up @@ -87,10 +87,10 @@ def test_capture_event(self, patch_process_event_with_plugins):
},
)

@patch("posthog.api.capture.push_scope")
@patch("posthog.api.capture.configure_scope")
@patch("posthog.api.capture.celery_app.send_task", MagicMock())
def test_capture_event_adds_library_to_sentry(self, patch_push_scope):
mock_set_tag = mock_sentry_context_for_tagging(patch_push_scope)
def test_capture_event_adds_library_to_sentry(self, patched_scope):
mock_set_tag = mock_sentry_context_for_tagging(patched_scope)

data = {
"event": "$autocapture",
Expand All @@ -112,10 +112,10 @@ def test_capture_event_adds_library_to_sentry(self, patch_push_scope):

mock_set_tag.assert_has_calls([call("library", "web"), call("library.version", "1.14.1")])

@patch("posthog.api.capture.push_scope")
@patch("posthog.api.capture.configure_scope")
@patch("posthog.api.capture.celery_app.send_task", MagicMock())
def test_capture_event_adds_unknown_to_sentry_when_no_properties_sent(self, patch_push_scope):
mock_set_tag = mock_sentry_context_for_tagging(patch_push_scope)
def test_capture_event_adds_unknown_to_sentry_when_no_properties_sent(self, patched_scope):
mock_set_tag = mock_sentry_context_for_tagging(patched_scope)

data = {
"event": "$autocapture",
Expand Down