Class InstrumenterBuilder<REQUEST,RESPONSE>
java.lang.Object
io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder<REQUEST,RESPONSE>
A builder of
Instrumenter
. Instrumentation libraries should generally expose their own
builder with controls that are appropriate for that library and delegate to this to create the
Instrumenter
.-
Method Summary
Modifier and TypeMethodDescriptionaddAttributesExtractor
(AttributesExtractor<? super REQUEST, ? super RESPONSE> attributesExtractor) Adds aAttributesExtractor
to extract attributes from requests and responses.final InstrumenterBuilder<REQUEST,
RESPONSE> addAttributesExtractors
(AttributesExtractor<? super REQUEST, ? super RESPONSE>... attributesExtractors) AddsAttributesExtractor
s to extract attributes from requests and responses.addAttributesExtractors
(Iterable<? extends AttributesExtractor<? super REQUEST, ? super RESPONSE>> attributesExtractors) AddsAttributesExtractor
s to extract attributes from requests and responses.addContextCustomizer
(ContextCustomizer<? super REQUEST> contextCustomizer) Adds aContextCustomizer
to customize the context duringInstrumenter.start(Context, Object)
.addRequestListener
(RequestListener listener) Adds aRequestListener
which will be called for request start and end.addRequestMetrics
(RequestMetrics factory) Adds aRequestMetrics
whose metrics will be recorded for request start and end.addSpanLinksExtractor
(SpanLinksExtractor<REQUEST> spanLinksExtractor) Adds aSpanLinksExtractor
to extract span links from requests.newClientInstrumenter
(io.opentelemetry.context.propagation.TextMapSetter<REQUEST> setter) Returns a newInstrumenter
which will create client spans and inject context into requests.newConsumerInstrumenter
(io.opentelemetry.context.propagation.TextMapGetter<REQUEST> getter) Returns a newInstrumenter
which will create consumer spans and extract context from requests.Returns a newInstrumenter
which will create internal spans and do no context propagation.newInstrumenter
(SpanKindExtractor<? super REQUEST> spanKindExtractor) Returns a newInstrumenter
which will create spans with kind determined by the passedspanKindExtractor
and do no context propagation.newProducerInstrumenter
(io.opentelemetry.context.propagation.TextMapSetter<REQUEST> setter) Returns a newInstrumenter
which will create producer spans and inject context into requests.newServerInstrumenter
(io.opentelemetry.context.propagation.TextMapGetter<REQUEST> getter) Returns a newInstrumenter
which will create server spans and extract context from requests.setDisabled
(boolean disabled) Deprecated.setEnabled
(boolean enabled) Allows enabling/disabling theInstrumenter
based on theenabled
value passed as parameter.setErrorCauseExtractor
(ErrorCauseExtractor errorCauseExtractor) Sets theErrorCauseExtractor
to extract the root cause from an exception handling the request.setInstrumentationVersion
(String instrumentationVersion) Sets the instrumentation version that'll be associated with all telemetry produced by thisInstrumenter
.setSchemaUrl
(String schemaUrl) Sets the OpenTelemetry schema URL that'll be associated with all telemetry produced by thisInstrumenter
.setSpanStatusExtractor
(SpanStatusExtractor<? super REQUEST, ? super RESPONSE> spanStatusExtractor) Sets theSpanStatusExtractor
to use to determine theStatusCode
for a response.setTimeExtractor
(TimeExtractor<REQUEST, RESPONSE> timeExtractor) Sets theTimeExtractor
to extract the timestamp marking the start and end of processing.
-
Method Details
-
setInstrumentationVersion
public InstrumenterBuilder<REQUEST,RESPONSE> setInstrumentationVersion(String instrumentationVersion) Sets the instrumentation version that'll be associated with all telemetry produced by thisInstrumenter
.- Parameters:
instrumentationVersion
- is the version of the instrumentation library, not the version of the instrument*ed* library.
-
setSchemaUrl
Sets the OpenTelemetry schema URL that'll be associated with all telemetry produced by thisInstrumenter
. -
setSpanStatusExtractor
public InstrumenterBuilder<REQUEST,RESPONSE> setSpanStatusExtractor(SpanStatusExtractor<? super REQUEST, ? super RESPONSE> spanStatusExtractor) Sets theSpanStatusExtractor
to use to determine theStatusCode
for a response. -
addAttributesExtractor
public InstrumenterBuilder<REQUEST,RESPONSE> addAttributesExtractor(AttributesExtractor<? super REQUEST, ? super RESPONSE> attributesExtractor) Adds aAttributesExtractor
to extract attributes from requests and responses. -
addAttributesExtractors
public InstrumenterBuilder<REQUEST,RESPONSE> addAttributesExtractors(Iterable<? extends AttributesExtractor<? super REQUEST, ? super RESPONSE>> attributesExtractors) AddsAttributesExtractor
s to extract attributes from requests and responses. -
addAttributesExtractors
@SafeVarargs public final InstrumenterBuilder<REQUEST,RESPONSE> addAttributesExtractors(AttributesExtractor<? super REQUEST, ? super RESPONSE>... attributesExtractors) AddsAttributesExtractor
s to extract attributes from requests and responses. -
addSpanLinksExtractor
public InstrumenterBuilder<REQUEST,RESPONSE> addSpanLinksExtractor(SpanLinksExtractor<REQUEST> spanLinksExtractor) Adds aSpanLinksExtractor
to extract span links from requests. -
addContextCustomizer
public InstrumenterBuilder<REQUEST,RESPONSE> addContextCustomizer(ContextCustomizer<? super REQUEST> contextCustomizer) Adds aContextCustomizer
to customize the context duringInstrumenter.start(Context, Object)
. -
addRequestListener
Adds aRequestListener
which will be called for request start and end. -
addRequestMetrics
Adds aRequestMetrics
whose metrics will be recorded for request start and end. -
setErrorCauseExtractor
public InstrumenterBuilder<REQUEST,RESPONSE> setErrorCauseExtractor(ErrorCauseExtractor errorCauseExtractor) Sets theErrorCauseExtractor
to extract the root cause from an exception handling the request. -
setTimeExtractor
public InstrumenterBuilder<REQUEST,RESPONSE> setTimeExtractor(TimeExtractor<REQUEST, RESPONSE> timeExtractor) Sets theTimeExtractor
to extract the timestamp marking the start and end of processing. If unset, the constructed instrumenter will defer determining start and end timestamps to the OpenTelemetry SDK.Note: if metrics are generated by the Instrumenter, the start and end times from the
TimeExtractor
will be used to generate any duration metrics, but the internal metric timestamp (when it occurred) will always be stamped with "now" when the metric is recorded (i.e. there is no way to back date a metric recording). -
setEnabled
Allows enabling/disabling theInstrumenter
based on theenabled
value passed as parameter. All instrumenters are enabled by default. -
setDisabled
Deprecated.UsesetEnabled(boolean)
instead.Allows to disable theInstrumenter
. -
newClientInstrumenter
public Instrumenter<REQUEST,RESPONSE> newClientInstrumenter(io.opentelemetry.context.propagation.TextMapSetter<REQUEST> setter) Returns a newInstrumenter
which will create client spans and inject context into requests. -
newServerInstrumenter
public Instrumenter<REQUEST,RESPONSE> newServerInstrumenter(io.opentelemetry.context.propagation.TextMapGetter<REQUEST> getter) Returns a newInstrumenter
which will create server spans and extract context from requests. -
newProducerInstrumenter
public Instrumenter<REQUEST,RESPONSE> newProducerInstrumenter(io.opentelemetry.context.propagation.TextMapSetter<REQUEST> setter) Returns a newInstrumenter
which will create producer spans and inject context into requests. -
newConsumerInstrumenter
public Instrumenter<REQUEST,RESPONSE> newConsumerInstrumenter(io.opentelemetry.context.propagation.TextMapGetter<REQUEST> getter) Returns a newInstrumenter
which will create consumer spans and extract context from requests. -
newInstrumenter
Returns a newInstrumenter
which will create internal spans and do no context propagation. -
newInstrumenter
public Instrumenter<REQUEST,RESPONSE> newInstrumenter(SpanKindExtractor<? super REQUEST> spanKindExtractor) Returns a newInstrumenter
which will create spans with kind determined by the passedspanKindExtractor
and do no context propagation.
-
setEnabled(boolean)
instead.