// Copyright 2025 Envoy Project 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.

syntax = "proto3";

package envoy.config.trace.v3;

import "envoy/config/core/v3/address.proto";
import "envoy/config/core/v3/base.proto";

import "google/protobuf/struct.proto";

import "udpa/annotations/migrate.proto";
import "udpa/annotations/status.proto";
import "udpa/annotations/versioning.proto";
import "validate/validate.proto";

option java_package = "io.envoyproxy.envoy.config.trace.v3";
option java_outer_classname = "XrayProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/config/trace/v3;tracev3";
option (udpa.annotations.file_migrate).move_to_package = "envoy.extensions.tracers.xray.v4alpha";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: AWS X-Ray Tracer Configuration]
// Configuration for AWS X-Ray tracer
//
// The X-Ray tracer will automatically attach :ref:`custom_tags <envoy_v3_api_field_extensions.filters.network.http_connection_manager.v3.HttpConnectionManager.Tracing.custom_tags>` as annotations to the span. (See: `Annotations <https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-annotations>`_.)
//
// AWS X-Ray trace annotations are also created by the tracing subsystem automatically based on metadata provided during creation of a span.
//
// An example X-Ray trace span that is generated by the envoy trace subsystem is as follows:
//
// .. code-block:: json
//
//   {
//     "Id": "1-6698980d-e829ae270ab34b69b488b098",
//     "Duration": 0.016,
//     "LimitExceeded": false,
//     "Segments":
//     [
//       {
//         "Id": "15d65e5ced8dfe76",
//         "Document":
//         {
//           "id": "15d65e5ced8dfe76",
//           "name": "envoy-example",
//           "start_time": 1721276429.410355,
//           "trace_id": "1-6698980d-e829ae270ab34b69b488b098",
//           "end_time": 1721276429.426068,
//           "fault": true,
//           "http":
//           {
//             "request":
//             {
//               "url": "http://example/path",
//               "method": "GET",
//               "user_agent": "curl/8.5.0",
//               "client_ip": "127.0.0.1",
//               "x_forwarded_for": false
//             },
//             "response":
//             {
//               "status": 503,
//               "content_length": 216
//             }
//           },
//           "aws": {},
//           "annotations":
//           {
//             "response_flags": "UF",
//             "component": "proxy",
//             "upstream_cluster": "upstream_cluster",
//             "annotation_from_custom_tag": "example",
//             "http.protocol": "HTTP/1.1",
//             "request_size": "0",
//             "downstream_cluster": "-",
//             "direction": "ingress",
//             "upstream_cluster.name": "upstream_cluster"
//           }
//         }
//       }
//     ]
//   }
//

// [#extension: envoy.tracers.xray]
message XRayConfig {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.config.trace.v2alpha.XRayConfig";

  message SegmentFields {
    // The type of AWS resource, e.g. "AWS::AppMesh::Proxy".
    string origin = 1;

    // AWS resource metadata dictionary.
    // See: `X-Ray Segment Document documentation <https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html#api-segmentdocuments-aws>`__
    google.protobuf.Struct aws = 2;
  }

  // The UDP endpoint of the X-Ray Daemon where the spans will be sent.
  // If this value is not set, the default value of 127.0.0.1:2000 will be used.
  core.v3.SocketAddress daemon_endpoint = 1;

  // The name of the X-Ray segment.
  string segment_name = 2 [(validate.rules).string = {min_len: 1}];

  // The location of a local custom sampling rules JSON file.
  // For an example of the sampling rules see:
  // `X-Ray SDK documentation
  // <https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-go-configuration.html#xray-sdk-go-configuration-sampling>`_
  core.v3.DataSource sampling_rule_manifest = 3;

  // Optional custom fields to be added to each trace segment.
  // see: `X-Ray Segment Document documentation
  // <https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html>`__
  SegmentFields segment_fields = 4;
}
