internal NewRelicTraceExporter(NRSpans.SpanDataSender spanDataSender, TelemetryConfiguration config, ILoggerFactory loggerFactory) { _spanDataSender = spanDataSender; spanDataSender.AddVersionInfo(_productName, _productVersion); _config = config; _nrEndpoints = config.NewRelicEndpoints.Select(x => x.ToLower()).ToArray(); if (loggerFactory != null) { _logger = loggerFactory.CreateLogger("NewRelicTraceExporter"); } }
public void Setup() { var config = new TelemetryConfiguration().WithAPIKey("123456").WithServiceName(testServiceName); var mockDataSender = new NRSpans.SpanDataSender(config); //Capture the spans that were requested to be sent to New Relic. mockDataSender.WithCaptureSendDataAsyncDelegate((sb, retryId) => { _resultNRSpans.AddRange(sb.Spans); }); //Prevent actually sending those spans to New Relic. mockDataSender.WithHttpHandlerImpl((json) => { return(Task.FromResult(new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.OK))); }); var exporter = new NewRelicTraceExporter(mockDataSender, config, null); using (var tracerFactory = TracerFactory.Create( builder => builder.AddProcessorPipeline( c => c.SetExporter(exporter)))) { var tracer = tracerFactory.GetTracer("TestTracer"); // Creating the following spans Trace Expected Outcome // ----------------------------------------------------------------------------------- // 0 Test Span 1 Trace 1 Included // 1 Test Span 2 Trace 1 Included // 2 Test Span 3 Trace 2 Included // 3 Test Span 4 Trace 3 Included // 4 Shoul be Filtered - HTTP Call to NR Trace 3 Excluded // 5 Should be filtered - Child of HTTP Trace 3 Excluded _otSpans.Add(tracer.StartRootSpan("Test Span 1")); _otSpans.Add(tracer.StartSpan("Test Span 2", _otSpans[0])); _otSpans.Add(tracer.StartRootSpan("Test Span 3")); _otSpans.Add(tracer.StartRootSpan("Test Span 4")); _otSpans.Add(tracer.StartSpan("Should Be Filtered - HTTP Call to NR", _otSpans[3]).PutHttpRawUrlAttribute(config.TraceUrl)); _otSpans.Add(tracer.StartSpan("Should Be Filtered - Child of HTTP", _otSpans[4])); _otSpans[0].Status = Status.Ok; _otSpans[1].Status = Status.Aborted; _otSpans[2].Status = Status.Ok; _otSpans[3].Status = Status.Ok; _otSpans[4].Status = Status.Ok; _otSpans[5].Status = Status.Ok; Thread.Sleep(100); _otSpans[1].End(); Thread.Sleep(125); _otSpans[0].End(); Thread.Sleep(150); _otSpans[2].End(); Thread.Sleep(175); _otSpans[5].End(); Thread.Sleep(100); _otSpans[4].End(); Thread.Sleep(50); _otSpans[3].End(); } }