io.opencensus.tags.unsafe.ContextUtils Java Examples

The following examples show how to use io.opencensus.tags.unsafe.ContextUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatsRecorderImplTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void record_CurrentContextSet() {
  View view =
      View.create(
          VIEW_NAME,
          "description",
          MEASURE_DOUBLE,
          Sum.create(),
          Arrays.asList(KEY),
          Cumulative.create());
  viewManager.registerView(view);
  TagContext tags = new SimpleTagContext(Tag.create(KEY, VALUE));
  Context orig = ContextUtils.withValue(Context.current(), tags).attach();
  try {
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0).record();
  } finally {
    Context.current().detach(orig);
  }
  ViewData viewData = viewManager.getView(VIEW_NAME);

  // record() should have used the given TagContext.
  assertThat(viewData.getAggregationMap().keySet()).containsExactly(Arrays.asList(VALUE));
}
 
Example #2
Source File: CurrentTagMapUtilsTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCurrentTagMap_ContextSetToNull() {
  Context orig = ContextUtils.withValue(Context.current(), null).attach();
  try {
    TagContext tags = CurrentTagMapUtils.getCurrentTagMap();
    assertThat(tags).isNotNull();
    assertThat(tagContextToList(tags)).isEmpty();
  } finally {
    Context.current().detach(orig);
  }
}
 
Example #3
Source File: TaggerImplTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private TagContextBuilder getResultOfCurrentBuilder(TagContext tagsToSet) {
  Context orig = ContextUtils.withValue(Context.current(), tagsToSet).attach();
  try {
    return tagger.currentBuilder();
  } finally {
    Context.current().detach(orig);
  }
}
 
Example #4
Source File: TaggerImplTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private TagContext getResultOfGetCurrentTagContext(TagContext tagsToSet) {
  Context orig = ContextUtils.withValue(Context.current(), tagsToSet).attach();
  try {
    return tagger.getCurrentTagContext();
  } finally {
    Context.current().detach(orig);
  }
}
 
Example #5
Source File: TaggerImplTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private TagContext getResultOfWithTagContext(TagContext tagsToSet) {
  Scope scope = tagger.withTagContext(tagsToSet);
  try {
    return ContextUtils.getValue(Context.current());
  } finally {
    scope.close();
  }
}
 
Example #6
Source File: CensusStatsModule.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public Context filterContext(Context context) {
  if (!module.tagger.empty().equals(parentCtx)) {
    return ContextUtils.withValue(context, parentCtx);
  }
  return context;
}
 
Example #7
Source File: StatsTestUtils.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
public TagContext getCurrentTagContext() {
  return ContextUtils.TAG_CONTEXT_KEY.get();
}
 
Example #8
Source File: MeasureMapImpl.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Override
public void record() {
  // Use the context key directly, to avoid depending on the tags implementation.
  record(ContextUtils.getValue(Context.current()));
}
 
Example #9
Source File: StatsTestUtils.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public TagContext getCurrentTagContext() {
  return ContextUtils.getValue(Context.current());
}
 
Example #10
Source File: CurrentTagMapUtils.java    From opencensus-java with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the {@link TagContext} from the current context.
 *
 * @return the {@code TagContext} from the current context.
 */
static TagContext getCurrentTagMap() {
  return ContextUtils.getValue(Context.current());
}
 
Example #11
Source File: CurrentTagMapUtils.java    From opencensus-java with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a new {@link WithTagMap}.
 *
 * @param tags the {@code TagContext} to be added to the current {@code Context}.
 */
private WithTagMap(TagContext tags) {
  orig = ContextUtils.withValue(Context.current(), tags).attach();
}