Skip to content

Commit

Permalink
Add APM instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
axw committed Jul 17, 2020
1 parent 93e12d4 commit 678adef
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 18 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module github.com/graphaelli/zat
go 1.12

require (
go.elastic.co/apm v1.8.0
go.elastic.co/apm/module/apmhttp v1.8.0
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
google.golang.org/api v0.10.0
gopkg.in/yaml.v2 v2.2.4
Expand Down
52 changes: 52 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
cloud.google.com/go v0.38.0 h1:ROfEUZz+Gh5pa62DJWXSaonyu3StP6EA6lPEXPI6mCo=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cucumber/godog v0.8.1 h1:lVb+X41I4YDreE+ibZ50bdXmySxgRviYFgKY6Aw4XE8=
github.com/cucumber/godog v0.8.1/go.mod h1:vSh3r/lM+psC1BPXvdkSEuNjmXfpVqrMGYAElF6hxnA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/elastic/go-sysinfo v1.1.1 h1:ZVlaLDyhVkDfjwPGU55CQRCRolNpc7P0BbyhhQZQmMI=
github.com/elastic/go-sysinfo v1.1.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0=
github.com/elastic/go-windows v1.0.0 h1:qLURgZFkkrYyTTkvYpsZIgf83AUsdIHfvlJaqaZ7aSY=
github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
Expand All @@ -16,6 +27,8 @@ github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Z
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
Expand All @@ -24,7 +37,35 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4=
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURmKE=
github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ=
github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis=
github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
go.elastic.co/apm v1.8.0 h1:AWEKpHwRal0yCMd4K8Oxy1HAa7xid+xq1yy+XjgoVU0=
go.elastic.co/apm v1.8.0/go.mod h1:tCw6CkOJgkWnzEthFN9HUP1uL3Gjc/Ur6m7gRPLaoH0=
go.elastic.co/apm/module/apmhttp v1.8.0 h1:5AJPefWJzWDLX/47XIDfaloGiYWkkOQEULvlrI6Ieaw=
go.elastic.co/apm/module/apmhttp v1.8.0/go.mod h1:9LPFlEON51/lRbnWDfqAWErihIiAFDUMfMV27YjoWQ8=
go.elastic.co/fastjson v1.0.0 h1:ooXV/ABvf+tBul26jcVViPT3sBir0PvXgibYB1IQQzg=
go.elastic.co/fastjson v1.0.0/go.mod h1:PmeUOMMtLHQr9ZS9J9owrAVg0FkaZDRZJEFTTGHtchs=
go.opencensus.io v0.21.0 h1:mU6zScU4U1YAFPHEHYk+3JC4SY7JxgkqS10ZOSyksNg=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand All @@ -42,6 +83,8 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c h1:uOCk1iQW6Vc18bnC13MfzScl+wdKBmM9Y9kU7Z83/lw=
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
Expand All @@ -55,6 +98,9 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b h1:ag/x1USPSsqHud38I9BAC88qdNLDHHtQ4mlgQIZPPNA=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191025021431-6c3a3bfe00ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e h1:9vRrk9YW2BTzLP0VCB9ZDjU4cPqkg+IDWL7XgxA1yxQ=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
Expand Down Expand Up @@ -83,8 +129,14 @@ google.golang.org/grpc v1.20.1 h1:Hz2g2wirWK7H0qIIhGIqRGTuMwTE8HEKFnDZZ7lm9NU=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
howett.net/plist v0.0.0-20181124034731-591f970eefbb h1:jhnBjNi9UFpfpl8YZhA9CrOqpnJdvzuiHsl/dnxl11M=
howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=
51 changes: 38 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
"sync"
"time"

"go.elastic.co/apm"
"go.elastic.co/apm/module/apmhttp"
"golang.org/x/net/context/ctxhttp"
"google.golang.org/api/drive/v3"
"gopkg.in/yaml.v2"

Expand Down Expand Up @@ -104,7 +107,7 @@ func NewMux(zat *Config, params runParams) *http.ServeMux {
if andQuery != "" {
query += " and " + andQuery
}
files, err := googleClient.ListFiles(context.TODO(), query, "")
files, err := googleClient.ListFiles(r.Context(), query, "")
if err != nil {
logger.Print(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand All @@ -128,7 +131,7 @@ func NewMux(zat *Config, params runParams) *http.ServeMux {
return
}

recordings, err := zoomClient.ListRecordings(time.Now().Add(-168*time.Hour), "")
recordings, err := zoomClient.ListRecordings(r.Context(), time.Now().Add(-168*time.Hour), "")
if err != nil {
logger.Print(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down Expand Up @@ -232,6 +235,9 @@ func recordingFileName(meeting zoom.Meeting, recording zoom.RecordingFile) strin
}

func mkdir(ctx context.Context, gdrive *drive.Service, parent *drive.File, folder string) (*drive.File, error, bool) {
span, ctx := apm.StartSpan(ctx, "mkdir", "app")
defer span.End()

// maybe no need to check if it exists first, can just "mkdir -p" no matter what? for now look to enable dryrun
// exact match 1 folder
query := fmt.Sprintf("mimeType=%q and %q in parents and name=%q and trashed=false", google.MimeTypeFolder, parent.Id, folder)
Expand All @@ -251,14 +257,16 @@ func mkdir(ctx context.Context, gdrive *drive.Service, parent *drive.File, folde
Name: folder,
MimeType: google.MimeTypeFolder,
Parents: []string{parent.Id},
}).SupportsAllDrives(true).Do(); err != nil {
}).Context(ctx).SupportsAllDrives(true).Do(); err != nil {
return nil, err, false
} else {
return result, nil, true
}
}

func (z *Config) Archive(meeting zoom.Meeting, params runParams) error {
func (z *Config) Archive(ctx context.Context, meeting zoom.Meeting, params runParams) error {
span, ctx := apm.StartSpan(ctx, "Archive", "app")
defer span.End()

var curArchMeeting = archivedMeeting{name: meeting.Topic,
fileNumber: 0,
Expand All @@ -268,7 +276,7 @@ func (z *Config) Archive(meeting zoom.Meeting, params runParams) error {
archDetails = append(archDetails, &curArchMeeting)

// check what is already uploaded for this meeting
gdrive, err := z.googleClient.Service(context.TODO())
gdrive, err := z.googleClient.Service(ctx)
if err != nil {
return fmt.Errorf("while creating gdrive client: %w", err)
}
Expand All @@ -278,14 +286,15 @@ func (z *Config) Archive(meeting zoom.Meeting, params runParams) error {
curArchMeeting.status = "error"
return fmt.Errorf("no mapping found for meeting %d %q", meeting.ID, meeting.Topic)
}
parent, err := gdrive.Files.Get(parentFolderName).SupportsAllDrives(true).Do()

parent, err := gdrive.Files.Get(parentFolderName).Context(ctx).SupportsAllDrives(true).Do()
if err != nil {
curArchMeeting.status = "error"
return fmt.Errorf("while finding parent of %q: %w", parentFolderName, err)
}

// parent folder for this meeting
meetingFolder, err, created := mkdir(context.TODO(), gdrive, parent, meetingFolderName(meeting))
meetingFolder, err, created := mkdir(ctx, gdrive, parent, meetingFolderName(meeting))
if err != nil {
curArchMeeting.status = "error"
return fmt.Errorf("while finding/creating meeting folder: %w", err)
Expand All @@ -304,7 +313,11 @@ func (z *Config) Archive(meeting zoom.Meeting, params runParams) error {
alreadyUploaded := make(map[string]struct{})
nextPageToken := ""
for page := 0; page < 5; page++ {
call := gdrive.Files.List().SupportsTeamDrives(true).IncludeTeamDriveItems(true).Q(fmt.Sprintf("%q in parents", meetingFolder.Id))
call := gdrive.Files.List().
Context(ctx).
SupportsTeamDrives(true).
IncludeTeamDriveItems(true).
Q(fmt.Sprintf("%q in parents", meetingFolder.Id))
if nextPageToken != "" {
call = call.PageToken(nextPageToken)
}
Expand Down Expand Up @@ -355,11 +368,13 @@ func (z *Config) Archive(meeting zoom.Meeting, params runParams) error {
continue
}
z.logger.Printf("uploading %q to \"%s/%s\"", name, parent.Name, meetingFolder.Name)
r, err := http.Get(f.DownloadURL)
r, err := ctxhttp.Get(ctx, http.DefaultClient, f.DownloadURL)
if err != nil {
curArchMeeting.status = "error"
return fmt.Errorf("while downloading recording %s: %w", f.DownloadURL, err)
}
defer r.Body.Close()

if r.StatusCode != http.StatusOK {
curArchMeeting.status = "error"
return fmt.Errorf("while downloading recording %s: download failed, got %d error: %#v",
Expand All @@ -373,7 +388,7 @@ func (z *Config) Archive(meeting zoom.Meeting, params runParams) error {
_, err = gdrive.Files.Create(&drive.File{
Name: name,
Parents: []string{meetingFolder.Id},
}).Media(r.Body).SupportsAllDrives(true).Do()
}).Context(ctx).Media(r.Body).SupportsAllDrives(true).Do()
if err != nil {
curArchMeeting.status = "error"
return fmt.Errorf("while uploading recording %s: %w", f.DownloadURL, err)
Expand All @@ -391,21 +406,27 @@ type runParams struct {
}

func (z *Config) Run(params runParams) error {
tx := apm.DefaultTracer.StartTransaction("archiveRecordings", "background")
defer tx.End()
ctx := apm.ContextWithTransaction(context.Background(), tx)

z.logger.Print("archiving recordings")
archDetails = []*archivedMeeting{}
nextPageToken := ""
for {
recordings, err := z.zoomClient.ListRecordings(time.Now().Add(-1*params.since), nextPageToken)
recordings, err := z.zoomClient.ListRecordings(ctx, time.Now().Add(-1*params.since), nextPageToken)
if err != nil {
apm.CaptureError(ctx, err).Send()
return fmt.Errorf("failed to list recordings: %w", err)
}
for _, meeting := range recordings.Meetings {
if meeting.Duration < params.minDuration {
z.logger.Printf("skipped %d minute meeting at %s", meeting.Duration, meeting.StartTime)
continue
}
if err := z.Archive(meeting, params); err != nil {
if err := z.Archive(ctx, meeting, params); err != nil {
z.logger.Print(err)
apm.CaptureError(ctx, err).Send()
}
}
nextPageToken = recordings.NextPageToken
Expand Down Expand Up @@ -478,6 +499,10 @@ func main() {

logger := log.New(os.Stderr, "", cmd.LogFmt)

// Instrument http.DefaultClient and http.DefaultTransport.
http.DefaultClient = apmhttp.WrapClient(http.DefaultClient)
http.DefaultTransport = apmhttp.WrapRoundTripper(http.DefaultTransport)

googleClient, err := google.NewClientFromFile(
logger,
path.Join(*cfgDir, cmd.GoogleConfigPath),
Expand Down Expand Up @@ -511,7 +536,7 @@ func main() {
wg.Add(1)
server := http.Server{
Addr: *addr,
Handler: NewMux(zat, rp),
Handler: apmhttp.Wrap(NewMux(zat, rp)),
}
go func() {
logger.Printf("starting on http://%s", server.Addr)
Expand Down
10 changes: 5 additions & 5 deletions zoom/zoom.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (c *Client) HasCreds() bool {
src := c.config.TokenSource(context.TODO(), c.credentials)
newToken, err := src.Token() // this actually goes and renews the tokens
if err != nil {
c.logger.Printf("error updating google token %w", err)
c.logger.Printf("error updating google token %s", err)
return false
}
if newToken.AccessToken != c.credentials.AccessToken {
Expand All @@ -184,7 +184,7 @@ func (c *Client) addBearerAuth(r *http.Request) {
r.Header.Set("Authorization", "Bearer "+c.credentials.AccessToken)
}

func (c *Client) NewApiRequest(method, uri string) (*http.Request, error) {
func (c *Client) NewApiRequest(ctx context.Context, method, uri string) (*http.Request, error) {
u := *c.apiBaseUrl
u.Path = path.Join(u.Path, uri)
req, err := http.NewRequest(method, u.String(), nil)
Expand All @@ -194,7 +194,7 @@ func (c *Client) NewApiRequest(method, uri string) (*http.Request, error) {
if c.HasCreds() {
c.addBearerAuth(req)
}
return req, nil
return req.WithContext(ctx), nil
}

func (c *Client) Do(req *http.Request, decodeTo interface{}) (*http.Response, error) {
Expand Down Expand Up @@ -249,9 +249,9 @@ func (c *Client) OauthHandler() func(w http.ResponseWriter, r *http.Request) {
// TODO: accept ListRecordingsRequest
// TODO: allow setting "to" to address > 30 day spans
// https://marketplace.zoom.us/docs/api-reference/zoom-api/cloud-recording/recordingslist
func (c *Client) ListRecordings(since time.Time, nextPageToken string) (*ListRecordingsResponse, error) {
func (c *Client) ListRecordings(ctx context.Context, since time.Time, nextPageToken string) (*ListRecordingsResponse, error) {
var j ListRecordingsResponse
req, err := c.NewApiRequest(http.MethodGet, "v2/users/me/recordings")
req, err := c.NewApiRequest(ctx, http.MethodGet, "v2/users/me/recordings")
if err != nil {
return nil, fmt.Errorf("while building ListRecordings request: %w", err)
}
Expand Down

0 comments on commit 678adef

Please sign in to comment.