Skip to content

Commit

Permalink
Add request param to EndTimeExtractor (#3947)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek authored Aug 27, 2021
1 parent ab9c688 commit 585cc55
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* must be comparable.
*/
@FunctionalInterface
public interface EndTimeExtractor<RESPONSE> {
public interface EndTimeExtractor<REQUEST, RESPONSE> {

/** Returns the timestamp marking the end of the response processing. */
Instant extract(@Nullable RESPONSE response);
Instant extract(REQUEST request, @Nullable RESPONSE response);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static <REQUEST, RESPONSE> InstrumenterBuilder<REQUEST, RESPONSE> newBuil
private final List<? extends RequestListener> requestListeners;
private final ErrorCauseExtractor errorCauseExtractor;
@Nullable private final StartTimeExtractor<REQUEST> startTimeExtractor;
@Nullable private final EndTimeExtractor<RESPONSE> endTimeExtractor;
@Nullable private final EndTimeExtractor<REQUEST, RESPONSE> endTimeExtractor;
private final boolean disabled;
private final SpanSuppressionStrategy spanSuppressionStrategy;

Expand Down Expand Up @@ -187,7 +187,7 @@ public void end(
}

if (endTimeExtractor != null) {
span.end(endTimeExtractor.extract(response));
span.end(endTimeExtractor.extract(request, response));
} else {
span.end();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> {
SpanStatusExtractor.getDefault();
ErrorCauseExtractor errorCauseExtractor = ErrorCauseExtractor.jdk();
@Nullable StartTimeExtractor<REQUEST> startTimeExtractor = null;
@Nullable EndTimeExtractor<RESPONSE> endTimeExtractor = null;
@Nullable EndTimeExtractor<REQUEST, RESPONSE> endTimeExtractor = null;
boolean disabled = false;

private boolean enableSpanSuppressionByType = ENABLE_SPAN_SUPPRESSION_BY_TYPE;
Expand Down Expand Up @@ -130,7 +130,8 @@ public InstrumenterBuilder<REQUEST, RESPONSE> setErrorCauseExtractor(
* determining start and end timestamps to the OpenTelemetry SDK.
*/
public InstrumenterBuilder<REQUEST, RESPONSE> setTimeExtractors(
StartTimeExtractor<REQUEST> startTimeExtractor, EndTimeExtractor<RESPONSE> endTimeExtractor) {
StartTimeExtractor<REQUEST> startTimeExtractor,
EndTimeExtractor<REQUEST, RESPONSE> endTimeExtractor) {
this.startTimeExtractor = requireNonNull(startTimeExtractor);
this.endTimeExtractor = requireNonNull(endTimeExtractor);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ void shouldStartSpanWithGivenStartTime() {
Instrumenter<Instant, Instant> instrumenter =
Instrumenter.<Instant, Instant>newBuilder(
otelTesting.getOpenTelemetry(), "test", request -> "test span")
.setTimeExtractors(request -> request, response -> response)
.setTimeExtractors(request -> request, (request, response) -> response)
.newInstrumenter();

Instant startTime = Instant.ofEpochSecond(100);
Expand Down Expand Up @@ -912,12 +912,12 @@ private static void validateInstrumentationTypeSpanPresent(SpanKey spanKey, Cont
}

private static Instrumenter<Map<String, String>, Map<String, String>> getInstrumenterWithType(
boolean enableInstrumenation, AttributesExtractor... attributeExtractors) {
boolean enableInstrumentation, AttributesExtractor... attributeExtractors) {
InstrumenterBuilder<Map<String, String>, Map<String, String>> builder =
Instrumenter.<Map<String, String>, Map<String, String>>newBuilder(
otelTesting.getOpenTelemetry(), "test", unused -> "span")
.addAttributesExtractors(attributeExtractors)
.enableInstrumentationTypeSuppression(enableInstrumenation);
.enableInstrumentationTypeSuppression(enableInstrumentation);

return builder.newClientInstrumenter(Map::put);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public final class JmsSingletons {
Instrumenter.<MessageWithDestination, Void>newBuilder(
otel, INSTRUMENTATION_NAME, spanNameExtractor)
.addAttributesExtractor(attributesExtractor)
.setTimeExtractors(MessageWithDestination::getStartTime, response -> Instant.now())
.setTimeExtractors(
MessageWithDestination::getStartTime, (request, response) -> Instant.now())
.newInstrumenter(SpanKindExtractor.alwaysConsumer());
LISTENER_INSTRUMENTER =
Instrumenter.<MessageWithDestination, Void>newBuilder(
Expand Down

0 comments on commit 585cc55

Please sign in to comment.