InstrumentationContext.java 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Copyright The OpenTelemetry Authors
  3. * SPDX-License-Identifier: Apache-2.0
  4. */
  5. package io.opentelemetry.javaagent.instrumentation.api;
  6. /** Instrumentation Context API. */
  7. public class InstrumentationContext {
  8. private InstrumentationContext() {}
  9. /**
  10. * Find a {@link ContextStore} instance for given key class and context class.
  11. *
  12. * <p>Conceptually this can be thought of as a map lookup to fetch a second level map given
  13. * keyClass.
  14. *
  15. * <p>In reality, the <em>calls</em> to this method are re-written to something more performant
  16. * while injecting advice into a method.
  17. *
  18. * <p>This method must only be called within an Advice class.
  19. *
  20. * @param keyClass The key class context is attached to.
  21. * @param contextClass The context class attached to the user class.
  22. * @param <K> key class
  23. * @param <C> context class
  24. * @return The instance of context store for given arguments.
  25. */
  26. public static <Q extends K, K, C> ContextStore<Q, C> get(
  27. Class<K> keyClass, Class<C> contextClass) {
  28. throw new IllegalStateException(
  29. "Calls to this method will be rewritten by Instrumentation Context Provider (e.g. FieldBackedProvider)");
  30. }
  31. }