[Python] OpenTelemetry LoggingInstrumentor Not Sending Logs to SigNoz

Discussão em 'Python' iniciado por Stack, Janeiro 30, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using the OpenTelemetry LoggingInstrumentor to push logs to SigNoz. The traces are being captured and displayed correctly in SigNoz, but the logs are not appearing in SigNoz. I have enabled automatic logging instrumentation using LoggingInstrumentor().instrument(set_logging_format=True), but there seems to be an issue with log ingestion.

    I've verified that my OpenTelemetry setup is correctly configured for tracing, and the OTLP gRPC exporter is successfully sending trace data. However, it appears that the logs are not being forwarded properly to SigNoz. I suspect there might be a missing configuration, an issue with the log exporter, or an incompatibility between LoggingInstrumentor and SigNoz's log processing pipeline.

    Expectation:

    I expected that enabling OpenTelemetry's LoggingInstrumentor with LoggingInstrumentor().instrument(set_logging_format=True) would automatically capture and send logs to SigNoz, similar to how traces are being successfully pushed. I anticipated seeing both traces and logs in the SigNoz dashboard, allowing for better observability and correlation between logs and traces.

    What I Tried: Configured OpenTelemetry for Logging:

    Used LoggingInstrumentor().instrument(set_logging_format=True) to enable automatic log instrumentation. Ensured that OpenTelemetry SDK and the OTLP gRPC exporter were correctly set up. Verified Trace Data:

    Checked that traces were successfully being sent and displayed in SigNoz, confirming that the OTLP exporter is functioning. Checked Logging Output Locally:

    Ensured that logs were being generated and written to local log files or console

    Code:

    from opentelemetry import trace
    from opentelemetry.sdk.trace import TracerProvider
    from opentelemetry.sdk.trace.export import BatchSpanProcessor
    from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
    from opentelemetry.sdk.resources import Resource
    from opentelemetry.instrumentation.logging import LoggingInstrumentor
    import logging

    # Configure the tracer to use OTLP exporter
    resource = Resource(attributes={
    "service.name": "your_service_name"
    })

    provider = TracerProvider(resource=resource)
    trace.set_tracer_provider(provider)

    otlp_exporter = OTLPSpanExporter(
    endpoint="***********:4317",
    insecure=True
    )

    span_processor = BatchSpanProcessor(otlp_exporter)
    provider.add_span_processor(span_processor)

    # Initialize automatic logging instrumentation
    LoggingInstrumentor().instrument(set_logging_format=True)

    # Example of logging
    logging.getLogger().setLevel(logging.INFO)

    def my_function():
    logging.info("This is an info log from my_function")

    Continue reading...

Compartilhe esta Página