You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地Docker Compose环境下Otel-Collector日志无法发送至Grafana Loki

使用Otel-Collector将日志发送至Grafana Loki

我在本地Docker Compose环境中部署了Grafana Loki,但无法将应用日志显示在Grafana中。以下是我的配置信息:

  • 应用埋点配置
logging.AddOpenTelemetry(options =>
            {
                options.IncludeFormattedMessage = true;
                options.IncludeScopes = true;
                options.ParseStateValues = true;
                //options.AddConsoleExporter();
                options.AddOtlpExporter(opts =>
                            opts.Endpoint =
                                new Uri("http://localhost:4317"));
            });
  • Docker Compose配置
version: '3.4'
networks:
  ragnarok:
services:
  otel-collector:
    container_name: olala-telemetry-otel-collector
    image: otel/opentelemetry-collector-contrib:0.80.0
    command: [ "--config=/etc/myotel.yaml" ]
    volumes:
      - ./otel-files/myotel.yaml:/etc/myotel.yaml
    ports:
      - "4317" # OTLP gRPC receiver
    networks:
      - ragnarok

  loki:
    container_name:  olala-telemetry-loki
    image: grafana/loki:main-125e168
    command: [ "-config.file=/etc/loki/local-config.yaml" ]
    volumes:
      - ./otel-files/loki.yml:/etc/loki/local-config.yaml
    ports:
      - "3100"
    networks:
      - ragnarok
  grafana:
    container_name: olala-telemetry-grafana
    image: grafana/grafana:10.0.1-ubuntu
    environment:
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
      - GF_AUTH_DISABLE_LOGIN_FORM=true
    volumes:
      - ./otel-files/grafana/grafana.ini:/etc/grafana/grafana.ini
      - ./otel-files/grafana/provisioning/datasources:/etc/grafana/provisioning/datasources
    ports:
      - 3001:3000
    networks:
      - ragnarok
  • Loki与Otel-Collector配置
    Loki配置文件采用了开源示例内容,同时我已在myotel.yaml中配置Loki exporter:
receivers:
  otlp:
    protocols:
      grpc:

exporters:
  loki:
    endpoint: http://loki:3100/loki/api/v1/push
    tls:
      insecure: true
  
processors:
  batch:
  attributes/loki:
    actions:
      - action: insert
        key: loki.attribute.labels
        value: RequestPath, dotnet.ilogger.category
service:
  telemetry:
    logs:
      level: "debug"
  pipelines:
    logs:
      receivers: [otlp]
      processors: [batch, attributes/loki]
      exporters: [loki]

我反复检查配置后未发现问题,但访问本地Grafana的Explorer选择Loki时始终显示无数据。我了解到部分示例使用Promtail发送日志,但我认为Otel-Collector应能完成该工作,请问我遗漏了哪些配置?


内容的提问来源于stack exchange,提问作者Art

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 03:58:10