BentoML icon indicating copy to clipboard operation
BentoML copied to clipboard

feature: opentelemetry logs exporter for all logs, not only monitor

Open MattiasDC opened this issue 7 months ago • 3 comments

Feature request

I would like it if it was possible to redirect all logs easily to an opentelemetry collector. Currently I only see monitoring related logs in my collector. I'm using these opentelemetry environment variables:

  • OTEL_LOGS_EXPORTER
  • OTEL_PYTHON_LOG_LEVEL
  • OTEL_EXPORTER_OTLP_ENDPOINT
  • OTEL_EXPORTER_OTLP_PROTOCOL
  • OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED
  • OTEL_PYTHON_LOG_CORRELATION

I run my bentoml command prepended with opentelemetry-instrument, but it seems that bentoml starts subprocesses which are not automatically instrumented.

Motivation

This feature would make it easy to set up opentelemetry log collector for all logs outputted by bentoml directly with otlp

Other

The reason for this seems to come from this code: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/e2ba6d43c0d9906e664da09abe8f5404e9026ec0/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/init.py#L123

MattiasDC avatar May 27 '25 15:05 MattiasDC

See https://docs.bentoml.com/en/latest/build-with-bentoml/observability/tracing.html#id3

aarnphm avatar May 28 '25 03:05 aarnphm

But isn't that only for the traces themselves? E.g. in this example there is both a traces exporter and a logs exporter

export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
opentelemetry-instrument \
  --traces_exporter console,otlp \
  --metrics_exporter console,otlp \
  --logs_exporter console,otlp \
  --service_name python-logs-example \
  python $(pwd)/example.py

MattiasDC avatar May 28 '25 06:05 MattiasDC

For example, I ran into an issue with a deployed model and found a trace with a 500 (internal server error) response. I then wanted to see the callstack of the internal server error. For this I had to check the container logs, as the logs themselves are not available in ELK, as they are not being send to the collector. Only the logs of the bentoml_monitor_data logger are being sent to opentelemetry. https://github.com/bentoml/BentoML/blob/1b09445b97b310f736cff7e2fd059f8873bd3d40/src/bentoml/_internal/monitoring/otlp.py#L202-L220

There is no way to configure this for the root logger and since BentoML uses Watcher, autoinstrumentation is to my understanding not possible

MattiasDC avatar Jun 03 '25 16:06 MattiasDC