io.opentelemetry.contrib.noopapi.NoopContextStorageProvider Maven / Gradle / Ivy
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.contrib.noopapi;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.ContextKey;
import io.opentelemetry.context.ContextStorage;
import io.opentelemetry.context.ContextStorageProvider;
import io.opentelemetry.context.Scope;
import javax.annotation.Nullable;
/**
* A {@link ContextStorageProvider} that returns a {@link ContextStorage} which is completely no-op.
*/
public class NoopContextStorageProvider implements ContextStorageProvider {
/** Returns a no-op context storage. */
@Override
public ContextStorage get() {
return NoopContextStorage.INSTANCE;
}
enum NoopContextStorage implements ContextStorage {
INSTANCE;
@Override
public Scope attach(Context toAttach) {
return Scope.noop();
}
@Override
public Context current() {
return NoopContext.INSTANCE;
}
}
enum NoopContext implements Context {
INSTANCE;
@Nullable
@Override
public V get(ContextKey key) {
return null;
}
@Override
public Context with(ContextKey k1, V v1) {
return this;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy