syntax = "proto3";

option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.proto";

import "Common.proto";
import "Downstream.proto";
import "KeyWithStringValue.proto";

service TraceSegmentService {
    rpc collect (stream UpstreamSegment) returns (Downstream) {
    }
}

message UpstreamSegment {
    repeated UniqueId globalTraceIds = 1;
    bytes segment = 2; // the byte array of TraceSegmentObject
}

message UniqueId {
    repeated int64 idParts = 1;
}

message TraceSegmentObject {
    UniqueId traceSegmentId = 1;
    repeated SpanObject spans = 2;
    int32 applicationId = 3;
    int32 applicationInstanceId = 4;
    bool isSizeLimited = 5;
}

message TraceSegmentReference {
    RefType refType = 1;
    UniqueId parentTraceSegmentId = 2;
    int32 parentSpanId = 3;
    int32 parentApplicationInstanceId = 4;
    string networkAddress = 5;
    int32 networkAddressId = 6;
    int32 entryApplicationInstanceId = 7;
    string entryServiceName = 8;
    int32 entryServiceId = 9;
    string parentServiceName = 10;
    int32 parentServiceId = 11;
}

message SpanObject {
    int32 spanId = 1;
    int32 parentSpanId = 2;
    int64 startTime = 3;
    int64 endTime = 4;
    repeated TraceSegmentReference refs = 5;
    int32 operationNameId = 6;
    string operationName = 7;
    int32 peerId = 8;
    string peer = 9;
    SpanType spanType = 10;
    SpanLayer spanLayer = 11;
    int32 componentId = 12;
    string component = 13;
    bool isError = 14;
    repeated KeyWithStringValue tags = 15;
    repeated LogMessage logs = 16;
}

enum RefType {
    CrossProcess = 0;
    CrossThread = 1;
}

enum SpanLayer {
    Unknown = 0;
    Database = 1;
    RPCFramework = 2;
    Http = 3;
    MQ = 4;
    Cache = 5;
}

message LogMessage {
    int64 time = 1;
    repeated KeyWithStringValue data = 2;
}
