-
Notifications
You must be signed in to change notification settings - Fork 567
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
Confusing and delayed error "TypeError: bad argument type for built-in operation" when span name is not a string #3918
Comments
Hello, if this issue is not yet assigned to someone could I have a go at it? |
Please feel free. The contributing guide is here. If you are making progress towards submitting a PR, please report back and we can assign it to you as well. |
I tried reproducing the error but I got this: Could you please guide me as to what I should work on if this is the case? |
Can you show the stack trace? It should come from a different thread so I can't see how it could point to the Does this only happen when using unreleased code? |
It does not point to the exact line, just says that the issue is with the span name. Sorry wasn't more clear. Here is the stack trace:
|
That doesn't really cover point 2. It's trying to serialize a batch of spans, there's no way to track down which code the faulty span came from. The reason you're getting an error message seems to come down to this code in protobuf: # api_implementation.py
_implementation_type = None
try:
# pylint: disable=g-import-not-at-top
from google.protobuf.internal import _api_implementation
# The compile-time constants in the _api_implementation module can be used to
# switch to a certain implementation of the Python API at build time.
_implementation_type = _ApiVersionToImplementationType(
_api_implementation.api_version)
except ImportError:
pass # Unspecified by compiler flags.
def _CanImport(mod_name):
try:
mod = importlib.import_module(mod_name)
# Work around a known issue in the classic bootstrap .par import hook.
if not mod:
raise ImportError(mod_name + ' import succeeded but was None')
return True
except ImportError:
return False
if _implementation_type is None:
if _CanImport('google._upb._message'):
_implementation_type = 'upb'
elif _CanImport('google.protobuf.pyext._message'):
_implementation_type = 'cpp'
else:
_implementation_type = 'python'
...
def Type():
return _implementation_type # message_factory.py
if api_implementation.Type() == 'python':
from google.protobuf.internal import python_message as message_impl
else:
from google.protobuf.pyext import cpp_message as message_impl # pylint: disable=g-import-not-at-top hence the lines pointing to For me, |
Steps to reproduce
Create a span with a non-string name, then try to encode it, e.g. with the HTTP
OTLPSpanExporter
. For example:What is the actual behavior?
It logs:
What is the expected behavior?
tracer.start_span(123)
line.Overall I suggest that the concrete
opentelemetry.sdk.trace.Tracer.start_span
method and/orReadableSpan.__init__
should emit a warning if the span name is not a string and then convert the object to a string, catching any exceptions that raises. Setting an appropriate warning stacklevel is easier inTracer.start_span
, butReadableSpan.__init__
should cover more possible code paths.Context
While setting a non-string span name seems unusual and difficult to do accidentally, it happened in pydantic/logfire#176 when a user called
logger.exception(exc)
(which is normal and OK) wherelogger
is a standard librarylogging.Logger
hooked up to an OTEL tracer.The text was updated successfully, but these errors were encountered: