// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// This proto is part of experiment Logs ProtoBuf definition. This file should be removed
// once the logs are added to OTLP.
// The ProtoBuf implements OpenTelemetry Log Data Model:
// https://github.com/open-telemetry/oteps/blob/master/text/0097-log-data-model.md

syntax = "proto3";

package logsproto;

import "opentelemetry/proto/common/v1/common.proto";
import "opentelemetry/proto/resource/v1/resource.proto";

option go_package = "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/logs/v1";

// Service that can be used to push logs between one Application instrumented with
// OpenTelemetry and an collector, or between an collector and a central collector (in this
// case logs are sent/received to/from multiple Applications).
service LogService {
    // For performance reasons, it is recommended to keep this RPC
    // alive for the entire life of the application.
    rpc Export(ExportLogServiceRequest) returns (ExportLogServiceResponse) {}
}

message ExportLogServiceRequest {
    // An array of ResourceLogs.
    // For data coming from a single resource this array will typically contain one
    // element. Intermediary nodes (such as OpenTelemetry Collector) that receive
    // data from multiple origins typically batch the data before forwarding further and
    // in that case this array will contain multiple elements.
    repeated ResourceLogs resource_logs = 1;
}

message ExportLogServiceResponse {
}

// A collection of logs from a Resource.
message ResourceLogs {
    // The resource for the logs in this message.
    // If this field is not set then no resource info is known.
    opentelemetry.proto.resource.v1.Resource resource = 1;

    repeated LogRecord logs = 2;
}

enum SeverityNumber {
    UNDEFINED_SEVERITY_NUMBER = 0;
    TRACE  = 1;
    TRACE2 = 2;
    TRACE3 = 3;
    TRACE4 = 4;
    DEBUG  = 5;
    DEBUG2 = 6;
    DEBUG3 = 7;
    DEBUG4 = 8;
    INFO   = 9;
    INFO2  = 10;
    INFO3  = 11;
    INFO4  = 12;
    WARN   = 13;
    WARN2  = 14;
    WARN3  = 15;
    WARN4  = 16;
    ERROR  = 17;
    ERROR2 = 18;
    ERROR3 = 19;
    ERROR4 = 20;
    FATAL  = 21;
    FATAL2 = 22;
    FATAL3 = 23;
    FATAL4 = 24;
}

enum LogRecordFlags {
    UNDEFINED_LOG_RECORD_FLAG = 0;
    TRACE_FLAGS_MASK = 0x000000FF;
}

message LogRecord {
    // timestamp_unix_nano is the time when the event occurred.
    // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970.
    // Value of 0 indicates unknown or missing timestamp.
    fixed64 timestamp_unix_nano = 1;

    // A unique identifier for a trace. All logs from the same trace share
    // the same `trace_id`. The ID is a 16-byte array. An ID with all zeroes
    // is considered invalid. Can be set for logs that are part of request processing
    // and have an assigned trace id. Optional.
    bytes trace_id = 2;

    // A unique identifier for a span within a trace, assigned when the span
    // is created. The ID is an 8-byte array. An ID with all zeroes is considered
    // invalid. Can be set for logs that are part of a particular processing span.
    // If span_id is present trace_id SHOULD be also present. Optional.
    bytes span_id = 3;

    // Optional flags, a bit field. 8 least significant bits are the trace flags as
    // defined in W3C Trace Context specification. 24 most significant bits are reserved
    // and must be set to 0. Readers that must not assume that 24 most significant bits
    // will be zero and must correctly mask the bits when reading 8-bit trace flag (use
    // flags & TRACE_FLAGS_MASK). Optional.
    uint32 flags = 4;

    // Numerical value of the severity, normalized to values described in
    // https://github.com/open-telemetry/oteps/pull/97. Optional.
    SeverityNumber severity_number = 5;

    // The severity text (also known as log level). The original string representation as
    // it is known at the source. Optional.
    string severity_text = 6;

    // Short event identifier that does not contain varying parts. ShortName describes
    // what happened (e.g. "ProcessStarted"). Recommended to be no longer than 50
    // characters. Not guaranteed to be unique in any way. Optional.
    string short_name = 7;

    // A value containing the body of the log record. Can be for example a human-readable
    // string message (including multi-line) describing the event in a free form or it can
    // be a structured data composed of arrays and maps of other values. Optional.
    // TODO: According to Log Data Model this must be of 'any' type, but we are not yet
    // capable of representing it in memory so we are using string temporarily.
    string body = 8;

    // Additional attributes that describe the specific event occurrence. Optional.
    repeated opentelemetry.proto.common.v1.AttributeKeyValue attributes = 9;
    uint32 dropped_attributes_count = 10;
}
