Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add request param to EndTimeExtractor #3947

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not related to this PR, is this supposed to be using nanoTime?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably should -- I think it was using just System.currentTimeMillis()before the Instrumenter refactoring. I'll change that to take nanos into account in the next PR.

.newInstrumenter(SpanKindExtractor.alwaysConsumer());
LISTENER_INSTRUMENTER =
Instrumenter.<MessageWithDestination, Void>newBuilder(
Expand Down