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

feat: Add Transactions to sentry-go #235

Merged
merged 19 commits into from
Jun 3, 2020
Merged

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Jun 1, 2020

Motivation

This PR aims to add the concept of a transaction to sentry-go. This is important for us so that we can leverage the sentry-go transport in the otel-collector. This also setups the interfaces so that we can possibly add AM support to sentry-go in the future.

Implementation

We add a struct type Span to represent a Sentry span. We also edit the Event struct to add three new fields, StartTimestamp, Spans, and Type. By setting Type == "transaction", users will send transaction events.

The transport code was also changed to account for this. If a type == "transaction" is detected, it will use the envelopes endpoint instead.

Testing

A few unit tests have been added to test the new functions added. This functionality was also demoed with the collector, and was found to be fully functional with no regressions found.

@AbhiPrasad AbhiPrasad changed the title [WIP] feat: Add Transactions to sentry-go feat: Add Transactions to sentry-go Jun 2, 2020
@AbhiPrasad AbhiPrasad marked this pull request as ready for review June 2, 2020 13:12
@AbhiPrasad
Copy link
Member Author

Seems CI is broken due to go-errors/errors#27

dsn.go Outdated Show resolved Hide resolved
interfaces.go Outdated Show resolved Hide resolved
interfaces.go Outdated Show resolved Hide resolved
interfaces.go Outdated Show resolved Hide resolved
interfaces.go Outdated Show resolved Hide resolved
interfaces.go Outdated Show resolved Hide resolved
interfaces.go Outdated Show resolved Hide resolved
interfaces_test.go Outdated Show resolved Hide resolved
interfaces_test.go Outdated Show resolved Hide resolved
interfaces_test.go Outdated Show resolved Hide resolved
transport_test.go Outdated Show resolved Hide resolved
transport_test.go Outdated Show resolved Hide resolved
- fix: Change how DSN API URL is formatted
- test: Don't calculate DSN every loop in transport test
- test: Compare envelope payload using cpm.Diff
@AbhiPrasad
Copy link
Member Author

AbhiPrasad commented Jun 3, 2020

@rhcarvalho This is ready for another pass.

Summary of changes since last review:

  • I adjusted the event marshalJSON to account for transaction specific fields (type, start_timestamp, spans). I also added new tests to account for this new functionality in interfaces_test.go
  • I made the change from using %v to %s in the DSN fmt
  • I adjusted the transport test to not re-parse DSN every test case loop
  • I changed the envelope payload test to compare bytes, but still kept some functionality from before to account for the fact that the sent_at field is set using time.Now() Updated the envelope creation function and test
  • I fixed up comments and formatting

The changes were again tested with the collector and found to be working 👍

transport.go Outdated Show resolved Hide resolved
transport_test.go Outdated Show resolved Hide resolved
transport.go Outdated Show resolved Hide resolved
rhcarvalho and others added 9 commits June 3, 2020 17:44
- Move new types down
- Sort +- logically Span fields
- set `omitempty` for `Span.Status`
To keep code related to DSN manipulation consistently together.
The object is to document better what is being done there and why, and
to avoid repeating tricks to work around differences between error
events and transactions.

Also fixed tests that were broken by my previous commits directly on
GitHub (change of order in struct fields change serialized JSON).

Also removed optional newline at the end of the envelope -- less bytes
is better? A typical request payload does not require the extra new
line, and the net/http library handles HTTP protocol under the hood
(e.g. setting Content-Length header).
With the line in, the comment does not show up in godoc output.
Copy link
Contributor

@rhcarvalho rhcarvalho left a comment

Choose a reason for hiding this comment

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

@AbhiPrasad I think we're almost done. Please have a review yourself too. I have one comment that could be addressed in a follow up.

Comment on lines -190 to -199
body := getRequestBodyFromEvent(event)
if body == nil {
request, err := getRequestFromEvent(event, t.dsn)
if err != nil {
return
}

request, _ := http.NewRequest(
http.MethodPost,
t.dsn.StoreAPIURL().String(),
bytes.NewBuffer(body),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

There are two builtin transport implementations, we need this to be applied to HTTPSyncTransport too, so it becomes an alternative to send transactions/envelopes too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will address this in next PR

@AbhiPrasad AbhiPrasad merged commit 8a3c4a7 into master Jun 3, 2020
@AbhiPrasad AbhiPrasad deleted the abhi/feat/transactions branch June 3, 2020 22:51
AbhiPrasad added a commit that referenced this pull request Jun 3, 2020
* feat: Add Transaction and Span structs
* ref: Update functions to work with transaction events
* ref: Update DSN to work with envelope endpoint
* test: Add golden test to snapshot test important interfaces
* ref: Update transport to use envelopes endpoint

Co-authored-by: Rodolfo Carvalho <rodolfo.carvalho@sentry.io>
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.

None yet

2 participants