Skip to content

Commit

Permalink
fix: Fix some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Oct 2, 2019
1 parent 60049e8 commit dc22543
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
2 changes: 2 additions & 0 deletions sentry_sdk/hub.py
Expand Up @@ -301,6 +301,8 @@ def bind_client(
"""Binds a new client to the hub."""
top = self._stack[-1]
self._stack[-1] = (new, top[1])
if not new or new.options["_experiments"].get("fast_serialize", False):
top[1].clear_breadcrumbs()

def capture_event(
self,
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/stdlib.py
Expand Up @@ -108,7 +108,6 @@ def getresponse(self, *args, **kwargs):
rv = real_getresponse(self, *args, **kwargs)

if data_dict is not None:
data_dict["httplib_response"] = rv
data_dict["status_code"] = rv.status
data_dict["reason"] = rv.reason
except TypeError:
Expand Down Expand Up @@ -200,7 +199,8 @@ def sentry_patched_popen_init(self, *a, **kw):
env["SUBPROCESS_" + k.upper().replace("-", "_")] = v

with hub.start_span(op="subprocess", description=description) as span:
span.set_data("subprocess.cwd", cwd)
if cwd:
span.set_data("subprocess.cwd", cwd)

rv = old_popen_init(self, *a, **kw) # type: ignore

Expand Down
27 changes: 15 additions & 12 deletions sentry_sdk/tracing.py
Expand Up @@ -338,13 +338,12 @@ def finish(self, hub=None):
)

def to_json(self, client):
# type: (Optional[sentry_sdk.Client]) -> Any
# type: (Optional[sentry_sdk.Client]) -> Dict[str, Any]
rv = {
"trace_id": self.trace_id,
"span_id": self.span_id,
"parent_span_id": self.parent_span_id,
"same_process_as_parent": self.same_process_as_parent,
"transaction": self.transaction,
"op": self.op,
"description": self.description,
"start_timestamp": partial_serialize(
Expand All @@ -356,9 +355,19 @@ def to_json(self, client):
"timestamp": partial_serialize(
client, self.timestamp, is_databag=False, should_repr_strings=False
),
"tags": self._tags,
"data": self._data,
}
} # type: Dict[str, Any]

transaction = self.transaction
if transaction:
rv["transaction"] = transaction

tags = self._tags
if tags:
rv["tags"] = tags

data = self._data
if data:
rv["data"] = data

return rv

Expand Down Expand Up @@ -460,17 +469,11 @@ def _maybe_create_breadcrumbs_from_span(hub, span):
message=span.description, type="redis", category="redis", data=span._tags
)
elif span.op == "http" and span.is_success():
hub.add_breadcrumb(
type="http",
category="httplib",
data=span._data,
hint={"httplib_response": span._data.pop("httplib_response", None)},
)
hub.add_breadcrumb(type="http", category="httplib", data=span._data)
elif span.op == "subprocess":
hub.add_breadcrumb(
type="subprocess",
category="subprocess",
message=span.description,
data=span._data,
hint={"popen_instance": span._data.pop("popen_instance", None)},
)
2 changes: 0 additions & 2 deletions tests/integrations/celery/test_celery.py
Expand Up @@ -131,14 +131,12 @@ def dummy_task(x, y):
assert execution_event["spans"] == []
assert submission_event["spans"] == [
{
u"data": {},
u"description": u"dummy_task",
u"op": "celery.submit",
u"parent_span_id": submission_event["contexts"]["trace"]["span_id"],
u"same_process_as_parent": True,
u"span_id": submission_event["spans"][0]["span_id"],
u"start_timestamp": submission_event["spans"][0]["start_timestamp"],
u"tags": {},
u"timestamp": submission_event["spans"][0]["timestamp"],
u"trace_id": text_type(span.trace_id),
}
Expand Down
5 changes: 1 addition & 4 deletions tests/integrations/stdlib/test_httplib.py
Expand Up @@ -40,10 +40,7 @@ def test_crumb_capture(sentry_init, capture_events):

def test_crumb_capture_hint(sentry_init, capture_events):
def before_breadcrumb(crumb, hint):
if "httplib_response" in hint:
con = hint["httplib_response"].getheader("Connection")
assert con.lower() == "close"
crumb["data"]["extra"] = "foo"
crumb["data"]["extra"] = "foo"
return crumb

sentry_init(integrations=[StdlibIntegration()], before_breadcrumb=before_breadcrumb)
Expand Down
1 change: 1 addition & 0 deletions tests/integrations/stdlib/test_subprocess.py
Expand Up @@ -123,6 +123,7 @@ def test_subprocess_basic(
assert message_event["message"] == "hi"

data = {"subprocess.cwd": os.getcwd()} if with_cwd else {}

crumb, = message_event["breadcrumbs"]
assert crumb == {
"category": "subprocess",
Expand Down

0 comments on commit dc22543

Please sign in to comment.