opentelemetry-python icon indicating copy to clipboard operation
opentelemetry-python copied to clipboard

OTLPLogExporter throws unexpected error

Open maurarlo opened this issue 2 years ago • 3 comments

Describe your environment

  • Windows system
  • Python version 3.10.9
  • Packages:
backoff                                  2.2.1
certifi                                  2022.12.7
charset-normalizer                       3.1.0
Deprecated                               1.2.13
googleapis-common-protos                 1.59.0
grpcio                                   1.53.0
idna                                     3.4
importlib-metadata                       6.0.1
opentelemetry-api                        1.21.0
opentelemetry-exporter-otlp              1.21.0
opentelemetry-exporter-otlp-proto-common 1.21.0
opentelemetry-exporter-otlp-proto-grpc   1.21.0
opentelemetry-exporter-otlp-proto-http   1.21.0
opentelemetry-proto                      1.21.0
opentelemetry-sdk                        1.21.0
opentelemetry-semantic-conventions       0.42b0
pip                                      23.3.1
protobuf                                 4.22.1
requests                                 2.28.2
setuptools                               65.5.0
typing_extensions                        4.5.0
urllib3                                  1.26.15
wrapt                                    1.15.0
zipp                                     3.15.0

Steps to reproduce

Logs are not being sent or exported to an OTEL collector.

With this OTEL configuration:

receivers:
  otlp:
    protocols:
      grpc:

processors:
  batch:

exporters:
  logging:

service:
    pipelines:
        logs:
            receivers: [otlp]
            exporters: [logging]

And this Python code:

import logging

from opentelemetry._logs import set_logger_provider
from opentelemetry.exporter.otlp.proto.grpc._log_exporter import OTLPLogExporter
from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler
from opentelemetry.sdk._logs.export import (
    BatchLogRecordProcessor,
    SimpleLogRecordProcessor,
    ConsoleLogExporter
)
from opentelemetry.sdk.resources import Resource


logger_provider = LoggerProvider(
    resource=Resource.create(
        {
            "service.name": "my-dummy-service",
            "service.instance.id": "my-first-instance",
        }
    )
)

set_logger_provider(logger_provider)

exporter = OTLPLogExporter(insecure=True)
#exporter = ConsoleLogExporter()
logger_provider.add_log_record_processor(BatchLogRecordProcessor(exporter))
#logger_provider.add_log_record_processor(SimpleLogRecordProcessor(exporter))
handler = LoggingHandler(level=logging.NOTSET, logger_provider=logger_provider)

# Attach OTLP handler
# TODO: adding handler to root does nothing or it is not reflected in the container
#logging.getLogger().addHandler(handler)
#logging.info("When you want to see some important info...")
#logging.error("There is an unexpected error...")

# Using a custom logger:
my_logger = logging.getLogger("my-dummy-service-logger")
my_logger.addHandler(handler)
my_logger.info("When you want to see some important info...")
my_logger.error("There is an unexpected error...")

The output is this: Failed to export logs to localhost:4317, error code: StatusCode.UNIMPLEMENTED

What is the expected behavior?

I was expecting that the logs would be sent to the OTEL collector and then I would be able to visualize that information from the OTEL container, but that is not happening.

What is the actual behavior?

When using the root logger, it does nothing: console output is empty and nothing is reflected in OTEL container logs.

When using a custom or namespaced logger, console output shows this error: Failed to export logs to localhost:4317, error code: StatusCode.UNIMPLEMENTED

Additional context

I have used these links as reference for this dummy code https://opentelemetry-python.readthedocs.io/en/latest/examples/logs/README.html and https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples/logs, but I cannot achieve the expected result.

maurarlo avatar Nov 22 '23 03:11 maurarlo

I am hitting the same issue, were you able to get past this?

fhuthmacher avatar Jan 17 '24 23:01 fhuthmacher

I'm not able to reproduce this. Running the script with the list of requirements and a local collector (latest main, using the above config) works fine for me. I can only get the above error if I run the script without the collector.

pmcollins avatar Jan 18 '24 16:01 pmcollins

@maurarlo @fhuthmacher

Are you still experiencing this issue?

lzchen avatar Jul 02 '24 21:07 lzchen

@maurarlo @fhuthmacher

Are you still experiencing this issue?

@lzchen, I just checked it again using version 1.25.0, and it doesn't happen anymore, I don't know if it is due to the recent version, or to the new version of the OTEL collector, but issue does not happen anymore.

maurarlo avatar Jul 13 '24 02:07 maurarlo