eclipse / microprofile-telemetry

microprofile telemetry
Apache License 2.0
16 stars 16 forks source link

Allow to mark REST-Client code as failure #35

Open pilhuhn opened 1 year ago

pilhuhn commented 1 year ago

Description

As a:

...I need to be able to:

Mark an interface for a rest-client so that certain return codes trigger marking the span as failed

Something like

@WithSpan(errorOn={4xx,5xx})
@GET
@Path("/access/") // trailing slash is required by api
@Consumes("application/json")
@Produces("application/json")
RbacRaw getRbacInfo(@QueryParam("application") String application,...)

and then in the interceptor code do

  Span span = SpanBuilder.startNew()
   try {
       statusCode = doRemoteCall();   
       if (statusCode matches withSpan.errorOn) {
           span.setStatus(StatusCode.ERROR);
       }
   } catch (Exception e) {
        span.setStatus(StatusCode.ERROR);
        span.recordException(e);
   } finally {
        span.end();
  }

...which enables me to: Get non-behaving remote client calls into the trace without manually wrap all the remote client calls into the mentioned code manually.

pilhuhn commented 1 year ago

As @WithSpan is part of OTel, we should probably use a different annotation (MP-specific) for the errorOn attribute.

brunobat commented 1 year ago

Hi Heiko, The OTel spec has the concept of Sampler, to drop spans that are not needed. This use case seems to fit it. I don't think there is the need for a specific annotation. The rest-client spec can potentially be updated to include one of these filters. See an example: https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/examples/extension/src/main/java/com/example/javaagent/DemoSampler.java

Emily-Jiang commented 1 year ago

@Azquelt will take a further look at this.