Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit f6aefa2

Browse files
author
Trevor Rosen
authored
Update MetricAttributes; more debugging support (#76)
Fixes #75
1 parent e79236e commit f6aefa2

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

client.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ func (c *Client) DefaultPaginationParameters(length int) *PaginationParameters {
244244

245245
// Do performs the HTTP request on the wire, taking an optional second parameter for containing a response
246246
func (c *Client) Do(req *http.Request, respData interface{}) (*http.Response, error) {
247+
if c.debugMode {
248+
dumpRequest(req)
249+
}
250+
247251
resp, err := c.httpClient.Do(req)
248252

249253
// error in performing request
@@ -307,7 +311,7 @@ func dumpResponse(resp *http.Response) {
307311
fmt.Printf("response status: %s\n", resp.Status)
308312
if resp.ContentLength != 0 {
309313
if respBytes, err := ioutil.ReadAll(resp.Body); err != nil {
310-
log.Printf("Error reading body: %s", err)
314+
log.Printf("error reading body: %s", err)
311315
return
312316
} else {
313317
resp.Body.Close()
@@ -316,3 +320,19 @@ func dumpResponse(resp *http.Response) {
316320
}
317321
}
318322
}
323+
324+
// dumpRequest is a debugging function which dumps the HTTP request to stdout
325+
func dumpRequest(req *http.Request) {
326+
if req.Body == nil{
327+
return
328+
}
329+
330+
if reqBytes, err := ioutil.ReadAll(req.Body); err != nil {
331+
log.Printf("error reading body: %s", err)
332+
return
333+
} else {
334+
req.Body.Close()
335+
req.Body = ioutil.NopCloser(bytes.NewBuffer(reqBytes))
336+
log.Printf("request body: %s\n\n", string(reqBytes))
337+
}
338+
}

metrics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type MetricAttributes struct {
2424
CreatedByUA string `json:"created_by_ua,omitempty"`
2525
GapDetection bool `json:"gap_detection,omitempty"`
2626
Aggregate bool `json:"aggregate,omitempty"`
27+
SummarizeFunction string `json:"summarize_function,omitempty"`
2728
}
2829

2930
type MetricsResponse struct {

0 commit comments

Comments
 (0)