Skip to content

Commit

Permalink
Update to the new v2 reporting path. (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewDolan authored Oct 10, 2017
1 parent bf2e792 commit bd4ce9b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
27 changes: 20 additions & 7 deletions http_collector_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
"io/ioutil"
"net/http"
"time"
"net/url"
"fmt"
)

const (
collectorHttpMethod = "POST"
collectorHttpPath = "/v1/report"
collectorHttpPath = "/api/v2/reports"
collectorHttpContentTypeHeaderValue = "application/octet-stream"

contentTypeHeaderKey = "Content-Type"
Expand All @@ -30,8 +32,8 @@ type httpCollectorClient struct {
reportTimeout time.Duration

// Remote service that will receive reports.
socketAddress string
client *http.Client
url *url.URL
client *http.Client

// converters
converter *protoConverter
Expand All @@ -47,15 +49,26 @@ func (closer *transportCloser) Close() error {
return nil
}

func newHttpCollectorClient(opts Options, reporterID uint64, attributes map[string]string) *httpCollectorClient {
func newHttpCollectorClient(
opts Options,
reporterID uint64,
attributes map[string]string,
) (*httpCollectorClient, error) {
url, err := url.Parse(opts.Collector.HostPort())
if err != nil {
fmt.Println("collector config does not produce valid url", err)
return nil, err
}
url.Path = collectorHttpPath

return &httpCollectorClient{
reporterID: reporterID,
accessToken: opts.AccessToken,
attributes: attributes,
reportTimeout: opts.ReportTimeout,
socketAddress: opts.Collector.HostPort(),
url: url,
converter: newProtoConverter(opts),
}
}, nil
}

func (client *httpCollectorClient) ConnectClient() (Connection, error) {
Expand Down Expand Up @@ -112,7 +125,7 @@ func (client *httpCollectorClient) toRequest(

requestBody := bytes.NewReader(buf)

request, err := http.NewRequest(collectorHttpMethod, client.socketAddress+collectorHttpPath, requestBody)
request, err := http.NewRequest(collectorHttpMethod, client.url.String(), requestBody)
if err != nil {
return nil, err
}
Expand Down
14 changes: 9 additions & 5 deletions tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ func NewTracer(opts Options) Tracer {

impl.buffer.setCurrent(now)

impl.client = newClient(opts, impl.reporterID, attributes)
impl.client, err = newClient(opts, impl.reporterID, attributes)
if err != nil {
fmt.Println("Failed to create to Collector client!", err)
return nil
}

conn, err := impl.client.ConnectClient()
if err != nil {
Expand All @@ -144,21 +148,21 @@ func NewTracer(opts Options) Tracer {
}


func newClient(opts Options, reporterId uint64, attributes map[string]string) collectorClient {
func newClient(opts Options, reporterId uint64, attributes map[string]string) (collectorClient, error) {
if opts.UseThrift {
return newThriftCollectorClient(opts, reporterId, attributes)
return newThriftCollectorClient(opts, reporterId, attributes), nil
}

if opts.UseHttp {
return newHttpCollectorClient(opts, reporterId, attributes)
}

if opts.UseGRPC {
return newGrpcCollectorClient(opts, reporterId, attributes)
return newGrpcCollectorClient(opts, reporterId, attributes), nil
}

// No transport specified, defaulting to GRPC
return newGrpcCollectorClient(opts, reporterId, attributes)
return newGrpcCollectorClient(opts, reporterId, attributes), nil
}

func (tracer *tracerImpl) Options() Options {
Expand Down

0 comments on commit bd4ce9b

Please sign in to comment.