[Python] using pydantic.logfire sending data to grafana-otel-container

Discussão em 'Python' iniciado por Stack, Agosto 13, 2025.

  1. Stack

    Stack Membro Participativo

    I am using lofgire to send traces, logs and metrics to grafana-otel container. However, in the grafana UI (reachable unter http://localhost:3000 and login is pw: admin & user: admin), only traces and metrics but no logs are shown.

    Here is my docker-compose to set up grafana-otel:

    grafana:
    driver: local
    loki:
    driver: local
    prometheus:
    driver: local

    services:
    alternative-backend-opentelemetry:
    image: grafana/otel-lgtm
    network_mode: host
    ports:
    - 4317:4317
    - 4318:4318
    - 3000:3000
    environment:
    - ENABLE_LOGS_LOKI=true
    - OTEL_METRIC_EXPORT_INTERVAL=500
    - GF_PATHS_DATA=/data/grafana
    volumes:
    - grafana:/data/grafana
    - prometheus:/data/prometheus
    - loki:/data/loki


    and here is an example of my app.py to send the data via logfire:

    os.environ["OTEL_METRIC_EXPORT_INTERVAL"]="5000"
    os.environ["OTEL_EXPORTER_OTLP_PROTOCOL"]="http/protobuf"
    os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"]="http://localhost:4318"
    os.environ["LOGFIRE_HTTPX_CAPTURE_ALL"]="true"

    import logfire
    import time

    logfire.configure(
    service_name='service_name',
    send_to_logfire=False,
    )

    logfire.info("User logged in")

    with logfire.span("Processing request {request_id}", request_id=123):
    # Code within this block is traced within the span
    logfire.info("Started processing")
    # ... more code ...
    logfire.info("Finished processing")


    def my_logger():
    logfire.info("I'm logging..")


    if __name__ == "__main__":
    while True:
    my_logger()
    time.sleep(20)

    Continue reading...

Compartilhe esta Página