Skip to content

Commit

Permalink
Remove Attributes combanation from onEnd, move Attributes extract fro…
Browse files Browse the repository at this point in the history
…m onStart to onEnd
  • Loading branch information
wgy035 committed Aug 7, 2024
1 parent 593db23 commit e023041
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) {
}
clientDurationHistogram.record(
(endNanos - state.startTimeNanos()) / NANOS_PER_MS,
state.startAttributes().toBuilder().putAll(endAttributes).build(),
endAttributes,
context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ abstract class RpcCommonAttributesExtractor<REQUEST, RESPONSE>

@Override
public final void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
internalSet(attributes, RPC_SYSTEM, getter.getSystem(request));
internalSet(attributes, RPC_SERVICE, getter.getService(request));
internalSet(attributes, RPC_METHOD, getter.getMethod(request));

}

@Override
Expand All @@ -42,5 +40,8 @@ public final void onEnd(
@Nullable RESPONSE response,
@Nullable Throwable error) {
// No response attributes
internalSet(attributes, RPC_SYSTEM, getter.getSystem(request));
internalSet(attributes, RPC_SERVICE, getter.getService(request));
internalSet(attributes, RPC_METHOD, getter.getMethod(request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) {
}
serverDurationHistogram.record(
(endNanos - state.startTimeNanos()) / NANOS_PER_MS,
state.startAttributes().toBuilder().putAll(endAttributes).build(),
endAttributes,
context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ private void doEnd(
if (operationListeners.length != 0) {
long endNanos = getNanos(endTime);
for (int i = operationListeners.length - 1; i >= 0; i--) {

operationListeners[i].onEnd(context, attributes, endNanos);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,7 @@ public static <REQUEST, RESPONSE> HttpClientAttributesExtractorBuilder<REQUEST,

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
super.onStart(attributes, parentContext, request);

internalServerExtractor.onStart(attributes, request);

String fullUrl = stripSensitiveData(getter.getUrlFull(request));
internalSet(attributes, UrlAttributes.URL_FULL, fullUrl);

int resendCount = resendCountIncrementer.applyAsInt(parentContext);
if (resendCount > 0) {
attributes.put(HttpAttributes.HTTP_REQUEST_RESEND_COUNT, resendCount);
}
}

@Override
Expand All @@ -90,7 +80,15 @@ public void onEnd(
@Nullable RESPONSE response,
@Nullable Throwable error) {
super.onEnd(attributes, context, request, response, error);
internalServerExtractor.onEnd(attributes, request);

String fullUrl = stripSensitiveData(getter.getUrlFull(request));
internalSet(attributes, UrlAttributes.URL_FULL, fullUrl);

int resendCount = resendCountIncrementer.applyAsInt(context);
if (resendCount > 0) {
attributes.put(HttpAttributes.HTTP_REQUEST_RESEND_COUNT, resendCount);
}
internalNetworkExtractor.onEnd(attributes, request, response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) {
return;
}

Attributes attributes = state.startAttributes().toBuilder().putAll(endAttributes).build();

duration.record((endNanos - state.startTimeNanos()) / NANOS_PER_S, attributes, context);
duration.record((endNanos - state.startTimeNanos()) / NANOS_PER_S, endAttributes, context);
}

@AutoValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ abstract class HttpCommonAttributesExtractor<

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {

}

@Override
public void onEnd(
AttributesBuilder attributes,
Context context,
REQUEST request,
@Nullable RESPONSE response,
@Nullable Throwable error) {
String method = getter.getHttpRequestMethod(request);
if (method == null || knownMethods.contains(method)) {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, method);
Expand All @@ -72,15 +82,6 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST
internalSet(attributes, requestAttributeKey(name), values);
}
}
}

@Override
public void onEnd(
AttributesBuilder attributes,
Context context,
REQUEST request,
@Nullable RESPONSE response,
@Nullable Throwable error) {

Integer statusCode = null;
if (response != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,7 @@ public static <REQUEST, RESPONSE> HttpServerAttributesExtractorBuilder<REQUEST,

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
super.onStart(attributes, parentContext, request);

internalUrlExtractor.onStart(attributes, request);
internalServerExtractor.onStart(attributes, request);
internalClientExtractor.onStart(attributes, request);

internalSet(attributes, HttpAttributes.HTTP_ROUTE, getter.getHttpRoute(request));
internalSet(attributes, UserAgentAttributes.USER_AGENT_ORIGINAL, userAgent(request));
}

@Override
Expand All @@ -94,7 +87,13 @@ public void onEnd(
@Nullable Throwable error) {

super.onEnd(attributes, context, request, response, error);
internalSet(attributes, UserAgentAttributes.USER_AGENT_ORIGINAL, userAgent(request));

internalUrlExtractor.onEnd(attributes, request);
internalServerExtractor.onEnd(attributes, request);
internalClientExtractor.onEnd(attributes, request);

internalSet(attributes, HttpAttributes.HTTP_ROUTE, getter.getHttpRoute(request));
internalNetworkExtractor.onEnd(attributes, request, response);

internalSet(attributes, HttpAttributes.HTTP_ROUTE, httpRouteGetter.apply(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) {
return;
}

Attributes attributes = state.startAttributes().toBuilder().putAll(endAttributes).build();

duration.record((endNanos - state.startTimeNanos()) / NANOS_PER_S, attributes, context);
duration.record((endNanos - state.startTimeNanos()) / NANOS_PER_S, endAttributes, context);
}

@AutoValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public static <REQUEST, RESPONSE> ClientAttributesExtractor<REQUEST, RESPONSE> c

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
internalExtractor.onStart(attributes, request);
}

@Override
Expand All @@ -54,5 +53,7 @@ public void onEnd(
Context context,
REQUEST request,
@Nullable RESPONSE response,
@Nullable Throwable error) {}
@Nullable Throwable error) {
internalExtractor.onEnd(attributes, request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public static <REQUEST, RESPONSE> ServerAttributesExtractor<REQUEST, RESPONSE> c

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
internalExtractor.onStart(attributes, request);
}

@Override
Expand All @@ -53,5 +52,7 @@ public void onEnd(
Context context,
REQUEST request,
@Nullable RESPONSE response,
@Nullable Throwable error) {}
@Nullable Throwable error) {
internalExtractor.onEnd(attributes, request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public InternalClientAttributesExtractor(
this.capturePort = capturePort;
}

public void onStart(AttributesBuilder attributes, REQUEST request) {
public void onEnd(AttributesBuilder attributes, REQUEST request) {
AddressAndPort clientAddressAndPort = addressAndPortExtractor.extract(request);

if (clientAddressAndPort.address != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public InternalServerAttributesExtractor(
this.addressAndPortExtractor = addressAndPortExtractor;
}

public void onStart(AttributesBuilder attributes, REQUEST request) {
public void onEnd(AttributesBuilder attributes, REQUEST request) {
AddressAndPort serverAddressAndPort = addressAndPortExtractor.extract(request);

if (serverAddressAndPort.address != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public static <REQUEST, RESPONSE> UrlAttributesExtractor<REQUEST, RESPONSE> crea

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
internalExtractor.onStart(attributes, request);
}

@Override
Expand All @@ -52,5 +51,7 @@ public void onEnd(
Context context,
REQUEST request,
@Nullable RESPONSE response,
@Nullable Throwable error) {}
@Nullable Throwable error) {
internalExtractor.onEnd(attributes, request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public InternalUrlAttributesExtractor(
this.alternateSchemeProvider = alternateSchemeProvider;
}

public void onStart(AttributesBuilder attributes, REQUEST request) {
public void onEnd(AttributesBuilder attributes, REQUEST request) {
String urlScheme = getUrlScheme(request);
String urlPath = getter.getUrlPath(request);
String urlQuery = getter.getUrlQuery(request);
Expand Down

0 comments on commit e023041

Please sign in to comment.