Created
February 6, 2023 16:33
-
-
Save hermanbanken/2f72daf19fb47ac28143904962dea3e0 to your computer and use it in GitHub Desktop.
Download Google Cloud Trace as JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module github.com/q42philips/trace-export | |
go 1.19 | |
require cloud.google.com/go/trace v1.8.0 | |
require ( | |
cloud.google.com/go/compute v1.14.0 // indirect | |
cloud.google.com/go/compute/metadata v0.2.3 // indirect | |
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect | |
github.com/golang/protobuf v1.5.2 // indirect | |
github.com/google/go-cmp v0.5.9 // indirect | |
github.com/googleapis/enterprise-certificate-proxy v0.2.1 // indirect | |
github.com/googleapis/gax-go/v2 v2.7.0 // indirect | |
go.opencensus.io v0.24.0 // indirect | |
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect | |
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect | |
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect | |
golang.org/x/text v0.5.0 // indirect | |
google.golang.org/api v0.108.0 // indirect | |
google.golang.org/appengine v1.6.7 // indirect | |
google.golang.org/genproto v0.0.0-20230125152338-dcaf20b6aeaa // indirect | |
google.golang.org/grpc v1.51.0 // indirect | |
google.golang.org/protobuf v1.28.1 // indirect | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"encoding/json" | |
"os" | |
trace "cloud.google.com/go/trace/apiv1" | |
tracepb "cloud.google.com/go/trace/apiv1/tracepb" | |
) | |
// copied from https://pkg.go.dev/cloud.google.com/go/[email protected]/apiv1#Client.GetTrace | |
func main() { | |
ctx := context.Background() | |
c, err := trace.NewClient(ctx) | |
if err != nil { | |
panic(err) | |
} | |
defer c.Close() | |
// See https://pkg.go.dev/cloud.google.com/go/trace/apiv1/tracepb#GetTraceRequest. | |
req := &tracepb.GetTraceRequest{ | |
ProjectId: os.Getenv("PROJECT"), | |
TraceId: os.Getenv("TRACE"), | |
} | |
resp, err := c.GetTrace(ctx, req) | |
if err != nil { | |
panic(err) | |
} | |
// Output as JSON | |
bytes, err := json.MarshalIndent(resp, "", " ") | |
if err != nil { | |
panic(err) | |
} | |
os.Stdout.Write(bytes) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment