Search in sources :

Example 1 with ContextPayload

use of io.opentelemetry.javaagent.instrumentation.rmi.context.ContextPayload in project opentelemetry-java-instrumentation by open-telemetry.

the class ContextDispatcher method dispatch.

@Override
// Instrumenting deprecated class
@SuppressWarnings("deprecation")
public void dispatch(Remote obj, java.rmi.server.RemoteCall call) throws IOException {
    ObjectInput in = call.getInputStream();
    int operationId = in.readInt();
    // skip 8 bytes
    in.readLong();
    if (PROPAGATOR.isOperationWithPayload(operationId)) {
        ContextPayload payload = ContextPayload.read(in);
        if (payload != null) {
            Context context = payload.extract();
            SpanContext spanContext = Span.fromContext(context).getSpanContext();
            if (spanContext.isValid()) {
                THREAD_LOCAL_CONTEXT.set(context);
            } else {
                THREAD_LOCAL_CONTEXT.set(null);
            }
        }
    }
    // send result stream the client is expecting
    call.getResultStream(true);
    // release held streams to allow next call to continue
    call.releaseInputStream();
    call.releaseOutputStream();
    call.done();
}
Also used : Context(io.opentelemetry.context.Context) SpanContext(io.opentelemetry.api.trace.SpanContext) ContextPayload(io.opentelemetry.javaagent.instrumentation.rmi.context.ContextPayload) SpanContext(io.opentelemetry.api.trace.SpanContext) ObjectInput(java.io.ObjectInput)

Aggregations

SpanContext (io.opentelemetry.api.trace.SpanContext)1 Context (io.opentelemetry.context.Context)1 ContextPayload (io.opentelemetry.javaagent.instrumentation.rmi.context.ContextPayload)1 ObjectInput (java.io.ObjectInput)1