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

io.opentelemetry.opencensusshim.OpenTelemetryCtx Maven / Gradle / Ivy

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

package io.opentelemetry.opencensusshim;

import io.opencensus.trace.ContextHandle;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import javax.annotation.Nullable;

final class OpenTelemetryCtx implements ContextHandle {

  private final Context context;

  @Nullable private Scope scope;

  public OpenTelemetryCtx(Context context) {
    this.context = context;
  }

  Context getContext() {
    return context;
  }

  @Override
  @SuppressWarnings("MustBeClosedChecker")
  public ContextHandle attach() {
    scope = context.makeCurrent();
    return this;
  }

  @Override
  public void detach(ContextHandle ctx) {
    OpenTelemetryCtx impl = (OpenTelemetryCtx) ctx;
    if (impl.scope != null) {
      impl.scope.close();
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy