-
Notifications
You must be signed in to change notification settings - Fork 75
impl(o11y): introduce resend_count logic #4156
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ public class SpanTracer implements ApiTracer { | |
| private final String attemptSpanName; | ||
| private final ApiTracerContext apiTracerContext; | ||
| private TraceManager.Span attemptHandle; | ||
| private long resendCount; | ||
|
|
||
| /** | ||
| * Creates a new instance of {@code SpanTracer}. | ||
|
|
@@ -65,6 +66,7 @@ public SpanTracer( | |
| this.attemptSpanName = attemptSpanName; | ||
| this.apiTracerContext = apiTracerContext; | ||
| this.attemptAttributes = new HashMap<>(); | ||
| this.resendCount = 0; | ||
| buildAttributes(); | ||
| } | ||
|
|
||
|
|
@@ -76,15 +78,48 @@ private void buildAttributes() { | |
| @Override | ||
| public void attemptStarted(Object request, int attemptNumber) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we verify that if we can reuse
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. I'll do a quick research and provide info in the PR description. |
||
| Map<String, Object> attemptAttributes = new HashMap<>(this.attemptAttributes); | ||
|
|
||
| if (this.resendCount > 0) { | ||
| ApiTracerContext.Transport transport = apiTracerContext.transport(); | ||
| if (transport == ApiTracerContext.Transport.GRPC) { | ||
| attemptAttributes.put( | ||
| ObservabilityAttributes.GRPC_RESEND_COUNT_ATTRIBUTE, this.resendCount); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This attribute should starting at 1 for the first retry per requirements doc.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we are handling that requirement in line 82: if (this.resendCount > 0) {...} |
||
| } else if (transport == ApiTracerContext.Transport.HTTP) { | ||
| attemptAttributes.put( | ||
| ObservabilityAttributes.HTTP_RESEND_COUNT_ATTRIBUTE, this.resendCount); | ||
| } | ||
| } | ||
|
|
||
| // Start the specific attempt span with the operation span as parent | ||
| this.attemptHandle = traceManager.createSpan(attemptSpanName, attemptAttributes); | ||
| this.resendCount++; | ||
| } | ||
|
|
||
| @Override | ||
| public void attemptSucceeded() { | ||
| endAttempt(); | ||
| } | ||
|
|
||
| @Override | ||
| public void attemptCancelled() { | ||
| endAttempt(); | ||
| } | ||
|
|
||
| @Override | ||
| public void attemptFailedDuration(Throwable error, java.time.Duration delay) { | ||
| endAttempt(); | ||
| } | ||
|
|
||
| @Override | ||
| public void attemptFailedRetriesExhausted(Throwable error) { | ||
| endAttempt(); | ||
| } | ||
|
|
||
| @Override | ||
| public void attemptPermanentFailure(Throwable error) { | ||
| endAttempt(); | ||
| } | ||
|
|
||
| private void endAttempt() { | ||
| if (attemptHandle != null) { | ||
| attemptHandle.end(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use
AtomicIntegerinstead? There should be only one thread modifying the value, but in case the retries happen in a different thread, the number may not be immediately visible to other thread.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do