예제 #1
0
        public void GlobalSetup()
        {
            this.server = TestHttpServer.RunServer(
                (ctx) =>
            {
                using (Stream receiveStream = ctx.Request.InputStream)
                {
                    while (true)
                    {
                        if (receiveStream.Read(this.buffer, 0, this.buffer.Length) == 0)
                        {
                            break;
                        }
                    }
                }

                ctx.Response.StatusCode = 200;
                ctx.Response.OutputStream.Close();
            },
                out this.serverHost,
                out this.serverPort);

            var options = new OtlpExporterOptions
            {
                Endpoint = new Uri($"http://{this.serverHost}:{this.serverPort}"),
            };

            this.exporter = new OtlpTraceExporter(
                options,
                new OtlpHttpTraceExportClient(options, options.HttpClientFactory()));

            this.activity      = ActivityHelper.CreateTestActivity();
            this.activityBatch = new CircularBuffer <Activity>(this.NumberOfSpans);
        }
        public void NewOtlpHttpTraceExportClient_OtlpExporterOptions_ExporterHasCorrectProperties()
        {
            var header1 = new { Name = "hdr1", Value = "val1" };
            var header2 = new { Name = "hdr2", Value = "val2" };

            var options = new OtlpExporterOptions
            {
                Headers = $"{header1.Name}={header1.Value}, {header2.Name} = {header2.Value}",
            };

            var client = new OtlpHttpTraceExportClient(options, options.HttpClientFactory());

            Assert.NotNull(client.HttpClient);

            Assert.Equal(2, client.Headers.Count);
            Assert.Contains(client.Headers, kvp => kvp.Key == header1.Name && kvp.Value == header1.Value);
            Assert.Contains(client.Headers, kvp => kvp.Key == header2.Name && kvp.Value == header2.Value);
        }