1// Copyright 2022 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.v2;
18
19import "google/api/field_behavior.proto";
20import "google/api/resource.proto";
21import "google/protobuf/timestamp.proto";
22import "google/protobuf/wrappers.proto";
23import "google/rpc/status.proto";
24
25option csharp_namespace = "Google.Cloud.Trace.V2";
26option go_package = "cloud.google.com/go/trace/apiv2/tracepb;tracepb";
27option java_multiple_files = true;
28option java_outer_classname = "TraceProto";
29option java_package = "com.google.devtools.cloudtrace.v2";
30option php_namespace = "Google\\Cloud\\Trace\\V2";
31option ruby_package = "Google::Cloud::Trace::V2";
32
33// A span represents a single operation within a trace. Spans can be
34// nested to form a trace tree. Often, a trace contains a root span
35// that describes the end-to-end latency, and one or more subspans for
36// its sub-operations.
37//
38// A trace can also contain multiple root spans, or none at all.
39// Spans do not need to be contiguous. There might be
40// gaps or overlaps between spans in a trace.
41message Span {
42  option (google.api.resource) = {
43    type: "cloudtrace.googleapis.com/Span"
44    pattern: "projects/{project}/traces/{trace}/spans/{span}"
45  };
46
47  // A set of attributes as key-value pairs.
48  message Attributes {
49    // A set of attributes. Each attribute's key can be up to 128 bytes
50    // long. The value can be a string up to 256 bytes, a signed 64-bit integer,
51    // or the boolean values `true` or `false`. For example:
52    //
53    //     "/instance_id": { "string_value": { "value": "my-instance" } }
54    //     "/http/request_bytes": { "int_value": 300 }
55    //     "abc.com/myattribute": { "bool_value": false }
56    map<string, AttributeValue> attribute_map = 1;
57
58    // The number of attributes that were discarded. Attributes can be discarded
59    // because their keys are too long or because there are too many attributes.
60    // If this value is 0 then all attributes are valid.
61    int32 dropped_attributes_count = 2;
62  }
63
64  // A time-stamped annotation or message event in the Span.
65  message TimeEvent {
66    // Text annotation with a set of attributes.
67    message Annotation {
68      // A user-supplied message describing the event. The maximum length for
69      // the description is 256 bytes.
70      TruncatableString description = 1;
71
72      // A set of attributes on the annotation. You can have up to 4 attributes
73      // per Annotation.
74      Attributes attributes = 2;
75    }
76
77    // An event describing a message sent/received between Spans.
78    message MessageEvent {
79      // Indicates whether the message was sent or received.
80      enum Type {
81        // Unknown event type.
82        TYPE_UNSPECIFIED = 0;
83
84        // Indicates a sent message.
85        SENT = 1;
86
87        // Indicates a received message.
88        RECEIVED = 2;
89      }
90
91      // Type of MessageEvent. Indicates whether the message was sent or
92      // received.
93      Type type = 1;
94
95      // An identifier for the MessageEvent's message that can be used to match
96      // `SENT` and `RECEIVED` MessageEvents.
97      int64 id = 2;
98
99      // The number of uncompressed bytes sent or received.
100      int64 uncompressed_size_bytes = 3;
101
102      // The number of compressed bytes sent or received. If missing, the
103      // compressed size is assumed to be the same size as the uncompressed
104      // size.
105      int64 compressed_size_bytes = 4;
106    }
107
108    // The timestamp indicating the time the event occurred.
109    google.protobuf.Timestamp time = 1;
110
111    // A `TimeEvent` can contain either an `Annotation` object or a
112    // `MessageEvent` object, but not both.
113    oneof value {
114      // Text annotation with a set of attributes.
115      Annotation annotation = 2;
116
117      // An event describing a message sent/received between Spans.
118      MessageEvent message_event = 3;
119    }
120  }
121
122  // A collection of `TimeEvent`s. A `TimeEvent` is a time-stamped annotation
123  // on the span, consisting of either user-supplied key:value pairs, or
124  // details of a message sent/received between Spans.
125  message TimeEvents {
126    // A collection of `TimeEvent`s.
127    repeated TimeEvent time_event = 1;
128
129    // The number of dropped annotations in all the included time events.
130    // If the value is 0, then no annotations were dropped.
131    int32 dropped_annotations_count = 2;
132
133    // The number of dropped message events in all the included time events.
134    // If the value is 0, then no message events were dropped.
135    int32 dropped_message_events_count = 3;
136  }
137
138  // A pointer from the current span to another span in the same trace or in a
139  // different trace. For example, this can be used in batching operations,
140  // where a single batch handler processes multiple requests from different
141  // traces or when the handler receives a request from a different project.
142  message Link {
143    // The relationship of the current span relative to the linked span: child,
144    // parent, or unspecified.
145    enum Type {
146      // The relationship of the two spans is unknown.
147      TYPE_UNSPECIFIED = 0;
148
149      // The linked span is a child of the current span.
150      CHILD_LINKED_SPAN = 1;
151
152      // The linked span is a parent of the current span.
153      PARENT_LINKED_SPAN = 2;
154    }
155
156    // The `[TRACE_ID]` for a trace within a project.
157    string trace_id = 1;
158
159    // The `[SPAN_ID]` for a span within a trace.
160    string span_id = 2;
161
162    // The relationship of the current span relative to the linked span.
163    Type type = 3;
164
165    // A set of attributes on the link. Up to 32 attributes can be
166    // specified per link.
167    Attributes attributes = 4;
168  }
169
170  // A collection of links, which are references from this span to a span
171  // in the same or different trace.
172  message Links {
173    // A collection of links.
174    repeated Link link = 1;
175
176    // The number of dropped links after the maximum size was enforced. If
177    // this value is 0, then no links were dropped.
178    int32 dropped_links_count = 2;
179  }
180
181  // Type of span. Can be used to specify additional relationships between spans
182  // in addition to a parent/child relationship.
183  enum SpanKind {
184    // Unspecified. Do NOT use as default.
185    // Implementations MAY assume SpanKind.INTERNAL to be default.
186    SPAN_KIND_UNSPECIFIED = 0;
187
188    // Indicates that the span is used internally. Default value.
189    INTERNAL = 1;
190
191    // Indicates that the span covers server-side handling of an RPC or other
192    // remote network request.
193    SERVER = 2;
194
195    // Indicates that the span covers the client-side wrapper around an RPC or
196    // other remote request.
197    CLIENT = 3;
198
199    // Indicates that the span describes producer sending a message to a broker.
200    // Unlike client and  server, there is no direct critical path latency
201    // relationship between producer and consumer spans (e.g. publishing a
202    // message to a pubsub service).
203    PRODUCER = 4;
204
205    // Indicates that the span describes consumer receiving a message from a
206    // broker. Unlike client and  server, there is no direct critical path
207    // latency relationship between producer and consumer spans (e.g. receiving
208    // a message from a pubsub service subscription).
209    CONSUMER = 5;
210  }
211
212  // Required. The resource name of the span in the following format:
213  //
214  //  * `projects/[PROJECT_ID]/traces/[TRACE_ID]/spans/[SPAN_ID]`
215  //
216  // `[TRACE_ID]` is a unique identifier for a trace within a project;
217  // it is a 32-character hexadecimal encoding of a 16-byte array. It should
218  // not be zero.
219  //
220  // `[SPAN_ID]` is a unique identifier for a span within a trace; it
221  // is a 16-character hexadecimal encoding of an 8-byte array. It should not
222  // be zero.
223  // .
224  string name = 1 [(google.api.field_behavior) = REQUIRED];
225
226  // Required. The `[SPAN_ID]` portion of the span's resource name.
227  string span_id = 2 [(google.api.field_behavior) = REQUIRED];
228
229  // The `[SPAN_ID]` of this span's parent span. If this is a root span,
230  // then this field must be empty.
231  string parent_span_id = 3;
232
233  // Required. A description of the span's operation (up to 128 bytes).
234  // Cloud Trace displays the description in the
235  // Cloud console.
236  // For example, the display name can be a qualified method name or a file name
237  // and a line number where the operation is called. A best practice is to use
238  // the same display name within an application and at the same call point.
239  // This makes it easier to correlate spans in different traces.
240  TruncatableString display_name = 4 [(google.api.field_behavior) = REQUIRED];
241
242  // Required. The start time of the span. On the client side, this is the time
243  // kept by the local machine where the span execution starts. On the server
244  // side, this is the time when the server's application handler starts
245  // running.
246  google.protobuf.Timestamp start_time = 5
247      [(google.api.field_behavior) = REQUIRED];
248
249  // Required. The end time of the span. On the client side, this is the time
250  // kept by the local machine where the span execution ends. On the server
251  // side, this is the time when the server application handler stops running.
252  google.protobuf.Timestamp end_time = 6
253      [(google.api.field_behavior) = REQUIRED];
254
255  // A set of attributes on the span. You can have up to 32 attributes per
256  // span.
257  Attributes attributes = 7;
258
259  // Stack trace captured at the start of the span.
260  StackTrace stack_trace = 8;
261
262  // A set of time events. You can have up to 32 annotations and 128 message
263  // events per span.
264  TimeEvents time_events = 9;
265
266  // Links associated with the span. You can have up to 128 links per Span.
267  Links links = 10;
268
269  // Optional. The final status for this span.
270  google.rpc.Status status = 11 [(google.api.field_behavior) = OPTIONAL];
271
272  // Optional. Set this parameter to indicate whether this span is in
273  // the same process as its parent. If you do not set this parameter,
274  // Trace is unable to take advantage of this helpful information.
275  google.protobuf.BoolValue same_process_as_parent_span = 12
276      [(google.api.field_behavior) = OPTIONAL];
277
278  // Optional. The number of child spans that were generated while this span
279  // was active. If set, allows implementation to detect missing child spans.
280  google.protobuf.Int32Value child_span_count = 13
281      [(google.api.field_behavior) = OPTIONAL];
282
283  // Optional. Distinguishes between spans generated in a particular context.
284  // For example, two spans with the same name may be distinguished using
285  // `CLIENT` (caller) and `SERVER` (callee) to identify an RPC call.
286  SpanKind span_kind = 14 [(google.api.field_behavior) = OPTIONAL];
287}
288
289// The allowed types for `[VALUE]` in a `[KEY]:[VALUE]` attribute.
290message AttributeValue {
291  // The type of the value.
292  oneof value {
293    // A string up to 256 bytes long.
294    TruncatableString string_value = 1;
295
296    // A 64-bit signed integer.
297    int64 int_value = 2;
298
299    // A Boolean value represented by `true` or `false`.
300    bool bool_value = 3;
301  }
302}
303
304// A call stack appearing in a trace.
305message StackTrace {
306  // Represents a single stack frame in a stack trace.
307  message StackFrame {
308    // The fully-qualified name that uniquely identifies the function or
309    // method that is active in this frame (up to 1024 bytes).
310    TruncatableString function_name = 1;
311
312    // An un-mangled function name, if `function_name` is mangled.
313    // To get information about name mangling, run
314    // [this search](https://www.google.com/search?q=cxx+name+mangling).
315    // The name can be fully-qualified (up to 1024 bytes).
316    TruncatableString original_function_name = 2;
317
318    // The name of the source file where the function call appears (up to 256
319    // bytes).
320    TruncatableString file_name = 3;
321
322    // The line number in `file_name` where the function call appears.
323    int64 line_number = 4;
324
325    // The column number where the function call appears, if available.
326    // This is important in JavaScript because of its anonymous functions.
327    int64 column_number = 5;
328
329    // The binary module from where the code was loaded.
330    Module load_module = 6;
331
332    // The version of the deployed source code (up to 128 bytes).
333    TruncatableString source_version = 7;
334  }
335
336  // A collection of stack frames, which can be truncated.
337  message StackFrames {
338    // Stack frames in this call stack.
339    repeated StackFrame frame = 1;
340
341    // The number of stack frames that were dropped because there
342    // were too many stack frames.
343    // If this value is 0, then no stack frames were dropped.
344    int32 dropped_frames_count = 2;
345  }
346
347  // Stack frames in this stack trace. A maximum of 128 frames are allowed.
348  StackFrames stack_frames = 1;
349
350  // The hash ID is used to conserve network bandwidth for duplicate
351  // stack traces within a single trace.
352  //
353  // Often multiple spans will have identical stack traces.
354  // The first occurrence of a stack trace should contain both the
355  // `stackFrame` content and a value in `stackTraceHashId`.
356  //
357  // Subsequent spans within the same request can refer
358  // to that stack trace by only setting `stackTraceHashId`.
359  int64 stack_trace_hash_id = 2;
360}
361
362// Binary module.
363message Module {
364  // For example: main binary, kernel modules, and dynamic libraries
365  // such as libc.so, sharedlib.so (up to 256 bytes).
366  TruncatableString module = 1;
367
368  // A unique identifier for the module, usually a hash of its
369  // contents (up to 128 bytes).
370  TruncatableString build_id = 2;
371}
372
373// Represents a string that might be shortened to a specified length.
374message TruncatableString {
375  // The shortened string. For example, if the original string is 500
376  // bytes long and the limit of the string is 128 bytes, then
377  // `value` contains the first 128 bytes of the 500-byte string.
378  //
379  // Truncation always happens on a UTF8 character boundary. If there
380  // are multi-byte characters in the string, then the length of the
381  // shortened string might be less than the size limit.
382  string value = 1;
383
384  // The number of bytes removed from the original string. If this
385  // value is 0, then the string was not shortened.
386  int32 truncated_byte_count = 2;
387}
388