public void HttpClient_Posts_To_Configured_Endpoint(string uriPath)
        {
            // Arrange
            ConcurrentDictionary <Guid, string> responses = new ConcurrentDictionary <Guid, string>();

            using var testServer = TestHttpServer.RunServer(
                      context =>
            {
                context.Response.StatusCode = 200;

                using StreamReader readStream = new StreamReader(context.Request.InputStream);

                string requestContent = readStream.ReadToEnd();

                responses.TryAdd(
                    Guid.Parse(context.Request.QueryString["requestId"]),
                    context.Request.Url.LocalPath);

                context.Response.OutputStream.Close();
            },
                      out var testServerHost,
                      out var testServerPort);

            var requestId = Guid.NewGuid();
            var options   = new JaegerExporterOptions
            {
                Endpoint            = new Uri($"http://{testServerHost}:{testServerPort}{uriPath}?requestId={requestId}"),
                Protocol            = JaegerExportProtocol.HttpBinaryThrift,
                ExportProcessorType = ExportProcessorType.Simple,
            };

            using var jaegerExporter = new JaegerExporter(options);

            // Act
            jaegerExporter.SetResourceAndInitializeBatch(Resource.Empty);
            jaegerExporter.AppendSpan(CreateTestJaegerSpan());
            jaegerExporter.SendCurrentBatch();

            // Assert
            Assert.True(responses.ContainsKey(requestId));
            Assert.Equal(uriPath, responses[requestId]);
        }
        public void JaegerTraceExporter_SpansSplitToBatches_SpansIncludedInBatches(string protocolType, int maxPayloadSizeInBytes)
        {
            TProtocolFactory protocolFactory = protocolType == "Compact"
                ? new TCompactProtocol.Factory()
                : new TBinaryProtocol.Factory();
            var client = new TestJaegerClient();

            // Arrange
            using var jaegerExporter = new JaegerExporter(
                      new JaegerExporterOptions { MaxPayloadSizeInBytes = maxPayloadSizeInBytes },
                      protocolFactory,
                      client);
            jaegerExporter.SetResourceAndInitializeBatch(Resource.Empty);

            // Create six spans, each taking more space than the previous one
            var spans = new JaegerSpan[6];

            for (int i = 0; i < 6; i++)
            {
                spans[i] = CreateTestJaegerSpan(
                    additionalAttributes: new Dictionary <string, object>
                {
                    ["foo"] = new string('_', 10 * i),
                });
            }

            var protocol        = protocolFactory.GetProtocol();
            var serializedSpans = spans.Select(s =>
            {
                s.Write(protocol);
                var data = protocol.WrittenData.ToArray();
                protocol.Clear();
                return(data);
            }).ToArray();

            // Act
            var sentBatches = new List <byte[]>();

            foreach (var span in spans)
            {
                jaegerExporter.AppendSpan(span);
                var sentBatch = client.LastWrittenData;
                if (sentBatch != null)
                {
                    sentBatches.Add(sentBatch);
                    client.LastWrittenData = null;
                }
            }

            // Assert

            // Appending the six spans will send two batches with the first four spans
            Assert.Equal(2, sentBatches.Count);
            Assert.True(
                ContainsSequence(sentBatches[0], serializedSpans[0]),
                "Expected span data not found in sent batch");
            Assert.True(
                ContainsSequence(sentBatches[0], serializedSpans[1]),
                "Expected span data not found in sent batch");

            Assert.True(
                ContainsSequence(sentBatches[1], serializedSpans[2]),
                "Expected span data not found in sent batch");
            Assert.True(
                ContainsSequence(sentBatches[1], serializedSpans[3]),
                "Expected span data not found in sent batch");

            // jaegerExporter.Batch should contain the two remaining spans
            Assert.Equal(2U, jaegerExporter.NumberOfSpansInCurrentBatch);
            jaegerExporter.SendCurrentBatch();
            Assert.True(client.LastWrittenData != null);
            var serializedBatch = client.LastWrittenData;

            Assert.True(
                ContainsSequence(serializedBatch, serializedSpans[4]),
                "Expected span data not found in unsent batch");
            Assert.True(
                ContainsSequence(serializedBatch, serializedSpans[5]),
                "Expected span data not found in unsent batch");
        }