| // Copyright 2026 Google LLC. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| // Code generated file. DO NOT EDIT. |
| |
| // Package cloudtrace provides access to the Cloud Trace API. |
| // |
| // For product documentation, see: https://cloud.google.com/trace/ |
| // |
| // # Library status |
| // |
| // These client libraries are officially supported by Google. However, this |
| // library is considered complete and is in maintenance mode. This means |
| // that we will address critical bugs and security issues but will not add |
| // any new features. |
| // |
| // When possible, we recommend using our newer |
| // [Cloud Client Libraries for Go](https://pkg.go.dev/cloud.google.com/go) |
| // that are still actively being worked and iterated on. |
| // |
| // # Creating a client |
| // |
| // Usage example: |
| // |
| // import "google.golang.org/api/cloudtrace/v1" |
| // ... |
| // ctx := context.Background() |
| // cloudtraceService, err := cloudtrace.NewService(ctx) |
| // |
| // In this example, Google Application Default Credentials are used for |
| // authentication. For information on how to create and obtain Application |
| // Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials. |
| // |
| // # Other authentication options |
| // |
| // By default, all available scopes (see "Constants") are used to authenticate. |
| // To restrict scopes, use [google.golang.org/api/option.WithScopes]: |
| // |
| // cloudtraceService, err := cloudtrace.NewService(ctx, option.WithScopes(cloudtrace.TraceReadonlyScope)) |
| // |
| // To use an API key for authentication (note: some APIs do not support API |
| // keys), use [google.golang.org/api/option.WithAPIKey]: |
| // |
| // cloudtraceService, err := cloudtrace.NewService(ctx, option.WithAPIKey("AIza...")) |
| // |
| // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth |
| // flow, use [google.golang.org/api/option.WithTokenSource]: |
| // |
| // config := &oauth2.Config{...} |
| // // ... |
| // token, err := config.Exchange(ctx, ...) |
| // cloudtraceService, err := cloudtrace.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token))) |
| // |
| // See [google.golang.org/api/option.ClientOption] for details on options. |
| package cloudtrace // import "google.golang.org/api/cloudtrace/v1" |
| |
| import ( |
| "bytes" |
| "context" |
| "encoding/json" |
| "errors" |
| "fmt" |
| "io" |
| "log/slog" |
| "net/http" |
| "net/url" |
| "strconv" |
| "strings" |
| |
| "github.com/googleapis/gax-go/v2/internallog" |
| googleapi "google.golang.org/api/googleapi" |
| internal "google.golang.org/api/internal" |
| gensupport "google.golang.org/api/internal/gensupport" |
| option "google.golang.org/api/option" |
| internaloption "google.golang.org/api/option/internaloption" |
| htransport "google.golang.org/api/transport/http" |
| ) |
| |
| // Always reference these packages, just in case the auto-generated code |
| // below doesn't. |
| var _ = bytes.NewBuffer |
| var _ = strconv.Itoa |
| var _ = fmt.Sprintf |
| var _ = json.NewDecoder |
| var _ = io.Copy |
| var _ = url.Parse |
| var _ = gensupport.MarshalJSON |
| var _ = googleapi.Version |
| var _ = errors.New |
| var _ = strings.Replace |
| var _ = context.Canceled |
| var _ = internaloption.WithDefaultEndpoint |
| var _ = internal.Version |
| var _ = internallog.New |
| |
| const apiId = "cloudtrace:v1" |
| const apiName = "cloudtrace" |
| const apiVersion = "v1" |
| const basePath = "https://cloudtrace.googleapis.com/" |
| const basePathTemplate = "https://cloudtrace.UNIVERSE_DOMAIN/" |
| const mtlsBasePath = "https://cloudtrace.mtls.googleapis.com/" |
| |
| // OAuth2 scopes used by this API. |
| const ( |
| // See, edit, configure, and delete your Google Cloud data and see the email |
| // address for your Google Account. |
| CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform" |
| |
| // Write Trace data for a project or application |
| TraceAppendScope = "https://www.googleapis.com/auth/trace.append" |
| |
| // Read Trace data for a project or application |
| TraceReadonlyScope = "https://www.googleapis.com/auth/trace.readonly" |
| ) |
| |
| // NewService creates a new Service. |
| func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) { |
| scopesOption := internaloption.WithDefaultScopes( |
| "https://www.googleapis.com/auth/cloud-platform", |
| "https://www.googleapis.com/auth/trace.append", |
| "https://www.googleapis.com/auth/trace.readonly", |
| ) |
| // NOTE: prepend, so we don't override user-specified scopes. |
| opts = append([]option.ClientOption{scopesOption}, opts...) |
| opts = append(opts, internaloption.WithDefaultEndpoint(basePath)) |
| opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate)) |
| opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath)) |
| opts = append(opts, internaloption.EnableNewAuthLibrary()) |
| client, endpoint, err := htransport.NewClient(ctx, opts...) |
| if err != nil { |
| return nil, err |
| } |
| s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} |
| s.Projects = NewProjectsService(s) |
| if endpoint != "" { |
| s.BasePath = endpoint |
| } |
| return s, nil |
| } |
| |
| // New creates a new Service. It uses the provided http.Client for requests. |
| // |
| // Deprecated: please use NewService instead. |
| // To provide a custom HTTP client, use option.WithHTTPClient. |
| // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead. |
| func New(client *http.Client) (*Service, error) { |
| if client == nil { |
| return nil, errors.New("client is nil") |
| } |
| return NewService(context.TODO(), option.WithHTTPClient(client)) |
| } |
| |
| type Service struct { |
| client *http.Client |
| logger *slog.Logger |
| BasePath string // API endpoint base URL |
| UserAgent string // optional additional User-Agent fragment |
| |
| Projects *ProjectsService |
| } |
| |
| func (s *Service) userAgent() string { |
| if s.UserAgent == "" { |
| return googleapi.UserAgent |
| } |
| return googleapi.UserAgent + " " + s.UserAgent |
| } |
| |
| func NewProjectsService(s *Service) *ProjectsService { |
| rs := &ProjectsService{s: s} |
| rs.Traces = NewProjectsTracesService(s) |
| return rs |
| } |
| |
| type ProjectsService struct { |
| s *Service |
| |
| Traces *ProjectsTracesService |
| } |
| |
| func NewProjectsTracesService(s *Service) *ProjectsTracesService { |
| rs := &ProjectsTracesService{s: s} |
| return rs |
| } |
| |
| type ProjectsTracesService struct { |
| s *Service |
| } |
| |
| // Empty: A generic empty message that you can re-use to avoid defining |
| // duplicated empty messages in your APIs. A typical example is to use it as |
| // the request or the response type of an API method. For instance: service Foo |
| // { rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); } |
| type Empty struct { |
| // ServerResponse contains the HTTP response code and headers from the server. |
| googleapi.ServerResponse `json:"-"` |
| } |
| |
| // ListTracesResponse: The response message for the `ListTraces` method. |
| type ListTracesResponse struct { |
| // NextPageToken: If defined, indicates that there are more traces that match |
| // the request and that this value should be passed to the next request to |
| // continue retrieving additional traces. |
| NextPageToken string `json:"nextPageToken,omitempty"` |
| // Traces: List of trace records as specified by the view parameter. |
| Traces []*Trace `json:"traces,omitempty"` |
| |
| // ServerResponse contains the HTTP response code and headers from the server. |
| googleapi.ServerResponse `json:"-"` |
| // ForceSendFields is a list of field names (e.g. "NextPageToken") to |
| // unconditionally include in API requests. By default, fields with empty or |
| // default values are omitted from API requests. See |
| // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more |
| // details. |
| ForceSendFields []string `json:"-"` |
| // NullFields is a list of field names (e.g. "NextPageToken") to include in API |
| // requests with the JSON null value. By default, fields with empty values are |
| // omitted from API requests. See |
| // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details. |
| NullFields []string `json:"-"` |
| } |
| |
| func (s ListTracesResponse) MarshalJSON() ([]byte, error) { |
| type NoMethod ListTracesResponse |
| return gensupport.MarshalJSON(NoMethod(s), s.ForceSendFields, s.NullFields) |
| } |
| |
| // Trace: A trace describes how long it takes for an application to perform an |
| // operation. It consists of a set of spans, each of which represent a single |
| // timed event within the operation. |
| type Trace struct { |
| // ProjectId: Project ID of the Cloud project where the trace data is stored. |
| ProjectId string `json:"projectId,omitempty"` |
| // Spans: Collection of spans in the trace. |
| Spans []*TraceSpan `json:"spans,omitempty"` |
| // TraceId: Globally unique identifier for the trace. This identifier is a |
| // 128-bit numeric value formatted as a 32-byte hex string. For example, |
| // `382d4f4c6b7bb2f4a972559d9085001d`. The numeric value should not be zero. |
| TraceId string `json:"traceId,omitempty"` |
| |
| // ServerResponse contains the HTTP response code and headers from the server. |
| googleapi.ServerResponse `json:"-"` |
| // ForceSendFields is a list of field names (e.g. "ProjectId") to |
| // unconditionally include in API requests. By default, fields with empty or |
| // default values are omitted from API requests. See |
| // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more |
| // details. |
| ForceSendFields []string `json:"-"` |
| // NullFields is a list of field names (e.g. "ProjectId") to include in API |
| // requests with the JSON null value. By default, fields with empty values are |
| // omitted from API requests. See |
| // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details. |
| NullFields []string `json:"-"` |
| } |
| |
| func (s Trace) MarshalJSON() ([]byte, error) { |
| type NoMethod Trace |
| return gensupport.MarshalJSON(NoMethod(s), s.ForceSendFields, s.NullFields) |
| } |
| |
| // TraceSpan: A span represents a single timed event within a trace. Spans can |
| // be nested and form a trace tree. Often, a trace contains a root span that |
| // describes the end-to-end latency of an operation and, optionally, one or |
| // more subspans for its suboperations. Spans do not need to be contiguous. |
| // There may be gaps between spans in a trace. |
| type TraceSpan struct { |
| // EndTime: End time of the span in seconds and nanoseconds from the UNIX |
| // epoch. |
| EndTime string `json:"endTime,omitempty"` |
| // Kind: Distinguishes between spans generated in a particular context. For |
| // example, two spans with the same name may be distinguished using |
| // `RPC_CLIENT` and `RPC_SERVER` to identify queueing latency associated with |
| // the span. |
| // |
| // Possible values: |
| // "SPAN_KIND_UNSPECIFIED" - Unspecified. |
| // "RPC_SERVER" - Indicates that the span covers server-side handling of an |
| // RPC or other remote network request. |
| // "RPC_CLIENT" - Indicates that the span covers the client-side wrapper |
| // around an RPC or other remote request. |
| Kind string `json:"kind,omitempty"` |
| // Labels: Collection of labels associated with the span. Label keys must be |
| // less than 128 bytes. Label values must be less than 16 KiB. Some keys might |
| // have predefined meaning, and you can also create your own. For more |
| // information, see Cloud Trace labels |
| // (https://cloud.google.com/trace/docs/trace-labels). |
| Labels map[string]string `json:"labels,omitempty"` |
| // Name: Name of the span. Must be less than 128 bytes. The span name is |
| // sanitized and displayed in the Trace tool in the Google Cloud Platform |
| // Console. The name may be a method name or some other per-call site name. For |
| // the same executable and the same call point, a best practice is to use a |
| // consistent name, which makes it easier to correlate cross-trace spans. |
| Name string `json:"name,omitempty"` |
| // ParentSpanId: Optional. ID of the parent span, if any. |
| ParentSpanId uint64 `json:"parentSpanId,omitempty,string"` |
| // SpanId: Identifier for the span. Must be a 64-bit integer other than 0 and |
| // unique within a trace. For example, `2205310701640571284`. |
| SpanId uint64 `json:"spanId,omitempty,string"` |
| // StartTime: Start time of the span in seconds and nanoseconds from the UNIX |
| // epoch. |
| StartTime string `json:"startTime,omitempty"` |
| // ForceSendFields is a list of field names (e.g. "EndTime") to unconditionally |
| // include in API requests. By default, fields with empty or default values are |
| // omitted from API requests. See |
| // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more |
| // details. |
| ForceSendFields []string `json:"-"` |
| // NullFields is a list of field names (e.g. "EndTime") to include in API |
| // requests with the JSON null value. By default, fields with empty values are |
| // omitted from API requests. See |
| // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details. |
| NullFields []string `json:"-"` |
| } |
| |
| func (s TraceSpan) MarshalJSON() ([]byte, error) { |
| type NoMethod TraceSpan |
| return gensupport.MarshalJSON(NoMethod(s), s.ForceSendFields, s.NullFields) |
| } |
| |
| // Traces: List of new or updated traces. |
| type Traces struct { |
| // Traces: List of traces. |
| Traces []*Trace `json:"traces,omitempty"` |
| // ForceSendFields is a list of field names (e.g. "Traces") to unconditionally |
| // include in API requests. By default, fields with empty or default values are |
| // omitted from API requests. See |
| // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more |
| // details. |
| ForceSendFields []string `json:"-"` |
| // NullFields is a list of field names (e.g. "Traces") to include in API |
| // requests with the JSON null value. By default, fields with empty values are |
| // omitted from API requests. See |
| // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details. |
| NullFields []string `json:"-"` |
| } |
| |
| func (s Traces) MarshalJSON() ([]byte, error) { |
| type NoMethod Traces |
| return gensupport.MarshalJSON(NoMethod(s), s.ForceSendFields, s.NullFields) |
| } |
| |
| type ProjectsPatchTracesCall struct { |
| s *Service |
| projectId string |
| traces *Traces |
| urlParams_ gensupport.URLParams |
| ctx_ context.Context |
| header_ http.Header |
| } |
| |
| // PatchTraces: Sends trace spans to Cloud Trace. Spans cannot be updated. If |
| // the trace ID and span ID already exist, an additional copy of the span will |
| // be stored. |
| // |
| // - projectId: ID of the Cloud project where the trace data is stored. |
| func (r *ProjectsService) PatchTraces(projectId string, traces *Traces) *ProjectsPatchTracesCall { |
| c := &ProjectsPatchTracesCall{s: r.s, urlParams_: make(gensupport.URLParams)} |
| c.projectId = projectId |
| c.traces = traces |
| return c |
| } |
| |
| // Fields allows partial responses to be retrieved. See |
| // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more |
| // details. |
| func (c *ProjectsPatchTracesCall) Fields(s ...googleapi.Field) *ProjectsPatchTracesCall { |
| c.urlParams_.Set("fields", googleapi.CombineFields(s)) |
| return c |
| } |
| |
| // Context sets the context to be used in this call's Do method. |
| func (c *ProjectsPatchTracesCall) Context(ctx context.Context) *ProjectsPatchTracesCall { |
| c.ctx_ = ctx |
| return c |
| } |
| |
| // Header returns a http.Header that can be modified by the caller to add |
| // headers to the request. |
| func (c *ProjectsPatchTracesCall) Header() http.Header { |
| if c.header_ == nil { |
| c.header_ = make(http.Header) |
| } |
| return c.header_ |
| } |
| |
| func (c *ProjectsPatchTracesCall) doRequest(alt string) (*http.Response, error) { |
| reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) |
| body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.traces) |
| if err != nil { |
| return nil, err |
| } |
| c.urlParams_.Set("alt", alt) |
| c.urlParams_.Set("prettyPrint", "false") |
| urls := googleapi.ResolveRelative(c.s.BasePath, "v1/projects/{projectId}/traces") |
| urls += "?" + c.urlParams_.Encode() |
| req, err := http.NewRequest("PATCH", urls, body) |
| if err != nil { |
| return nil, err |
| } |
| req.Header = reqHeaders |
| googleapi.Expand(req.URL, map[string]string{ |
| "projectId": c.projectId, |
| }) |
| c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "cloudtrace.projects.patchTraces", "request", internallog.HTTPRequest(req, body.Bytes())) |
| return gensupport.SendRequest(c.ctx_, c.s.client, req) |
| } |
| |
| // Do executes the "cloudtrace.projects.patchTraces" call. |
| // Any non-2xx status code is an error. Response headers are in either |
| // *Empty.ServerResponse.Header or (if a response was returned at all) in |
| // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check |
| // whether the returned error was because http.StatusNotModified was returned. |
| func (c *ProjectsPatchTracesCall) Do(opts ...googleapi.CallOption) (*Empty, error) { |
| gensupport.SetOptions(c.urlParams_, opts...) |
| res, err := c.doRequest("json") |
| if res != nil && res.StatusCode == http.StatusNotModified { |
| if res.Body != nil { |
| res.Body.Close() |
| } |
| return nil, gensupport.WrapError(&googleapi.Error{ |
| Code: res.StatusCode, |
| Header: res.Header, |
| }) |
| } |
| if err != nil { |
| return nil, err |
| } |
| defer googleapi.CloseBody(res) |
| if err := googleapi.CheckResponse(res); err != nil { |
| return nil, gensupport.WrapError(err) |
| } |
| ret := &Empty{ |
| ServerResponse: googleapi.ServerResponse{ |
| Header: res.Header, |
| HTTPStatusCode: res.StatusCode, |
| }, |
| } |
| target := &ret |
| b, err := gensupport.DecodeResponseBytes(target, res) |
| if err != nil { |
| return nil, err |
| } |
| c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "cloudtrace.projects.patchTraces", "response", internallog.HTTPResponse(res, b)) |
| return ret, nil |
| } |
| |
| type ProjectsTracesGetCall struct { |
| s *Service |
| projectId string |
| traceId string |
| urlParams_ gensupport.URLParams |
| ifNoneMatch_ string |
| ctx_ context.Context |
| header_ http.Header |
| } |
| |
| // Get: Gets a single trace by its ID. |
| // |
| // - projectId: ID of the Cloud project where the trace data is stored. |
| // - traceId: ID of the trace to return. |
| func (r *ProjectsTracesService) Get(projectId string, traceId string) *ProjectsTracesGetCall { |
| c := &ProjectsTracesGetCall{s: r.s, urlParams_: make(gensupport.URLParams)} |
| c.projectId = projectId |
| c.traceId = traceId |
| return c |
| } |
| |
| // Fields allows partial responses to be retrieved. See |
| // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more |
| // details. |
| func (c *ProjectsTracesGetCall) Fields(s ...googleapi.Field) *ProjectsTracesGetCall { |
| c.urlParams_.Set("fields", googleapi.CombineFields(s)) |
| return c |
| } |
| |
| // IfNoneMatch sets an optional parameter which makes the operation fail if the |
| // object's ETag matches the given value. This is useful for getting updates |
| // only after the object has changed since the last request. |
| func (c *ProjectsTracesGetCall) IfNoneMatch(entityTag string) *ProjectsTracesGetCall { |
| c.ifNoneMatch_ = entityTag |
| return c |
| } |
| |
| // Context sets the context to be used in this call's Do method. |
| func (c *ProjectsTracesGetCall) Context(ctx context.Context) *ProjectsTracesGetCall { |
| c.ctx_ = ctx |
| return c |
| } |
| |
| // Header returns a http.Header that can be modified by the caller to add |
| // headers to the request. |
| func (c *ProjectsTracesGetCall) Header() http.Header { |
| if c.header_ == nil { |
| c.header_ = make(http.Header) |
| } |
| return c.header_ |
| } |
| |
| func (c *ProjectsTracesGetCall) doRequest(alt string) (*http.Response, error) { |
| reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_) |
| if c.ifNoneMatch_ != "" { |
| reqHeaders.Set("If-None-Match", c.ifNoneMatch_) |
| } |
| c.urlParams_.Set("alt", alt) |
| c.urlParams_.Set("prettyPrint", "false") |
| urls := googleapi.ResolveRelative(c.s.BasePath, "v1/projects/{projectId}/traces/{traceId}") |
| urls += "?" + c.urlParams_.Encode() |
| req, err := http.NewRequest("GET", urls, nil) |
| if err != nil { |
| return nil, err |
| } |
| req.Header = reqHeaders |
| googleapi.Expand(req.URL, map[string]string{ |
| "projectId": c.projectId, |
| "traceId": c.traceId, |
| }) |
| c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "cloudtrace.projects.traces.get", "request", internallog.HTTPRequest(req, nil)) |
| return gensupport.SendRequest(c.ctx_, c.s.client, req) |
| } |
| |
| // Do executes the "cloudtrace.projects.traces.get" call. |
| // Any non-2xx status code is an error. Response headers are in either |
| // *Trace.ServerResponse.Header or (if a response was returned at all) in |
| // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check |
| // whether the returned error was because http.StatusNotModified was returned. |
| func (c *ProjectsTracesGetCall) Do(opts ...googleapi.CallOption) (*Trace, error) { |
| gensupport.SetOptions(c.urlParams_, opts...) |
| res, err := c.doRequest("json") |
| if res != nil && res.StatusCode == http.StatusNotModified { |
| if res.Body != nil { |
| res.Body.Close() |
| } |
| return nil, gensupport.WrapError(&googleapi.Error{ |
| Code: res.StatusCode, |
| Header: res.Header, |
| }) |
| } |
| if err != nil { |
| return nil, err |
| } |
| defer googleapi.CloseBody(res) |
| if err := googleapi.CheckResponse(res); err != nil { |
| return nil, gensupport.WrapError(err) |
| } |
| ret := &Trace{ |
| ServerResponse: googleapi.ServerResponse{ |
| Header: res.Header, |
| HTTPStatusCode: res.StatusCode, |
| }, |
| } |
| target := &ret |
| b, err := gensupport.DecodeResponseBytes(target, res) |
| if err != nil { |
| return nil, err |
| } |
| c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "cloudtrace.projects.traces.get", "response", internallog.HTTPResponse(res, b)) |
| return ret, nil |
| } |
| |
| type ProjectsTracesListCall struct { |
| s *Service |
| projectId string |
| urlParams_ gensupport.URLParams |
| ifNoneMatch_ string |
| ctx_ context.Context |
| header_ http.Header |
| } |
| |
| // List: Returns a list of traces that match the specified filter conditions. |
| // |
| // - projectId: ID of the Cloud project where the trace data is stored. |
| func (r *ProjectsTracesService) List(projectId string) *ProjectsTracesListCall { |
| c := &ProjectsTracesListCall{s: r.s, urlParams_: make(gensupport.URLParams)} |
| c.projectId = projectId |
| return c |
| } |
| |
| // EndTime sets the optional parameter "endTime": End of the time interval |
| // (inclusive) during which the trace data was collected from the application. |
| func (c *ProjectsTracesListCall) EndTime(endTime string) *ProjectsTracesListCall { |
| c.urlParams_.Set("endTime", endTime) |
| return c |
| } |
| |
| // Filter sets the optional parameter "filter": A filter against properties of |
| // the trace. See filter syntax documentation |
| // (https://cloud.google.com/trace/docs/trace-filters) for details. |
| func (c *ProjectsTracesListCall) Filter(filter string) *ProjectsTracesListCall { |
| c.urlParams_.Set("filter", filter) |
| return c |
| } |
| |
| // OrderBy sets the optional parameter "orderBy": Field used to sort the |
| // returned traces. Can be one of the following: * `trace_id` * `name` (`name` |
| // field of root span in the trace) * `duration` (difference between `end_time` |
| // and `start_time` fields of the root span) * `start` (`start_time` field of |
| // the root span) Descending order can be specified by appending `desc` to the |
| // sort field (for example, `name desc`). Only one sort field is permitted. |
| func (c *ProjectsTracesListCall) OrderBy(orderBy string) *ProjectsTracesListCall { |
| c.urlParams_.Set("orderBy", orderBy) |
| return c |
| } |
| |
| // PageSize sets the optional parameter "pageSize": Maximum number of traces to |
| // return. If not specified or <= 0, the implementation selects a reasonable |
| // value. The implementation may return fewer traces than the requested page |
| // size. |
| func (c *ProjectsTracesListCall) PageSize(pageSize int64) *ProjectsTracesListCall { |
| c.urlParams_.Set("pageSize", fmt.Sprint(pageSize)) |
| return c |
| } |
| |
| // PageToken sets the optional parameter "pageToken": Token identifying the |
| // page of results to return. If provided, use the value of the |
| // `next_page_token` field from a previous request. |
| func (c *ProjectsTracesListCall) PageToken(pageToken string) *ProjectsTracesListCall { |
| c.urlParams_.Set("pageToken", pageToken) |
| return c |
| } |
| |
| // StartTime sets the optional parameter "startTime": Start of the time |
| // interval (inclusive) during which the trace data was collected from the |
| // application. |
| func (c *ProjectsTracesListCall) StartTime(startTime string) *ProjectsTracesListCall { |
| c.urlParams_.Set("startTime", startTime) |
| return c |
| } |
| |
| // View sets the optional parameter "view": Type of data returned for traces in |
| // the list. Default is `MINIMAL`. |
| // |
| // Possible values: |
| // |
| // "VIEW_TYPE_UNSPECIFIED" - Default is `MINIMAL` if unspecified. |
| // "MINIMAL" - Minimal view of the trace record that contains only the |
| // |
| // project and trace IDs. |
| // |
| // "ROOTSPAN" - Root span view of the trace record that returns the root |
| // |
| // spans along with the minimal trace data. |
| // |
| // "COMPLETE" - Complete view of the trace record that contains the actual |
| // |
| // trace data. This is equivalent to calling the REST `get` or RPC `GetTrace` |
| // method using the ID of each listed trace. |
| func (c *ProjectsTracesListCall) View(view string) *ProjectsTracesListCall { |
| c.urlParams_.Set("view", view) |
| return c |
| } |
| |
| // Fields allows partial responses to be retrieved. See |
| // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more |
| // details. |
| func (c *ProjectsTracesListCall) Fields(s ...googleapi.Field) *ProjectsTracesListCall { |
| c.urlParams_.Set("fields", googleapi.CombineFields(s)) |
| return c |
| } |
| |
| // IfNoneMatch sets an optional parameter which makes the operation fail if the |
| // object's ETag matches the given value. This is useful for getting updates |
| // only after the object has changed since the last request. |
| func (c *ProjectsTracesListCall) IfNoneMatch(entityTag string) *ProjectsTracesListCall { |
| c.ifNoneMatch_ = entityTag |
| return c |
| } |
| |
| // Context sets the context to be used in this call's Do method. |
| func (c *ProjectsTracesListCall) Context(ctx context.Context) *ProjectsTracesListCall { |
| c.ctx_ = ctx |
| return c |
| } |
| |
| // Header returns a http.Header that can be modified by the caller to add |
| // headers to the request. |
| func (c *ProjectsTracesListCall) Header() http.Header { |
| if c.header_ == nil { |
| c.header_ = make(http.Header) |
| } |
| return c.header_ |
| } |
| |
| func (c *ProjectsTracesListCall) doRequest(alt string) (*http.Response, error) { |
| reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_) |
| if c.ifNoneMatch_ != "" { |
| reqHeaders.Set("If-None-Match", c.ifNoneMatch_) |
| } |
| c.urlParams_.Set("alt", alt) |
| c.urlParams_.Set("prettyPrint", "false") |
| urls := googleapi.ResolveRelative(c.s.BasePath, "v1/projects/{projectId}/traces") |
| urls += "?" + c.urlParams_.Encode() |
| req, err := http.NewRequest("GET", urls, nil) |
| if err != nil { |
| return nil, err |
| } |
| req.Header = reqHeaders |
| googleapi.Expand(req.URL, map[string]string{ |
| "projectId": c.projectId, |
| }) |
| c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "cloudtrace.projects.traces.list", "request", internallog.HTTPRequest(req, nil)) |
| return gensupport.SendRequest(c.ctx_, c.s.client, req) |
| } |
| |
| // Do executes the "cloudtrace.projects.traces.list" call. |
| // Any non-2xx status code is an error. Response headers are in either |
| // *ListTracesResponse.ServerResponse.Header or (if a response was returned at |
| // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to |
| // check whether the returned error was because http.StatusNotModified was |
| // returned. |
| func (c *ProjectsTracesListCall) Do(opts ...googleapi.CallOption) (*ListTracesResponse, error) { |
| gensupport.SetOptions(c.urlParams_, opts...) |
| res, err := c.doRequest("json") |
| if res != nil && res.StatusCode == http.StatusNotModified { |
| if res.Body != nil { |
| res.Body.Close() |
| } |
| return nil, gensupport.WrapError(&googleapi.Error{ |
| Code: res.StatusCode, |
| Header: res.Header, |
| }) |
| } |
| if err != nil { |
| return nil, err |
| } |
| defer googleapi.CloseBody(res) |
| if err := googleapi.CheckResponse(res); err != nil { |
| return nil, gensupport.WrapError(err) |
| } |
| ret := &ListTracesResponse{ |
| ServerResponse: googleapi.ServerResponse{ |
| Header: res.Header, |
| HTTPStatusCode: res.StatusCode, |
| }, |
| } |
| target := &ret |
| b, err := gensupport.DecodeResponseBytes(target, res) |
| if err != nil { |
| return nil, err |
| } |
| c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "cloudtrace.projects.traces.list", "response", internallog.HTTPResponse(res, b)) |
| return ret, nil |
| } |
| |
| // Pages invokes f for each page of results. |
| // A non-nil error returned from f will halt the iteration. |
| // The provided context supersedes any context provided to the Context method. |
| func (c *ProjectsTracesListCall) Pages(ctx context.Context, f func(*ListTracesResponse) error) error { |
| c.ctx_ = ctx |
| defer c.PageToken(c.urlParams_.Get("pageToken")) |
| for { |
| x, err := c.Do() |
| if err != nil { |
| return err |
| } |
| if err := f(x); err != nil { |
| return err |
| } |
| if x.NextPageToken == "" { |
| return nil |
| } |
| c.PageToken(x.NextPageToken) |
| } |
| } |