Skip to content

[Observability] - Auto-implement tracing/observability #485

@edeandrea

Description

@edeandrea

When interacting with an mcp server from the client, the tool entrypoint should be auto-observed by opentelemetry (if its present), like we do with REST endpoints.

Even if I manually add tracing, like this for example, the spans do not correlate with the caller.

Also, if I add the @WithSpan annotation then things blow up.

  @Tool(name = "sendEmail", value = "Sends an email")
  public ToolResponse sendEmail(Email email) {
    var span = this.tracer.spanBuilder("sendEmail")
        .setAttribute("arg.email", email.toString())
        .setParent(Context.current().with(Span.current()))
        .setSpanKind(SpanKind.SERVER)
        .startSpan();

    try {
      var mail = Mail.withText(email.to(), email.subject(), email.body())
          .setFrom(email.from());

      this.mailer.send(mail);

      return ToolResponse.success("Email successfully sent");
    }
    finally {
      span.end();
    }
  }
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions