-
Notifications
You must be signed in to change notification settings - Fork 698
Exception while exporting logs: Invalid type {type(value)} of value {value} #3389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I have had the same issue since updating to Version 1.19.0/0.40b0 |
Thanks for the submission. Do either of you have a minimal program or test to reproduce this? |
Not sure if we should be making any changes here, the supported types are defined in the proto. |
Ping to have a repro of this issue. There should not be other value types besides the ones defined in the proto. |
@lzchen are you ok with closing this issue? |
Feel free to comment here if want to reopen. |
I see logging of raw objects somewhat frequently in Python codebases. @lzchen @ocelotl Would you be opposed to adding a |
@lzchen @ocelotl I'd like to see this issue reopened. I'm able to reproduce it. I think @siminn-arnorgj is proposing some valid options that deserve consideration, and this issue is blocking me from being able to adopt OpenTelemetry Exporters in my Python code. e.g. I'm using this library within the scope of a Django (not my choice) application. |
I don't have a complete working repro, but the gist of the issue was a code snippet like this:
This was raised in otel and prevented our logs from exporting properly, raising the following: Fix was just changing |
I'd also like this issue re-opened. While I'm happy to avoid passing custom types to the logger, it becomes very noisy when third party libraries do this, and the twisted python library that daphne is based on thinks this is an acceptable practice. As the python logger interface supports coercion via str or repr, the least surprising thing would be to do the same here. |
For those who follow and are using daphne like I am, the easiest way to deal with this is to patch via a super brittle diff file that will break on any bump to opentelemetry versions:
I'm using this on opentelemetry-exporter-otlp==1.26.0, you'll want to make your own diff with correct line numbers. The alternative to monkeypatch the opentelemetry-instrument command seems like it may be more robust, but the OTLP wrapper already is doing a bit more magic than I'm comfortable with. I'll also look at the other option, convincing the twisted web team to change their logging practices, and then get daphne to bump their twisted version, and then bump the version of daphne I'm using. |
If anyone can supply a reproducing script that would be helpful -- I am unable to reproduce this myself. |
This happens every time an object that is not a Here is a simple script to reproduce this issue:
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor
from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler
from opentelemetry.exporter.otlp.proto.grpc._log_exporter import OTLPLogExporter
import logging
def create_logging_handler():
logger_provider = LoggerProvider()
logger_provider.add_log_record_processor(
BatchLogRecordProcessor(OTLPLogExporter(insecure=True))
)
otel_handler = LoggingHandler(logger_provider=logger_provider)
return otel_handler
def main():
logging.basicConfig(level=logging.NOTSET)
logging.getLogger().addHandler(
create_logging_handler()
) # Add the handler to the root logger
logger = logging.getLogger(__name__)
try:
raise ValueError("Err")
except ValueError as e:
logger.error(e) # Logging of the raw exception object
import pymongo
pymongo.MongoClient("Cause pymongo to emit logs")
from twisted.logger import Logger, globalLogBeginner, STDLibLogObserver
globalLogBeginner.beginLoggingTo([STDLibLogObserver()])
Logger().info("Cause custom log message")
if __name__ == "__main__":
main() The most elegant and robust workaround I have found is to subclass the def create_logging_handler():
from pymongo.logger import LogMessage as pymongoLogMessage
from twisted.logger._stdlib import StringifiableFromEvent
logger_provider = LoggerProvider()
logger_provider.add_log_record_processor(
BatchLogRecordProcessor(OTLPLogExporter(insecure=True))
)
class ModifiedHandler(LoggingHandler):
def emit(self, record):
to_str_types = (Exception, pymongoLogMessage, StringifiableFromEvent)
if isinstance(record.msg, to_str_types):
record.msg = str(record.message)
super().emit(record)
otel_handler = ModifiedHandler(logger_provider=logger_provider)
return otel_handler This workaround fails if the unknown type is in a nested structure like I still feel like there should be a way to influence the exporter's behavior when encountering an unknown type. My suggestion is to either make the encoder an object/class which can be provided to the exporter, like so: |
Thanks for the excellent repro -- gives some context. The original issue states:
This seems like a reasonable idea. It conforms to the types supported by the protobuf spec, will eliminate the otel stacktrace logging mentioned above, and it gives other libraries some control over how their logged objects are represented when logged by otel by changing the Are there counterarguments? |
Steps to reproduce
What is the expected behavior?
No "Exception while exporting logs" errors in log
What is the actual behavior?
"Exception while exporting logs" error in log
Additional info
I think
_encode_value
atopentelemetry-python/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py
Line 79 in 8378db9
value
to string explicitly and only raise if conversion fails.The text was updated successfully, but these errors were encountered: