// // Copyright 2018, 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. // namespace OpenTelemetry.Exporter.Jaeger.Implimentation { using System; using System.Collections.Generic; using System.Text; using System.Threading; using System.Threading.Tasks; #if NET46 using Thrift.Protocol; #else using Thrift.Protocols; using Thrift.Protocols.Entities; using Thrift.Protocols.Utilities; #endif public class Batch : TAbstractBase { public Batch() { } public Batch(Process process, List spans) : this() { this.Process = process; this.Spans = spans; } public Process Process { get; set; } public List Spans { get; set; } #if NET46 public void Write(TProtocol oprot) { oprot.IncrementRecursionDepth(); try { var struc = new TStruct("Batch"); oprot.WriteStructBegin(struc); var field = new TField { Name = "process", Type = TType.Struct, ID = 1, }; oprot.WriteFieldBegin(field); this.Process.Write(oprot); oprot.WriteFieldEnd(); field.Name = "spans"; field.Type = TType.List; field.ID = 2; oprot.WriteFieldBegin(field); { oprot.WriteListBegin(new TList(TType.Struct, this.Spans.Count)); foreach (var s in this.Spans) { s.Write(oprot); } oprot.WriteListEnd(); } oprot.WriteFieldEnd(); oprot.WriteFieldStop(); oprot.WriteStructEnd(); } finally { oprot.DecrementRecursionDepth(); } } #else public async Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken) { oprot.IncrementRecursionDepth(); try { var struc = new TStruct("Batch"); await oprot.WriteStructBeginAsync(struc, cancellationToken); var field = new TField { Name = "process", Type = TType.Struct, ID = 1, }; await oprot.WriteFieldBeginAsync(field, cancellationToken); await this.Process.WriteAsync(oprot, cancellationToken); await oprot.WriteFieldEndAsync(cancellationToken); field.Name = "spans"; field.Type = TType.List; field.ID = 2; await oprot.WriteFieldBeginAsync(field, cancellationToken); { await oprot.WriteListBeginAsync(new TList(TType.Struct, this.Spans.Count), cancellationToken); foreach (JaegerSpan s in this.Spans) { await s.WriteAsync(oprot, cancellationToken); } await oprot.WriteListEndAsync(cancellationToken); } await oprot.WriteFieldEndAsync(cancellationToken); await oprot.WriteFieldStopAsync(cancellationToken); await oprot.WriteStructEndAsync(cancellationToken); } finally { oprot.DecrementRecursionDepth(); } } #endif public override string ToString() { var sb = new StringBuilder("Batch("); sb.Append(", Process: "); sb.Append(this.Process == null ? "" : this.Process.ToString()); sb.Append(", Spans: "); sb.Append(this.Spans); sb.Append(")"); return sb.ToString(); } } }