1// Copyright 2020 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15syntax = "proto3";
16
17package google.devtools.cloudtrace.v1;
18
19import "google/api/client.proto";
20import "google/api/field_behavior.proto";
21import "google/protobuf/empty.proto";
22import "google/protobuf/timestamp.proto";
23import "google/api/annotations.proto";
24
25option csharp_namespace = "Google.Cloud.Trace.V1";
26option go_package = "cloud.google.com/go/trace/apiv1/tracepb;tracepb";
27option java_multiple_files = true;
28option java_outer_classname = "TraceProto";
29option java_package = "com.google.devtools.cloudtrace.v1";
30option php_namespace = "Google\\Cloud\\Trace\\V1";
31option ruby_package = "Google::Cloud::Trace::V1";
32
33// This file describes an API for collecting and viewing traces and spans
34// within a trace.  A Trace is a collection of spans corresponding to a single
35// operation or set of operations for an application. A span is an individual
36// timed event which forms a node of the trace tree. Spans for a single trace
37// may span multiple services.
38service TraceService {
39  option (google.api.default_host) = "cloudtrace.googleapis.com";
40  option (google.api.oauth_scopes) =
41      "https://www.googleapis.com/auth/cloud-platform,"
42      "https://www.googleapis.com/auth/trace.append,"
43      "https://www.googleapis.com/auth/trace.readonly";
44
45  // Returns of a list of traces that match the specified filter conditions.
46  rpc ListTraces(ListTracesRequest) returns (ListTracesResponse) {
47    option (google.api.http) = {
48      get: "/v1/projects/{project_id}/traces"
49    };
50    option (google.api.method_signature) = "project_id";
51  }
52
53  // Gets a single trace by its ID.
54  rpc GetTrace(GetTraceRequest) returns (Trace) {
55    option (google.api.http) = {
56      get: "/v1/projects/{project_id}/traces/{trace_id}"
57    };
58    option (google.api.method_signature) = "project_id,trace_id";
59  }
60
61  // Sends new traces to Stackdriver Trace or updates existing traces. If the ID
62  // of a trace that you send matches that of an existing trace, any fields
63  // in the existing trace and its spans are overwritten by the provided values,
64  // and any new fields provided are merged with the existing trace data. If the
65  // ID does not match, a new trace is created.
66  rpc PatchTraces(PatchTracesRequest) returns (google.protobuf.Empty) {
67    option (google.api.http) = {
68      patch: "/v1/projects/{project_id}/traces"
69      body: "traces"
70    };
71    option (google.api.method_signature) = "project_id,traces";
72  }
73}
74
75// A trace describes how long it takes for an application to perform an
76// operation. It consists of a set of spans, each of which represent a single
77// timed event within the operation.
78message Trace {
79  // Project ID of the Cloud project where the trace data is stored.
80  string project_id = 1;
81
82  // Globally unique identifier for the trace. This identifier is a 128-bit
83  // numeric value formatted as a 32-byte hex string. For example,
84  // `382d4f4c6b7bb2f4a972559d9085001d`.
85  string trace_id = 2;
86
87  // Collection of spans in the trace.
88  repeated TraceSpan spans = 3;
89}
90
91// List of new or updated traces.
92message Traces {
93  // List of traces.
94  repeated Trace traces = 1;
95}
96
97// A span represents a single timed event within a trace. Spans can be nested
98// and form a trace tree. Often, a trace contains a root span that describes the
99// end-to-end latency of an operation and, optionally, one or more subspans for
100// its suboperations. Spans do not need to be contiguous. There may be gaps
101// between spans in a trace.
102message TraceSpan {
103  // Type of span. Can be used to specify additional relationships between spans
104  // in addition to a parent/child relationship.
105  enum SpanKind {
106    // Unspecified.
107    SPAN_KIND_UNSPECIFIED = 0;
108
109    // Indicates that the span covers server-side handling of an RPC or other
110    // remote network request.
111    RPC_SERVER = 1;
112
113    // Indicates that the span covers the client-side wrapper around an RPC or
114    // other remote request.
115    RPC_CLIENT = 2;
116  }
117
118  // Identifier for the span. Must be a 64-bit integer other than 0 and
119  // unique within a trace. For example, `2205310701640571284`.
120  fixed64 span_id = 1;
121
122  // Distinguishes between spans generated in a particular context. For example,
123  // two spans with the same name may be distinguished using `RPC_CLIENT`
124  // and `RPC_SERVER` to identify queueing latency associated with the span.
125  SpanKind kind = 2;
126
127  // Name of the span. Must be less than 128 bytes. The span name is sanitized
128  // and displayed in the Stackdriver Trace tool in the
129  // Google Cloud Platform Console.
130  // The name may be a method name or some other per-call site name.
131  // For the same executable and the same call point, a best practice is
132  // to use a consistent name, which makes it easier to correlate
133  // cross-trace spans.
134  string name = 3;
135
136  // Start time of the span in nanoseconds from the UNIX epoch.
137  google.protobuf.Timestamp start_time = 4;
138
139  // End time of the span in nanoseconds from the UNIX epoch.
140  google.protobuf.Timestamp end_time = 5;
141
142  // Optional. ID of the parent span, if any.
143  fixed64 parent_span_id = 6 [(google.api.field_behavior) = OPTIONAL];
144
145  // Collection of labels associated with the span. Label keys must be less than
146  // 128 bytes. Label values must be less than 16 kilobytes (10MB for
147  // `/stacktrace` values).
148  //
149  // Some predefined label keys exist, or you may create your own. When creating
150  // your own, we recommend the following formats:
151  //
152  // * `/category/product/key` for agents of well-known products (e.g.
153  //   `/db/mongodb/read_size`).
154  // * `short_host/path/key` for domain-specific keys (e.g.
155  //   `foo.com/myproduct/bar`)
156  //
157  // Predefined labels include:
158  //
159  // *   `/agent`
160  // *   `/component`
161  // *   `/error/message`
162  // *   `/error/name`
163  // *   `/http/client_city`
164  // *   `/http/client_country`
165  // *   `/http/client_protocol`
166  // *   `/http/client_region`
167  // *   `/http/host`
168  // *   `/http/method`
169  // *   `/http/path`
170  // *   `/http/redirected_url`
171  // *   `/http/request/size`
172  // *   `/http/response/size`
173  // *   `/http/route`
174  // *   `/http/status_code`
175  // *   `/http/url`
176  // *   `/http/user_agent`
177  // *   `/pid`
178  // *   `/stacktrace`
179  // *   `/tid`
180  map<string, string> labels = 7;
181}
182
183// The request message for the `ListTraces` method. All fields are required
184// unless specified.
185message ListTracesRequest {
186  // Type of data returned for traces in the list.
187  enum ViewType {
188    // Default is `MINIMAL` if unspecified.
189    VIEW_TYPE_UNSPECIFIED = 0;
190
191    // Minimal view of the trace record that contains only the project
192    // and trace IDs.
193    MINIMAL = 1;
194
195    // Root span view of the trace record that returns the root spans along
196    // with the minimal trace data.
197    ROOTSPAN = 2;
198
199    // Complete view of the trace record that contains the actual trace data.
200    // This is equivalent to calling the REST `get` or RPC `GetTrace` method
201    // using the ID of each listed trace.
202    COMPLETE = 3;
203  }
204
205  // Required. ID of the Cloud project where the trace data is stored.
206  string project_id = 1 [(google.api.field_behavior) = REQUIRED];
207
208  // Optional. Type of data returned for traces in the list. Default is
209  // `MINIMAL`.
210  ViewType view = 2 [(google.api.field_behavior) = OPTIONAL];
211
212  // Optional. Maximum number of traces to return. If not specified or <= 0, the
213  // implementation selects a reasonable value.  The implementation may
214  // return fewer traces than the requested page size.
215  int32 page_size = 3 [(google.api.field_behavior) = OPTIONAL];
216
217  // Token identifying the page of results to return. If provided, use the
218  // value of the `next_page_token` field from a previous request.
219  string page_token = 4;
220
221  // Start of the time interval (inclusive) during which the trace data was
222  // collected from the application.
223  google.protobuf.Timestamp start_time = 5;
224
225  // End of the time interval (inclusive) during which the trace data was
226  // collected from the application.
227  google.protobuf.Timestamp end_time = 6;
228
229  // Optional. A filter against labels for the request.
230  //
231  // By default, searches use prefix matching. To specify exact match, prepend
232  // a plus symbol (`+`) to the search term.
233  // Multiple terms are ANDed. Syntax:
234  //
235  // *   `root:NAME_PREFIX` or `NAME_PREFIX`: Return traces where any root
236  //     span starts with `NAME_PREFIX`.
237  // *   `+root:NAME` or `+NAME`: Return traces where any root span's name is
238  //     exactly `NAME`.
239  // *   `span:NAME_PREFIX`: Return traces where any span starts with
240  //     `NAME_PREFIX`.
241  // *   `+span:NAME`: Return traces where any span's name is exactly
242  //     `NAME`.
243  // *   `latency:DURATION`: Return traces whose overall latency is
244  //     greater or equal to than `DURATION`. Accepted units are nanoseconds
245  //     (`ns`), milliseconds (`ms`), and seconds (`s`). Default is `ms`. For
246  //     example, `latency:24ms` returns traces whose overall latency
247  //     is greater than or equal to 24 milliseconds.
248  // *   `label:LABEL_KEY`: Return all traces containing the specified
249  //     label key (exact match, case-sensitive) regardless of the key:value
250  //     pair's value (including empty values).
251  // *   `LABEL_KEY:VALUE_PREFIX`: Return all traces containing the specified
252  //     label key (exact match, case-sensitive) whose value starts with
253  //     `VALUE_PREFIX`. Both a key and a value must be specified.
254  // *   `+LABEL_KEY:VALUE`: Return all traces containing a key:value pair
255  //     exactly matching the specified text. Both a key and a value must be
256  //     specified.
257  // *   `method:VALUE`: Equivalent to `/http/method:VALUE`.
258  // *   `url:VALUE`: Equivalent to `/http/url:VALUE`.
259  string filter = 7 [(google.api.field_behavior) = OPTIONAL];
260
261  // Optional. Field used to sort the returned traces.
262  // Can be one of the following:
263  //
264  // *   `trace_id`
265  // *   `name` (`name` field of root span in the trace)
266  // *   `duration` (difference between `end_time` and `start_time` fields of
267  //      the root span)
268  // *   `start` (`start_time` field of the root span)
269  //
270  // Descending order can be specified by appending `desc` to the sort field
271  // (for example, `name desc`).
272  //
273  // Only one sort field is permitted.
274  string order_by = 8 [(google.api.field_behavior) = OPTIONAL];
275}
276
277// The response message for the `ListTraces` method.
278message ListTracesResponse {
279  // List of trace records as specified by the view parameter.
280  repeated Trace traces = 1;
281
282  // If defined, indicates that there are more traces that match the request
283  // and that this value should be passed to the next request to continue
284  // retrieving additional traces.
285  string next_page_token = 2;
286}
287
288// The request message for the `GetTrace` method.
289message GetTraceRequest {
290  // Required. ID of the Cloud project where the trace data is stored.
291  string project_id = 1 [(google.api.field_behavior) = REQUIRED];
292
293  // Required. ID of the trace to return.
294  string trace_id = 2 [(google.api.field_behavior) = REQUIRED];
295}
296
297// The request message for the `PatchTraces` method.
298message PatchTracesRequest {
299  // Required. ID of the Cloud project where the trace data is stored.
300  string project_id = 1 [(google.api.field_behavior) = REQUIRED];
301
302  // Required. The body of the message.
303  Traces traces = 2 [(google.api.field_behavior) = REQUIRED];
304}
305