# The list of traces
type TraceBrief {
  traces: [BasicTrace!]!
  total: Int!
}

# Trace basic info
type BasicTrace {
   operationName: String!
   duration: Int!
   start: String!
   isError: Boolean
   traceId: String
}

# Represent the conditions used for query TraceBrief
input TraceQueryCondition {
  # The value of 0 means all application.
  applicationId: Int
  traceId: String
  operationName: String
  # The time range of traces started
  queryDuration: Duration
  # The mix time of trace
  minTraceDuration: Int
  # The max time of trace
  maxTraceDuration: Int
  paging: Pagination!
}

enum QueryOrder {
  BY_START_TIME
  BY_DURATION
}

# The trace represents a distributed trace, includes all segments and spans.
type Trace {
  spans: [Span!]!
}

type Span {
  traceId: ID!
  segmentId: ID!
  spanId: Int!
  parentSpanId: Int!
  refs: [Ref!]!
  applicationCode: String!
  startTime: Long!
  endTime: Long!
  operationName: String
  # There are three span types: Local, Entry and Exit
  type: String!
  # Peer network id, e.g. host+port, ip+port
  peer: String
  component: String
  isError: Boolean
  # There are 5 layers: Unknown, Database, RPCFramework, Http, MQ and Cache
  layer: String
  tags: [KeyValue!]!
  logs: [LogEntity!]!
}

# Ref represents the link between the segment and its parents.
# The parent(ref) may not exists, which means batch process.
# The UI should display a list, representing the other trace IDs.
type Ref {
  traceId: ID!
  parentSegmentId: ID!
  parentSpanId: Int!
  # Ref type represents why did the ref happen.
  # Include: 1) CrossProcess 2) CrossThread
  type: RefType!
}

enum RefType {
  CROSS_PROCESS,
  CROSS_THREAD
}

type KeyValue {
  key: String!
  value: String
}

type LogEntity {
  time: Long!
  data: [KeyValue!]
}

extend type Query {
   queryBasicTraces(condition: TraceQueryCondition): TraceBrief
   queryTrace(traceId: ID!): Trace
}
