我有一个测试,我试图收集活动/跨度在内存中使用内存导出器。但测试失败,异常显示集合为空。
我尝试在Assert之前添加延迟,但结果仍然相同。设置中是否还需要其他内容,以便开始捕获活动?
[Fact]
public void Can_collect_Activities_in_memory()
{
var serviceName = "ServiceName";
var activities = new List<Activity>();
var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource(serviceName)
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("in-memory"))
.AddInMemoryExporter(activities)
.Build();
var source = new ActivitySource(serviceName);
var activity = source.StartActivity("TestActivity");
Assert.Single(activities);
}
字符串
1条答案
按热度按时间eulz3vhy1#
我想通了,我需要先停止活动。