我试图使用一个简单的例子来设置.NET和OpenTelemetry的日志。
using Microsoft.Extensions.Logging;
using OpenTelemetry.Exporter;
using OpenTelemetry.Logs;
using OpenTelemetry.Resources;
using var loggerFactory = LoggerFactory.Create(builder =>
{
builder.ClearProviders();
builder.AddOpenTelemetry(options =>
{
options
.ConfigureResource(c => c.AddService("GettingStarted"))
.AddConsoleExporter()
.AddOtlpExporter(config =>
{
config.Endpoint = new Uri("http://localhost:4318");
config.Protocol = OtlpExportProtocol.HttpProtobuf;
});
});
});
var logger = loggerFactory.CreateLogger<Program>();
for (var i = 0; i < 100; i++)
{
logger.LogError("{count}: Hello World!", i);
await Task.Delay(1000);
}
收集器配置(otel-collector-config.yaml):
receivers:
otlp:
protocols:
http:
exporters:
logging:
loglevel: debug
service:
telemetry:
logs:
level: debug
pipelines:
logs:
receivers: [otlp]
exporters: [logging]
OpenTelemetry Collector(docker-compose.yml):
services:
opentelemetry-collector:
image: otel/opentelemetry-collector:0.67.0
ports:
- 4318:4318
volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
这些日志会传送到控制台(ConsoleExporter),但我在收集器的日志(stdout)中看不到它。
我哪里做错了?
1条答案
按热度按时间ffscu2ro1#
我的直觉是合成文件中的收集器条目缺少
command
属性:因此,您的配置实际上没有应用于收集器。