io.opencensus.tags.Tags Java Examples

The following examples show how to use io.opencensus.tags.Tags. 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: HttpServerHandler.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link HttpServerHandler} with given parameters.
 *
 * @param tracer the Open Census tracing component.
 * @param extractor the {@code HttpExtractor} used to extract information from the
 *     request/response.
 * @param textFormat the {@code TextFormat} used in HTTP propagation.
 * @param getter the getter used when extracting information from the {@code carrier}.
 * @param publicEndpoint set to true for publicly accessible HTTP(S) server. If true then incoming
 *     tracecontext will be added as a link instead of as a parent.
 * @since 0.19
 */
public HttpServerHandler(
    Tracer tracer,
    HttpExtractor<Q, P> extractor,
    TextFormat textFormat,
    TextFormat.Getter<C> getter,
    Boolean publicEndpoint) {
  super(extractor);
  checkNotNull(tracer, "tracer");
  checkNotNull(textFormat, "textFormat");
  checkNotNull(getter, "getter");
  checkNotNull(publicEndpoint, "publicEndpoint");
  this.tracer = tracer;
  this.textFormat = textFormat;
  this.getter = getter;
  this.publicEndpoint = publicEndpoint;
  this.statsRecorder = Stats.getStatsRecorder();
  this.tagger = Tags.getTagger();
}
 
Example #2
Source File: HttpClientHandler.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link HttpClientHandler} with given parameters.
 *
 * @param tracer the Open Census tracing component.
 * @param extractor the {@code HttpExtractor} used to extract information from the
 *     request/response.
 * @param textFormat the {@code TextFormat} used in HTTP propagation.
 * @param setter the setter used when injecting information to the {@code carrier}.
 * @since 0.19
 */
public HttpClientHandler(
    Tracer tracer,
    HttpExtractor<Q, P> extractor,
    TextFormat textFormat,
    TextFormat.Setter<C> setter) {
  super(extractor);
  checkNotNull(setter, "setter");
  checkNotNull(textFormat, "textFormat");
  checkNotNull(tracer, "tracer");
  this.setter = setter;
  this.textFormat = textFormat;
  this.tracer = tracer;
  this.statsRecorder = Stats.getStatsRecorder();
  this.tagger = Tags.getTagger();
}
 
Example #3
Source File: CensusStatsModule.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link CensusStatsModule} with the default OpenCensus implementation.
 */
CensusStatsModule(Supplier<Stopwatch> stopwatchSupplier, boolean propagateTags) {
  this(
      Tags.getTagger(),
      Tags.getTagPropagationComponent().getBinarySerializer(),
      Stats.getStatsRecorder(),
      stopwatchSupplier,
      propagateTags);
}
 
Example #4
Source File: StackdriverMetrics.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
/** Records failure of the execution stage named {@code name}. */
public void measureFailure(Task task) {

  TagContext ctx =
      Tags.getTagger()
          .toBuilder(globalContext)
          .put(STAGE, TagValue.create(task.getName()))
          .put(GRADLE_PROJECT, TagValue.create(task.getProject().getPath()))
          .build();
  Stats.getStatsRecorder().newMeasureMap().put(M_SUCCESS, 0).record(ctx);
}
 
Example #5
Source File: StackdriverMetrics.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
/** Records success and latency of the execution stage named {@code name}. */
public void measureSuccess(Task task, long elapsedTime) {

  TagContext ctx =
      Tags.getTagger()
          .toBuilder(globalContext)
          .put(STAGE, TagValue.create(task.getName()))
          .put(GRADLE_PROJECT, TagValue.create(task.getProject().getPath()))
          .build();
  Stats.getStatsRecorder()
      .newMeasureMap()
      .put(M_SUCCESS, 1)
      .put(M_LATENCY, elapsedTime)
      .record(ctx);
}
 
Example #6
Source File: StackdriverMetrics.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
/** Extract opencensus context(if any) from environment. */
private static TagContext deserializeContext() {
  String serializedContext = System.getenv("OPENCENSUS_STATS_CONTEXT");
  if (serializedContext == null) {
    return Tags.getTagger().empty();
  }

  TagContextBinarySerializer serializer = Tags.getTagPropagationComponent().getBinarySerializer();

  try {
    return serializer.fromByteArray(Base64.getDecoder().decode(serializedContext));
  } catch (TagContextDeserializationException e) {
    return Tags.getTagger().empty();
  }
}
 
Example #7
Source File: OpenCensusMetricExporterSpi.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
private Scope tagScope() {
    TagContextBuilder builder = Tags.getTagger().currentBuilder();

    if (sendInstanceName)
        builder.put(INSTANCE_NAME_TAG, instanceNameValue, METADATA);

    if (sendNodeId)
        builder.put(NODE_ID_TAG, nodeIdValue, METADATA);

    if (sendConsistentId)
        builder.put(CONSISTENT_ID_TAG, consistenIdValue, METADATA);

    return builder.buildScoped();
}
 
Example #8
Source File: CensusStatsModule.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link CensusStatsModule} with the default OpenCensus implementation.
 */
CensusStatsModule(Supplier<Stopwatch> stopwatchSupplier,
    boolean propagateTags, boolean recordStartedRpcs, boolean recordFinishedRpcs,
    boolean recordRealTimeMetrics) {
  this(
      Tags.getTagger(),
      Tags.getTagPropagationComponent().getBinarySerializer(),
      Stats.getStatsRecorder(),
      stopwatchSupplier,
      propagateTags, recordStartedRpcs, recordFinishedRpcs, recordRealTimeMetrics);
}
 
Example #9
Source File: TagsTest.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Test
public void getTagger() {
  assertThat(Tags.getTagger()).isInstanceOf(TaggerImpl.class);
}
 
Example #10
Source File: TagsTest.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Test
public void getTagContextSerializer() {
  assertThat(Tags.getTagPropagationComponent()).isInstanceOf(TagPropagationComponentImpl.class);
}
 
Example #11
Source File: TagsTest.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Test
public void getTagger() {
  assertThat(Tags.getTagger()).isInstanceOf(TaggerImpl.class);
}
 
Example #12
Source File: TagsTest.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Test
public void getTagContextSerializer() {
  assertThat(Tags.getTagPropagationComponent()).isInstanceOf(TagPropagationComponentImpl.class);
}