Reputation: 49
I'm trying to setup logs with .NET and OpenTelemetry.
My goal is to send the logs to the Grafana Agent and then forward them to the collector
//Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
var otel = builder.Services.AddOpenTelemetry();
otel.ConfigureResource(resource => resource
.AddService(builder.Environment.ApplicationName));
builder.Logging.AddOpenTelemetry(options =>
{
options.IncludeScopes = true;
options.IncludeFormattedMessage = true;
options.ParseStateValues = true;
options.AddOtlpExporter(otlpOptions =>
{
otlpOptions.Endpoint = new Uri("http://localhost:4318");
});
});
var app = builder.Build();
app.MapGet("/", SendGreeting);
app.Run();
async Task<String> SendGreeting(ILogger<Program> logger)
{
logger.LogInformation("Test Log");
return "Hello World!";
}
Docker-compose.yml
services:
grafana:
image: grafana/grafana-oss:latest
ports:
- '3000:3000'
networks:
- monitoring
volumes:
- grafana-storage:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
grafana-agent:
image: grafana/agent:latest
ports:
- "12345:12345"
volumes:
- ./grafana-agent.yaml:/etc/agent.yaml
command:
- "--config.file=/etc/agent.yaml"
networks:
- monitoring
otel-collector:
image: otel/opentelemetry-collector-contrib
volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
ports:
- 1888:1888 # pprof extension
- 8888:8888 # Prometheus metrics exposed by the Collector
- 8889:8889 # Prometheus exporter metrics
- 13133:13133 # health_check extension
- 4317:4317 # OTLP gRPC receiver
- 4318:4318 # OTLP http receiver
- 55679:55679 # zpages extension
command: ["--config=/etc/otel-collector-config.yaml"]
networks:
- monitoring
volumes:
grafana-storage:
networks:
monitoring:
grafana-agent.yml
server:
log_level: info
logs:
configs:
- name: otel-logs
positions:
filename: /tmp/positions.yaml
scrape_configs:
- job_name: otel-logs
static_configs:
- targets: ['localhost']
labels:
job: otel-logs
__path__: /var/log/*.log
clients:
- url: http://otel-collector:4318
otel-collector-config.yaml
receivers:
otlp:
protocols:
http:
exporters:
logging:
loglevel: info
service:
telemetry:
logs:
level: info
pipelines:
logs:
receivers: [otlp]
exporters: [logging]
The logs reach the console (ConsoleExporter), but I don’t see them in the collector’s stdout logs
What am I doing wrong?
Upvotes: 0
Views: 100
Reputation: 49
turns out the problem was in the config for collector
proper configuration:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
processors:
batch:
exporters:
debug:
verbosity: detailed
service:
pipelines:
logs:
receivers: [otlp]
processors: [batch]
exporters: [debug]
Upvotes: 0