trace.proto 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. // Copyright 2019, OpenTelemetry Authors
  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. syntax = "proto3";
  15. package opentelemetry.proto.trace.v1;
  16. import "opentelemetry/proto/common/v1/common.proto";
  17. import "opentelemetry/proto/resource/v1/resource.proto";
  18. option csharp_namespace = "OpenTelemetry.Proto.Trace.V1";
  19. option java_multiple_files = true;
  20. option java_package = "io.opentelemetry.proto.trace.v1";
  21. option java_outer_classname = "TraceProto";
  22. option go_package = "go.opentelemetry.io/proto/otlp/trace/v1";
  23. // TracesData represents the traces data that can be stored in a persistent storage,
  24. // OR can be embedded by other protocols that transfer OTLP traces data but do
  25. // not implement the OTLP protocol.
  26. //
  27. // The main difference between this message and collector protocol is that
  28. // in this message there will not be any "control" or "metadata" specific to
  29. // OTLP protocol.
  30. //
  31. // When new fields are added into this message, the OTLP request MUST be updated
  32. // as well.
  33. message TracesData {
  34. // An array of ResourceSpans.
  35. // For data coming from a single resource this array will typically contain
  36. // one element. Intermediary nodes that receive data from multiple origins
  37. // typically batch the data before forwarding further and in that case this
  38. // array will contain multiple elements.
  39. repeated ResourceSpans resource_spans = 1;
  40. }
  41. // A collection of ScopeSpans from a Resource.
  42. message ResourceSpans {
  43. reserved 1000;
  44. // The resource for the spans in this message.
  45. // If this field is not set then no resource info is known.
  46. opentelemetry.proto.resource.v1.Resource resource = 1;
  47. // A list of ScopeSpans that originate from a resource.
  48. repeated ScopeSpans scope_spans = 2;
  49. // The Schema URL, if known. This is the identifier of the Schema that the resource data
  50. // is recorded in. Notably, the last part of the URL path is the version number of the
  51. // schema: http[s]://server[:port]/path/<version>. To learn more about Schema URL see
  52. // https://opentelemetry.io/docs/specs/otel/schemas/#schema-url
  53. // This schema_url applies to the data in the "resource" field. It does not apply
  54. // to the data in the "scope_spans" field which have their own schema_url field.
  55. string schema_url = 3;
  56. }
  57. // A collection of Spans produced by an InstrumentationScope.
  58. message ScopeSpans {
  59. // The instrumentation scope information for the spans in this message.
  60. // Semantically when InstrumentationScope isn't set, it is equivalent with
  61. // an empty instrumentation scope name (unknown).
  62. opentelemetry.proto.common.v1.InstrumentationScope scope = 1;
  63. // A list of Spans that originate from an instrumentation scope.
  64. repeated Span spans = 2;
  65. // The Schema URL, if known. This is the identifier of the Schema that the span data
  66. // is recorded in. Notably, the last part of the URL path is the version number of the
  67. // schema: http[s]://server[:port]/path/<version>. To learn more about Schema URL see
  68. // https://opentelemetry.io/docs/specs/otel/schemas/#schema-url
  69. // This schema_url applies to all spans and span events in the "spans" field.
  70. string schema_url = 3;
  71. }
  72. // A Span represents a single operation performed by a single component of the system.
  73. //
  74. // The next available field id is 17.
  75. message Span {
  76. // A unique identifier for a trace. All spans from the same trace share
  77. // the same `trace_id`. The ID is a 16-byte array. An ID with all zeroes OR
  78. // of length other than 16 bytes is considered invalid (empty string in OTLP/JSON
  79. // is zero-length and thus is also invalid).
  80. //
  81. // This field is required.
  82. bytes trace_id = 1;
  83. // A unique identifier for a span within a trace, assigned when the span
  84. // is created. The ID is an 8-byte array. An ID with all zeroes OR of length
  85. // other than 8 bytes is considered invalid (empty string in OTLP/JSON
  86. // is zero-length and thus is also invalid).
  87. //
  88. // This field is required.
  89. bytes span_id = 2;
  90. // trace_state conveys information about request position in multiple distributed tracing graphs.
  91. // It is a trace_state in w3c-trace-context format: https://www.w3.org/TR/trace-context/#tracestate-header
  92. // See also https://github.com/w3c/distributed-tracing for more details about this field.
  93. string trace_state = 3;
  94. // The `span_id` of this span's parent span. If this is a root span, then this
  95. // field must be empty. The ID is an 8-byte array.
  96. bytes parent_span_id = 4;
  97. // Flags, a bit field.
  98. //
  99. // Bits 0-7 (8 least significant bits) are the trace flags as defined in W3C Trace
  100. // Context specification. To read the 8-bit W3C trace flag, use
  101. // `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`.
  102. //
  103. // See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions.
  104. //
  105. // Bits 8 and 9 represent the 3 states of whether a span's parent
  106. // is remote. The states are (unknown, is not remote, is remote).
  107. // To read whether the value is known, use `(flags & SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK) != 0`.
  108. // To read whether the span is remote, use `(flags & SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0`.
  109. //
  110. // When creating span messages, if the message is logically forwarded from another source
  111. // with an equivalent flags fields (i.e., usually another OTLP span message), the field SHOULD
  112. // be copied as-is. If creating from a source that does not have an equivalent flags field
  113. // (such as a runtime representation of an OpenTelemetry span), the high 22 bits MUST
  114. // be set to zero.
  115. // Readers MUST NOT assume that bits 10-31 (22 most significant bits) will be zero.
  116. //
  117. // [Optional].
  118. fixed32 flags = 16;
  119. // A description of the span's operation.
  120. //
  121. // For example, the name can be a qualified method name or a file name
  122. // and a line number where the operation is called. A best practice is to use
  123. // the same display name at the same call point in an application.
  124. // This makes it easier to correlate spans in different traces.
  125. //
  126. // This field is semantically required to be set to non-empty string.
  127. // Empty value is equivalent to an unknown span name.
  128. //
  129. // This field is required.
  130. string name = 5;
  131. // SpanKind is the type of span. Can be used to specify additional relationships between spans
  132. // in addition to a parent/child relationship.
  133. enum SpanKind {
  134. // Unspecified. Do NOT use as default.
  135. // Implementations MAY assume SpanKind to be INTERNAL when receiving UNSPECIFIED.
  136. SPAN_KIND_UNSPECIFIED = 0;
  137. // Indicates that the span represents an internal operation within an application,
  138. // as opposed to an operation happening at the boundaries. Default value.
  139. SPAN_KIND_INTERNAL = 1;
  140. // Indicates that the span covers server-side handling of an RPC or other
  141. // remote network request.
  142. SPAN_KIND_SERVER = 2;
  143. // Indicates that the span describes a request to some remote service.
  144. SPAN_KIND_CLIENT = 3;
  145. // Indicates that the span describes a producer sending a message to a broker.
  146. // Unlike CLIENT and SERVER, there is often no direct critical path latency relationship
  147. // between producer and consumer spans. A PRODUCER span ends when the message was accepted
  148. // by the broker while the logical processing of the message might span a much longer time.
  149. SPAN_KIND_PRODUCER = 4;
  150. // Indicates that the span describes consumer receiving a message from a broker.
  151. // Like the PRODUCER kind, there is often no direct critical path latency relationship
  152. // between producer and consumer spans.
  153. SPAN_KIND_CONSUMER = 5;
  154. }
  155. // Distinguishes between spans generated in a particular context. For example,
  156. // two spans with the same name may be distinguished using `CLIENT` (caller)
  157. // and `SERVER` (callee) to identify queueing latency associated with the span.
  158. SpanKind kind = 6;
  159. // start_time_unix_nano is the start time of the span. On the client side, this is the time
  160. // kept by the local machine where the span execution starts. On the server side, this
  161. // is the time when the server's application handler starts running.
  162. // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970.
  163. //
  164. // This field is semantically required and it is expected that end_time >= start_time.
  165. fixed64 start_time_unix_nano = 7;
  166. // end_time_unix_nano is the end time of the span. On the client side, this is the time
  167. // kept by the local machine where the span execution ends. On the server side, this
  168. // is the time when the server application handler stops running.
  169. // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970.
  170. //
  171. // This field is semantically required and it is expected that end_time >= start_time.
  172. fixed64 end_time_unix_nano = 8;
  173. // attributes is a collection of key/value pairs. Note, global attributes
  174. // like server name can be set using the resource API. Examples of attributes:
  175. //
  176. // "/http/user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
  177. // "/http/server_latency": 300
  178. // "example.com/myattribute": true
  179. // "example.com/score": 10.239
  180. //
  181. // The OpenTelemetry API specification further restricts the allowed value types:
  182. // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/README.md#attribute
  183. // Attribute keys MUST be unique (it is not allowed to have more than one
  184. // attribute with the same key).
  185. repeated opentelemetry.proto.common.v1.KeyValue attributes = 9;
  186. // dropped_attributes_count is the number of attributes that were discarded. Attributes
  187. // can be discarded because their keys are too long or because there are too many
  188. // attributes. If this value is 0, then no attributes were dropped.
  189. uint32 dropped_attributes_count = 10;
  190. // Event is a time-stamped annotation of the span, consisting of user-supplied
  191. // text description and key-value pairs.
  192. message Event {
  193. // time_unix_nano is the time the event occurred.
  194. fixed64 time_unix_nano = 1;
  195. // name of the event.
  196. // This field is semantically required to be set to non-empty string.
  197. string name = 2;
  198. // attributes is a collection of attribute key/value pairs on the event.
  199. // Attribute keys MUST be unique (it is not allowed to have more than one
  200. // attribute with the same key).
  201. repeated opentelemetry.proto.common.v1.KeyValue attributes = 3;
  202. // dropped_attributes_count is the number of dropped attributes. If the value is 0,
  203. // then no attributes were dropped.
  204. uint32 dropped_attributes_count = 4;
  205. }
  206. // events is a collection of Event items.
  207. repeated Event events = 11;
  208. // dropped_events_count is the number of dropped events. If the value is 0, then no
  209. // events were dropped.
  210. uint32 dropped_events_count = 12;
  211. // A pointer from the current span to another span in the same trace or in a
  212. // different trace. For example, this can be used in batching operations,
  213. // where a single batch handler processes multiple requests from different
  214. // traces or when the handler receives a request from a different project.
  215. message Link {
  216. // A unique identifier of a trace that this linked span is part of. The ID is a
  217. // 16-byte array.
  218. bytes trace_id = 1;
  219. // A unique identifier for the linked span. The ID is an 8-byte array.
  220. bytes span_id = 2;
  221. // The trace_state associated with the link.
  222. string trace_state = 3;
  223. // attributes is a collection of attribute key/value pairs on the link.
  224. // Attribute keys MUST be unique (it is not allowed to have more than one
  225. // attribute with the same key).
  226. repeated opentelemetry.proto.common.v1.KeyValue attributes = 4;
  227. // dropped_attributes_count is the number of dropped attributes. If the value is 0,
  228. // then no attributes were dropped.
  229. uint32 dropped_attributes_count = 5;
  230. // Flags, a bit field.
  231. //
  232. // Bits 0-7 (8 least significant bits) are the trace flags as defined in W3C Trace
  233. // Context specification. To read the 8-bit W3C trace flag, use
  234. // `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`.
  235. //
  236. // See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions.
  237. //
  238. // Bits 8 and 9 represent the 3 states of whether the link is remote.
  239. // The states are (unknown, is not remote, is remote).
  240. // To read whether the value is known, use `(flags & SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK) != 0`.
  241. // To read whether the link is remote, use `(flags & SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0`.
  242. //
  243. // Readers MUST NOT assume that bits 10-31 (22 most significant bits) will be zero.
  244. // When creating new spans, bits 10-31 (most-significant 22-bits) MUST be zero.
  245. //
  246. // [Optional].
  247. fixed32 flags = 6;
  248. }
  249. // links is a collection of Links, which are references from this span to a span
  250. // in the same or different trace.
  251. repeated Link links = 13;
  252. // dropped_links_count is the number of dropped links after the maximum size was
  253. // enforced. If this value is 0, then no links were dropped.
  254. uint32 dropped_links_count = 14;
  255. // An optional final status for this span. Semantically when Status isn't set, it means
  256. // span's status code is unset, i.e. assume STATUS_CODE_UNSET (code = 0).
  257. Status status = 15;
  258. }
  259. // The Status type defines a logical error model that is suitable for different
  260. // programming environments, including REST APIs and RPC APIs.
  261. message Status {
  262. reserved 1;
  263. // A developer-facing human readable error message.
  264. string message = 2;
  265. // For the semantics of status codes see
  266. // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#set-status
  267. enum StatusCode {
  268. // The default status.
  269. STATUS_CODE_UNSET = 0;
  270. // The Span has been validated by an Application developer or Operator to
  271. // have completed successfully.
  272. STATUS_CODE_OK = 1;
  273. // The Span contains an error.
  274. STATUS_CODE_ERROR = 2;
  275. };
  276. // The status code.
  277. StatusCode code = 3;
  278. }
  279. // SpanFlags represents constants used to interpret the
  280. // Span.flags field, which is protobuf 'fixed32' type and is to
  281. // be used as bit-fields. Each non-zero value defined in this enum is
  282. // a bit-mask. To extract the bit-field, for example, use an
  283. // expression like:
  284. //
  285. // (span.flags & SPAN_FLAGS_TRACE_FLAGS_MASK)
  286. //
  287. // See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions.
  288. //
  289. // Note that Span flags were introduced in version 1.1 of the
  290. // OpenTelemetry protocol. Older Span producers do not set this
  291. // field, consequently consumers should not rely on the absence of a
  292. // particular flag bit to indicate the presence of a particular feature.
  293. enum SpanFlags {
  294. // The zero value for the enum. Should not be used for comparisons.
  295. // Instead use bitwise "and" with the appropriate mask as shown above.
  296. SPAN_FLAGS_DO_NOT_USE = 0;
  297. // Bits 0-7 are used for trace flags.
  298. SPAN_FLAGS_TRACE_FLAGS_MASK = 0x000000FF;
  299. // Bits 8 and 9 are used to indicate that the parent span or link span is remote.
  300. // Bit 8 (`HAS_IS_REMOTE`) indicates whether the value is known.
  301. // Bit 9 (`IS_REMOTE`) indicates whether the span or link is remote.
  302. SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK = 0x00000100;
  303. SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK = 0x00000200;
  304. // Bits 10-31 are reserved for future use.
  305. }