Interface Scope
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
NoOpTracerHook.NoOpScope
TracerHook-managed span.
Returned by TracerHook.startSpan(org.apache.juneau.rest.server.RestRequest). The framework drives
the setStatusCode / setError / close transitions inside a finally
block so the span always closes — including on exception paths.
Bridge implementations typically wrap the downstream tracer's native span / scope. The OpenTelemetry
bridge in juneau-rest-server-tracing-otel, for example, wraps an
io.opentelemetry.api.trace.Span plus its io.opentelemetry.context.Scope: setters
translate to span attribute / status writes; close() ends the span and closes the OTel
scope.
- Since:
- 10.0.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the span.default voidrecordRpcError(int code, String message) Records a JSON-RPC-level error outcome on this span.voidRecords the exception (if any) the@RestOphandler threw on the span.voidsetStatusCode(int statusCode) Records the HTTP response status code on the span.
-
Method Details
-
setStatusCode
Records the HTTP response status code on the span.Called by the framework after the
@RestOphandler completes — beforeclose(), and beforesetError(Throwable)if the handler also threw. Bridges typically translate the status into both a numeric attribute (e.g. OpenTelemetry'shttp.response.status_code) and an overall span status (HTTP5xxmaps to span-statusERROR; other codes map toUNSETper the OTel HTTP semantic conventions).- Parameters:
statusCode- The HTTP status code (e.g.200,404,500).
-
setError
Records the exception (if any) the@RestOphandler threw on the span.Called by the framework only when the handler threw — immediately before
close(). Bridges typically record the throwable as a span event with the stack trace, set the span status toERROR, and add anexception.typeattribute carrying the exception's simple-name.- Parameters:
error- The exception thrown by the handler. Nevernull when this method is called.
-
close
void close()Closes the span.Always called by the framework — via the standard
finally-block contract onAutoCloseable— whether the handler returned normally or threw. Implementations must not throw checked exceptions; the close path runs in afinallywhere masking the original handler exception is unsafe. Implementations that need to surface bridge-level errors should log + swallow instead.- Specified by:
closein interfaceAutoCloseable
-
recordRpcError
Records a JSON-RPC-level error outcome on this span.A dated MCP adapter dispatches every request over HTTP
200, so an application-level JSON-RPC error (for example an unknown tool name) never reachessetStatusCode(int)with anything but200and never throws intosetError(Throwable). This method gives such a caller a neutral way to observe that outcome on the span — called from the request-scoped tracing observation before a JSON-RPC error response is returned, distinct from both the HTTP status path and the thrown-exception path.Added as a source-compatible default so every existing
Scopeimplementation keeps compiling unchanged. The default implementation is a no-op; a bridge that wants to classify JSON-RPC errors on the span (for example the OpenTelemetry bridge injuneau-rest-server-tracing-otel) overrides it.- Parameters:
code- The JSON-RPC error code (e.g.-32601).message- The JSON-RPC error message. May benull .
-