public void JaegerTraceExporter_SetResource_UpdatesServiceName() { using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions()); var process = jaegerTraceExporter.Process; process.ServiceName = "TestService"; jaegerTraceExporter.SetResourceAndInitializeBatch(Resource.Empty); Assert.Equal("TestService", process.ServiceName); jaegerTraceExporter.SetResourceAndInitializeBatch(ResourceBuilder.CreateEmpty().AddService("MyService").Build()); Assert.Equal("MyService", process.ServiceName); jaegerTraceExporter.SetResourceAndInitializeBatch(ResourceBuilder.CreateEmpty().AddService("MyService", "MyNamespace").Build()); Assert.Equal("MyNamespace.MyService", process.ServiceName); }
public void JaegerTraceExporter_SetResource_IgnoreServiceResources() { using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions()); var process = jaegerTraceExporter.Process; jaegerTraceExporter.SetResourceAndInitializeBatch(ResourceBuilder.CreateEmpty().AddAttributes(new Dictionary <string, object> { [ResourceSemanticConventions.AttributeServiceName] = "servicename", [ResourceSemanticConventions.AttributeServiceNamespace] = "servicenamespace", }).Build()); Assert.Null(process.Tags); }
public void JaegerTraceExporter_BuildBatchesToTransmit_FlushedBatch() { // Arrange using var jaegerExporter = new JaegerExporter(new JaegerExporterOptions { MaxPayloadSizeInBytes = 1500 }); jaegerExporter.SetResourceAndInitializeBatch(Resource.Empty); // Act jaegerExporter.AppendSpan(CreateTestJaegerSpan()); jaegerExporter.AppendSpan(CreateTestJaegerSpan()); jaegerExporter.AppendSpan(CreateTestJaegerSpan()); // Assert Assert.Equal(1U, jaegerExporter.NumberOfSpansInCurrentBatch); }
public void JaegerTraceExporter_SetResource_CreatesTags() { using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions()); var process = jaegerTraceExporter.Process; jaegerTraceExporter.SetResourceAndInitializeBatch(ResourceBuilder.CreateEmpty().AddAttributes(new Dictionary <string, object> { ["Tag"] = "value", }).Build()); Assert.NotNull(process.Tags); Assert.Single(process.Tags); Assert.Equal("value", process.Tags["Tag"].VStr); }
public void JaegerTraceExporter_SetResource_CombinesTags() { using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions()); var process = jaegerTraceExporter.Process; process.Tags = new Dictionary<string, JaegerTag> { ["Tag1"] = new KeyValuePair<string, object>("Tag1", "value1").ToJaegerTag() }; jaegerTraceExporter.SetResourceAndInitializeBatch(ResourceBuilder.CreateEmpty().AddAttributes(new Dictionary<string, object> { ["Tag2"] = "value2", }).Build()); Assert.NotNull(process.Tags); Assert.Equal(2, process.Tags.Count); Assert.Equal("value1", process.Tags["Tag1"].VStr); Assert.Equal("value2", process.Tags["Tag2"].VStr); }
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"); }
public void JaegerTraceExporter_SpansSplitToBatches_SpansIncludedInBatches() { // Arrange var memoryTransport = new InMemoryTransport(); using var jaegerExporter = new JaegerExporter( new JaegerExporterOptions { MaxPayloadSizeInBytes = 1500 }, memoryTransport); jaegerExporter.SetResourceAndInitializeBatch(Resource.Empty); var tempTransport = new InMemoryTransport(initialCapacity: 3000); var protocol = new TCompactProtocol(tempTransport); // 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 serializedSpans = spans.Select(s => { s.Write(protocol); return tempTransport.ToArray(); }).ToArray(); // Act var sentBatches = new List<byte[]>(); foreach (var span in spans) { jaegerExporter.AppendSpan(span); var sentBatch = memoryTransport.ToArray(); if (sentBatch.Length > 0) { sentBatches.Add(sentBatch); } } // 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(2, jaegerExporter.Batch.Count); jaegerExporter.Batch.Write(protocol); var serializedBatch = tempTransport.ToArray(); 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"); }