Open1

MicroProfile Telemetry Tracing

shukawamshukawam

https://download.eclipse.org/microprofile/microprofile-telemetry-1.0/tracing/microprofile-telemetry-tracing-spec-1.0.html

Notes

The Metrics and Logging integrations of OpenTelemetry are out of scope of this specification. Implementations are free to provide support for both Metrics and Logging if desired.

仕様の範囲内なのは、Tracing だけで Metrics, Logging に関しては MicroProfile を実装する際に自由にサポートして、とのこと。

Automatic Instrumentation

Jakarta RESTful Web Services (server and client), and MicroProfile REST Clients are automatically enlisted to participate in distributed tracing without code modification as specified in the Tracing API.
These should follow the rules specified in the Semantic Conventions section.

自動計装の場合は、Jakarta RESTful Web Services(JAX-RS), MicroProfile REST Clientは分散トレーシングに自動的に登録される

Manual Instrumentation

Spanの作成は、@WithSpan が提供されているので、基本はこれを使う(トレースコンテキストとの関係付けも自動的に行われる)

@ApplicationScoped
class SpanBean{
    @WithSpan
    voidspan() {

    }

    @WithSpan("name")
    voidspanName() {

    }

    @WithSpan(kind = SpanKind.SERVER)
    voidspanKind() {

    }

    @WithSpan
    voidspanArgs(@SpanAttribute(value ="arg")Stringarg) {

    }
}

SpanBuilder も提供されているので自分で書きたいなら、これを使う

@RequestScoped
@Path("/")
public class SpanResource {
    @Inject
    Tracer tracer;

    @GET
    @Path("/span/new")
    public Response spanNew() {
        Span span = tracer.spanBuilder("span.new")
                .setSpanKind(SpanKind.INTERNAL)
                .setParent(Context.current().with(this.span))
                .setAttribute("my.attribute", "value")
                .startSpan();

        span.end();

        return Response.ok().build();
    }
}

現在のSpanを入手したいなら、Span.current() or CDI ベースで

Span.current()

@RequestScoped
@Path("/")
public class SpanResource {
    @GET
    @Path("/span/current")
    public Response spanCurrent() {
        Span span = Span.current();
        span.setAttribute("my.attribute", "value");
        return Response.ok().build();
    }
}

or CDI

@RequestScoped
@Path("/")
public class SpanResource {
    @Inject
    Span span;

    @GET
    @Path("/span/current")
    public Response spanCurrent() {
        span.setAttribute("my.attribute", "value");
        return Response.ok().build();
    }
}