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

OpenTracing Shim not converting exceptions to format expected by OpenTelemetry

Open gorbart opened this issue 5 months ago • 2 comments

Describe your environment

No response

What happened?

When using TracerShim.start_active_span as a context manager, errors raised inside this context manager are being caught by _on_error function that underneath calls SpanShim.log_kv and this is where problem lays. _on_error catches exception as an object, same with traceback and exception type. These are being passed in log_kv to OpenTelemetry's Span.add_event as argument attributes which is expected to be a dict of primitive types or lists of primitive types. All in all, OpenTelemetry logs a warning Invalid type type for attribute 'error.kind' value. Expected one of ["bool","str","bytes","int","float"] or a sequence of those types and discards this error.

It should be an easy fix with casting all objects present inside key_values to string inside log_kv function or something like that

Steps to Reproduce

with tracer.start_active_span("whatever"):
    raise Exception

Expected Result

An error present in logs

Actual Result

Warning Invalid type type for attribute 'error.kind' value. Expected one of ["bool","str","bytes","int","float"] or a sequence of those types

Additional context

No response

Would you like to implement a fix?

None

gorbart avatar Aug 27 '24 08:08 gorbart