Skip to content

πŸ› Bug Report: MCP Python instrumentation failed to parse HTTP Status codeΒ #3474

@thisthat

Description

@thisthat

Which component is this bug for?

AlephAlpha Instrumentation

πŸ“œ Description

In the case that a tool call has an error, the instrumentation tries to attach an error code to the span

if hasattr(result, "isError") and result.isError:
if len(result.content) > 0:
span.set_status(Status(StatusCode.ERROR, f"{result.content[0].text}"))
error_type = get_error_type(result.content[0].text)
if error_type is not None:
span.set_attribute(ERROR_TYPE, error_type)

The error code is derived by looking into the error message for any number and convert it to HTTPStatus

def get_error_type(error_message):
if not isinstance(error_message, str):
return None
match = re.search(r"\b(4\d{2}|5\d{2})\b", error_message)
if match:
num = int(match.group())
if 400 <= num <= 599:
return HTTPStatus(num).name

However, the HTTPStatus enum has a well-defined list of possible values (see them here). If the error message contains a random number, say, a port number like HTTPS 443, the HTTPStatus class will throw an error with the message 443 is not a valid HTTPStatus.

πŸ‘Ÿ Reproduction steps

Set up an MCP server where a tool call returns an error containing a number that is not part of the HTTPStatus enum.

πŸ‘ Expected behavior

The span should configure the error.type to be something like MCP tool Error. Parsing the first number found in the message as an HTTP status code is flaky and not representative of the error. If a network error occurs, the HTTP Instrumentation will report it.

πŸ‘Ž Actual Behavior with Screenshots

The tool call span wrongly reports the error as the HTTPStatus parsing error instead of the tool error.

πŸ€– Python Version

No response

πŸ“ƒ Provide any additional context for the Bug.

No response

πŸ‘€ Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

Are you willing to submit PR?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions