trace.proto 15 KB

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