add resource on tracer (#178)

* add resource on tracer

* empty->EMPTY
This commit is contained in:
Sergey Kanzhelev 2019-04-22 11:10:48 -07:00 committed by GitHub
parent 42f90bf819
commit 804ac529eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 0 deletions

View File

@ -53,8 +53,15 @@ public abstract class Resource {
private static final Map<String, String> ENV_LABEL_MAP =
parseResourceLabels(System.getenv(OC_RESOURCE_LABELS_ENV));
private static final Resource EMPTY =
new AutoValue_Resource(Collections.<String, String>emptyMap());
Resource() {}
public static Resource getEmpty() {
return EMPTY;
}
/**
* Returns a map of labels that describe the resource.
*

View File

@ -25,6 +25,7 @@ import openconsensus.context.Scope;
import openconsensus.context.propagation.BinaryFormat;
import openconsensus.context.propagation.TextFormat;
import openconsensus.internal.Utils;
import openconsensus.resource.Resource;
/**
* No-op implementations of trace classes.
@ -91,6 +92,16 @@ public final class NoopTrace {
Utils.checkNotNull(spanData, "spanData");
}
@Override
public void setResource(Resource resource) {
// do nothing
}
@Override
public Resource getResource() {
return Resource.getEmpty();
}
@Override
public BinaryFormat<SpanContext> getBinaryFormat() {
return BINARY_FORMAT;

View File

@ -22,6 +22,7 @@ import javax.annotation.Nullable;
import openconsensus.context.Scope;
import openconsensus.context.propagation.BinaryFormat;
import openconsensus.context.propagation.TextFormat;
import openconsensus.resource.Resource;
/**
* Tracer is a simple, thin class for {@link Span} creation and in-process context interaction.
@ -330,6 +331,23 @@ public abstract class Tracer {
public abstract SpanBuilder spanBuilderWithRemoteParent(
String spanName, @Nullable SpanContext remoteParentSpanContext);
/**
* Sets the {@link Resource} to be associated with all {@link Span} and {@link SpanData} objects
* recorded by this {@link Tracer}.
*
* @param resource Resource to be associated with all {@link Span} and {@link SpanData} objects.
*/
public abstract void setResource(Resource resource);
/**
* Gets the {@link Resource} that is associating with all the {@link Span} and {@link SpanData}
* objects recorded by this {@link Tracer}.
*
* @return {@link Resource} that is associating with all {@link Span} and {@link SpanData}
* objects.
*/
public abstract Resource getResource();
/**
* Records a {@link SpanData}. This API allows to send a pre-populated span object to the
* exporter. Sampling and recording decisions as well as other collection optimizations is a