All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.opentelemetry.javaagent.instrumentation.mongoasync.v3_3.SingleResultCallbackWrapper Maven / Gradle / Ivy

There is a newer version: 2.8.0-alpha
Show newest version
/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package io.opentelemetry.javaagent.instrumentation.mongoasync.v3_3;

import com.mongodb.async.SingleResultCallback;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;

public class SingleResultCallbackWrapper implements SingleResultCallback {
  private final Context context;
  private final SingleResultCallback delegate;

  public SingleResultCallbackWrapper(Context context, SingleResultCallback delegate) {
    this.context = context;
    this.delegate = delegate;
  }

  @Override
  public void onResult(Object server, Throwable throwable) {
    try (Scope ignored = context.makeCurrent()) {
      delegate.onResult(server, throwable);
    }
  }
}