Class Instrumentation
java.lang.Object
io.mishmash.opentelemetry.server.collector.Instrumentation
A simple class with helper methods for OpenTelemetry embedded collectors
own telemetry.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddErrorEvent(io.opentelemetry.api.trace.Span span, String errorMsg) Add an error to a span.voidaddErrorEvent(io.opentelemetry.api.trace.Span span, Throwable t) Add an error to a span.voidaddErrorEvent(io.opentelemetry.context.Context ctx, Throwable t) Add an error to the current span in the given context.voidAdd an event to the current span in the given context.voidendCurrentSpan(io.opentelemetry.context.Context ctx, Throwable t) End the current span in a given context with an error.io.opentelemetry.api.metrics.LongCounternewLongCounter(String name, String unit, String description) Create a new long counter metric.io.opentelemetry.api.metrics.ObservableLongGaugenewLongGauge(String name, String unit, String description, Consumer<io.opentelemetry.api.metrics.ObservableLongMeasurement> measurementCallback) Create a new long gauge metric with a callback.io.opentelemetry.api.metrics.LongHistogramCreate a new long histogram metric.io.opentelemetry.api.metrics.LongUpDownCounternewLongUpDownCounter(String name, String unit, String description) Create a new long UpDown counter metric.io.opentelemetry.api.trace.SpanstartNewSpan(io.opentelemetry.api.trace.Span parent, String spanName) Start a new child span.io.opentelemetry.api.trace.SpanstartNewSpan(String spanName) Start a new span.io.opentelemetry.context.ScopewithSpan(io.opentelemetry.api.trace.Span span) Set the given span as current.<T> CompletableFuture<T>wrapInSpan(CompletableFuture<T> future, Supplier<io.opentelemetry.api.trace.Span> newSpanSupplier) Wraps aCompletableFutureso that when it completes a span will be ended accordingly.
-
Constructor Details
-
Instrumentation
public Instrumentation()
-
-
Method Details
-
startNewSpan
Start a new span.- Parameters:
spanName- the name of the new span- Returns:
- the created span
-
startNewSpan
public io.opentelemetry.api.trace.Span startNewSpan(io.opentelemetry.api.trace.Span parent, String spanName) Start a new child span.- Parameters:
parent- the parent spanspanName- the new span name- Returns:
- the created span
-
withSpan
public io.opentelemetry.context.Scope withSpan(io.opentelemetry.api.trace.Span span) Set the given span as current.- Parameters:
span- the span- Returns:
- the scope to be used
-
wrapInSpan
public <T> CompletableFuture<T> wrapInSpan(CompletableFuture<T> future, Supplier<io.opentelemetry.api.trace.Span> newSpanSupplier) Wraps aCompletableFutureso that when it completes a span will be ended accordingly.- Type Parameters:
T- the return type of the future- Parameters:
future- the futurenewSpanSupplier- supplier of the span to wrap into- Returns:
- a new future to be used instead
-
addErrorEvent
Add an error to a span.- Parameters:
span- the spant- the exception that caused the error
-
addErrorEvent
Add an error to a span.- Parameters:
span- the spanerrorMsg- a text error message
-
addEvent
Add an event to the current span in the given context.- Parameters:
ctx- the contextmessage- the event message
-
addErrorEvent
Add an error to the current span in the given context.- Parameters:
ctx- the contextt- the exception that caused the error
-
endCurrentSpan
End the current span in a given context with an error.- Parameters:
ctx- the contextt- the exception that caused the error
-
newLongCounter
public io.opentelemetry.api.metrics.LongCounter newLongCounter(String name, String unit, String description) Create a new long counter metric.- Parameters:
name- the metric nameunit- the unit of measuredescription- the metric description- Returns:
- a new long counter
-
newLongUpDownCounter
public io.opentelemetry.api.metrics.LongUpDownCounter newLongUpDownCounter(String name, String unit, String description) Create a new long UpDown counter metric.- Parameters:
name- the metric nameunit- the unit of measuredescription- the metric description- Returns:
- a new UpDown counter metric
-
newLongGauge
public io.opentelemetry.api.metrics.ObservableLongGauge newLongGauge(String name, String unit, String description, Consumer<io.opentelemetry.api.metrics.ObservableLongMeasurement> measurementCallback) Create a new long gauge metric with a callback.- Parameters:
name- the metric nameunit- the unit of measuredescription- the metric descriptionmeasurementCallback- the callback to get values from- Returns:
- the new long gauge
-
newLongHistogram
public io.opentelemetry.api.metrics.LongHistogram newLongHistogram(String name, String unit, String description, List<Long> bucketBoundaries) Create a new long histogram metric.- Parameters:
name- the metric nameunit- the unit of measuredescription- the metric descriptionbucketBoundaries- the desired histogram buckets- Returns:
- the new long histogram metric
-