Skip to content

Commit

Permalink
feat: HTTPSyncTransport and transport factories
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Jun 19, 2019
1 parent 61e843c commit f01cbee
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 101 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

## 0.0.1-beta.5

- feat: **[breaking]** Add `NewHTTPTransport` and `NewHTTPSyncTransport` which accepts all transport options
- feat: New `HTTPSyncTransport` that blocks after each call
- feat: New `Echo` integration
- ref: **[breaking]** Remove `BufferSize` option from `ClientOptions` and move it to `HTTPTransport` instead
- ref: Export default `HTTPTransport`
- ref: Export `net/http` integration handler
- ref: Set `Request` instantly in the package handlers, not in `recoverWithSentry` so it can be accessed later on
- ci: Add craft config
Expand Down
50 changes: 1 addition & 49 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,55 +73,7 @@ sentry.Init(sentry.ClientOptions{
})
```

Available options:

```go
// ClientOptions that configures a SDK Client
type ClientOptions struct {
// The DSN to use. If not set the client is effectively disabled.
Dsn string
// In debug mode debug information is printed to stdput to help you understand what
// sentry is doing.
Debug bool
// The sample rate for event submission (0.0 - 1.0, defaults to 1.0)
SampleRate float32
// Before send callback.
BeforeSend func(event *Event, hint *EventHint) *Event
// Before breadcrumb add callback.
BeforeBreadcrumb func(breadcrumb *Breadcrumb, hint *BreadcrumbHint) *Breadcrumb
// Integrations to be installed on the current Client
Integrations func([]Integration) []Integration
// io.Writer implementation that should be used with the `Debug` mode
DebugWriter io.Writer
// The transport to use.
// This is an instance of a struct implementing `Transport` interface.
// Defaults to `httpTransport` from `transport.go`
Transport Transport
// The server name to be reported.
ServerName string
// The release to be sent with events.
Release string
// The dist to be sent with events.
Dist string
// The environment to be sent with events.
Environment string
// Maximum number of breadcrumbs.
MaxBreadcrumbs int
// An optional pointer to `http.Transport` that will be used with a default HTTPTransport.
HTTPTransport *http.Transport
// An optional HTTP proxy to use.
// This will default to the `http_proxy` environment variable.
// or `https_proxy` if that one exists.
HTTPProxy string
// An optional HTTPS proxy to use.
// This will default to the `HTTPS_PROXY` environment variable
// or `http_proxy` if that one exists.
HTTPSProxy string
// An optionsl CaCerts to use.
// Defaults to `gocertifi.CACerts()`.
CaCerts *x509.CertPool
}
```
Available options: see [Configuration](https://docs.sentry.io/platforms/go/config/) section.

### Providing SSL Certificates

Expand Down
4 changes: 1 addition & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ type ClientOptions struct {
Environment string
// Maximum number of breadcrumbs.
MaxBreadcrumbs int
// An optional size of the transport buffer. Defaults to 30.
BufferSize int
// An optional pointer to `http.Transport` that will be used with a default HTTPTransport.
HTTPTransport *http.Transport
// An optional HTTP proxy to use.
Expand Down Expand Up @@ -147,7 +145,7 @@ func (client *Client) setupTransport() {
transport := client.options.Transport

if transport == nil {
transport = new(httpTransport)
transport = NewHTTPTransport()
}

transport.Configure(client.options)
Expand Down
2 changes: 1 addition & 1 deletion example/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func main() {
return breadcrumb
},
SampleRate: 1,
Transport: new(devNullTransport),
Transport: &devNullTransport{},
Integrations: func(integrations []sentry.Integration) []sentry.Integration {
return append(integrations, integrations[1])
},
Expand Down
2 changes: 1 addition & 1 deletion example/multiclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
return nil
},
Integrations: func(integrations []sentry.Integration) []sentry.Integration {
return append(integrations, new(pickleIntegration))
return append(integrations, &pickleIntegration{})
},
})
hub1 := sentry.NewHub(client1, scope1)
Expand Down
40 changes: 40 additions & 0 deletions example/synctransport/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"log"
"time"

"github.com/getsentry/sentry-go"
)

func main() {
sentrySyncTransport := sentry.NewHTTPSyncTransport()
sentrySyncTransport.Timeout = time.Second * 3

_ = sentry.Init(sentry.ClientOptions{
Dsn: "https://[email protected]/1337",
Debug: true,
Transport: sentrySyncTransport,
})

go func() {
sentry.CaptureMessage("Event #1")
log.Println(1)
sentry.CaptureMessage("Event #2")
log.Println(2)
}()

sentry.CaptureMessage("Event #3")
log.Println(3)
sentry.CaptureMessage("Event #4")
log.Println(4)
sentry.CaptureMessage("Event #5")
log.Println(5)

go func() {
sentry.CaptureMessage("Event #6")
log.Println(6)
sentry.CaptureMessage("Event #7")
log.Println(7)
}()
}
Loading

0 comments on commit f01cbee

Please sign in to comment.