Skip to content

feat(attachments): Add basic support for attachments#856

Merged
mitsuhiko merged 19 commits into
masterfrom
feature/attachments
Oct 20, 2020
Merged

feat(attachments): Add basic support for attachments#856
mitsuhiko merged 19 commits into
masterfrom
feature/attachments

Conversation

@mitsuhiko

@mitsuhiko mitsuhiko commented Oct 12, 2020

Copy link
Copy Markdown
Contributor

Initial work in progress support for attachments.

Example integration that uploads stdout/stderr as attachments is here: https://gist.github.com/mitsuhiko/16815c06341370c90030b520984e6ee2

Comment thread sentry_sdk/scope.py
Comment thread sentry_sdk/client.py Outdated
Comment thread sentry_sdk/client.py Outdated
Comment thread sentry_sdk/client.py
Comment thread sentry_sdk/client.py
Comment thread sentry_sdk/client.py
if is_transaction:
envelope.add_transaction(event_opt)
else:
envelope.add_event(event_opt)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhcarvalho I'm starting to think this entire forcing events and transactions to go different paths on the envelope to be wrong-ish. We now need to check if it's a transaction or not to call a different method on the envelope but in both cases they do the same internally. The only difference is that add_event and add_transaction pass different event types.

@philipphofmann philipphofmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no real knowledge about Python, so my comments are mostly about the API and not language details. I didn't expect adding attachments to be so simple 😁

Comment thread sentry_sdk/client.py
Comment thread sentry_sdk/scope.py
Comment thread sentry_sdk/scope.py
Comment thread tests/test_basics.py
Comment thread sentry_sdk/attachments.py
Comment thread sentry_sdk/scope.py
Comment thread sentry_sdk/attachments.py Outdated
@mitsuhiko

Copy link
Copy Markdown
Contributor Author

Lots of comments, no approvals. Who can sign off on this?

@rhcarvalho rhcarvalho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had an idea to simplify the API, we may be able to reduce the number of input arguments and usage ambiguity.

cc @philipphofmann @bruno-garcia if that idea would translate well for your platforms of interest.

Comment thread sentry_sdk/attachments.py Outdated
Comment thread tests/test_basics.py
Comment thread tests/test_basics.py Outdated
Comment thread sentry_sdk/scope.py
@mitsuhiko

Copy link
Copy Markdown
Contributor Author

@philipphofmann i think this is ready to merge.

@philipphofmann philipphofmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only open question for me is why we don't have any overloads for add_attachment and the init of the attachment or maybe I'm missing something.

Either you want to pass bytes for an attachment or a file to read. So two methods would make sense for me. For the first method, you are forced to pass bytes and a filename for the second you only need to pass a path. This forces you to use the API right at compile time and you don't find out at runtime if you passed in the wrong arguments. We could ditch raising TypeError in the init of the Attachment. What do you think about that @mitsuhiko?

def add_attachment(
    self,
    bytes=None,  # type: bytes
    filename=None,  # type: str
    content_type=None,  # type: Optional[str]
    add_to_transactions=False,  # type: bool
)

def add_attachment(
    self,
    path=None,  # type: str
    filename=None,  # type: Optional[str]
    content_type=None,  # type: Optional[str]
    add_to_transactions=False,  # type: bool
)

Other comments are just nitpicking.

Comment thread sentry_sdk/client.py
Comment thread sentry_sdk/scope.py Outdated
Comment thread sentry_sdk/scope.py Outdated
Comment thread sentry_sdk/scope.py
@untitaker

Copy link
Copy Markdown
Member

@philipphofmann there's no such thing as an overload in Python. You can declare an overload in mypy, but that's almost outside of the language.

Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io>
@mitsuhiko

Copy link
Copy Markdown
Contributor Author

Basically what @untitaker said. This is how people do Python APIs :)

Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io>

@philipphofmann philipphofmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@philipphofmann

Copy link
Copy Markdown
Member

@philipphofmann there's no such thing as an overload in Python. You can declare an overload in mypy, but that's almost outside of the language.

Thanks, didn't know that. I never wrote a single line of Python yet 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants