-
Notifications
You must be signed in to change notification settings - Fork 39
feat: add basic tracing for responses #291
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,10 @@ import ( | |
"github.com/ipfs/go-peertaskqueue/peertask" | ||
"github.com/ipfs/go-peertaskqueue/peertracker" | ||
"github.com/libp2p/go-libp2p-core/peer" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/codes" | ||
"go.opentelemetry.io/otel/trace" | ||
|
||
"github.com/ipfs/go-graphsync" | ||
"github.com/ipfs/go-graphsync/ipldutil" | ||
|
@@ -50,6 +54,7 @@ func (rm *ResponseManager) terminateRequest(key responseKey) { | |
rm.connManager.Unprotect(key.p, key.requestID.Tag()) | ||
delete(rm.inProgressResponses, key) | ||
ipr.cancelFn() | ||
ipr.span.End() | ||
} | ||
|
||
func (rm *ResponseManager) processUpdate(key responseKey, update gsmsg.GraphSyncRequest) { | ||
|
@@ -58,6 +63,13 @@ func (rm *ResponseManager) processUpdate(key responseKey, update gsmsg.GraphSync | |
log.Warnf("received update for non existent request, peer %s, request ID %d", key.p.Pretty(), key.requestID) | ||
return | ||
} | ||
|
||
_, span := otel.Tracer("graphsync").Start(trace.ContextWithSpan(rm.ctx, response.span), "processUpdate", trace.WithAttributes( | ||
attribute.Int("id", int(update.ID())), | ||
attribute.StringSlice("extensions", update.ExtensionNames()), | ||
)) | ||
defer span.End() | ||
|
||
if response.state != graphsync.Paused { | ||
response.updates = append(response.updates, update) | ||
select { | ||
|
@@ -79,11 +91,15 @@ func (rm *ResponseManager) processUpdate(key responseKey, update gsmsg.GraphSync | |
}) | ||
if result.Err != nil { | ||
response.state = graphsync.CompletingSend | ||
response.span.RecordError(result.Err) | ||
response.span.SetStatus(codes.Error, result.Err.Error()) | ||
return | ||
} | ||
if result.Unpause { | ||
err := rm.unpauseRequest(key.p, key.requestID) | ||
if err != nil { | ||
span.RecordError(err) | ||
span.SetStatus(codes.Error, result.Err.Error()) | ||
log.Warnf("error unpausing request: %s", err.Error()) | ||
} | ||
} | ||
|
@@ -119,6 +135,13 @@ func (rm *ResponseManager) abortRequest(p peer.ID, requestID graphsync.RequestID | |
return errors.New("could not find request") | ||
} | ||
|
||
_, span := otel.Tracer("graphsync").Start(trace.ContextWithSpan(rm.ctx, response.span), "abortRequest") | ||
defer span.End() | ||
span.RecordError(err) | ||
span.SetStatus(codes.Error, err.Error()) | ||
response.span.RecordError(err) | ||
response.span.SetStatus(codes.Error, err.Error()) | ||
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 dunno what good span error conventions are but should we record this twice at two different levels? 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. Yeah, I don't know and wanted to discuss this with you. This particular one is a bit tricky, others are a little more clear I think that "this error belongs to the response" but here there's span for something called "abort" and as a user I'd expect to see what that abort was about on that span, but the error is also responsible for closing the request. 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. all good by me :) |
||
|
||
if response.state != graphsync.Running { | ||
_ = rm.responseAssembler.Transaction(p, requestID, func(rb responseassembler.ResponseBuilder) error { | ||
if ipldutil.IsContextCancelErr(err) { | ||
|
@@ -155,9 +178,15 @@ func (rm *ResponseManager) processRequests(p peer.ID, requests []gsmsg.GraphSync | |
rm.processUpdate(key, request) | ||
continue | ||
} | ||
ctx, responseSpan := otel.Tracer("graphsync").Start(rm.ctx, "response", trace.WithAttributes( | ||
attribute.Int("id", int(request.ID())), | ||
attribute.Int("priority", int(request.Priority())), | ||
attribute.String("root", request.Root().String()), | ||
attribute.StringSlice("extensions", request.ExtensionNames()), | ||
)) | ||
rm.connManager.Protect(p, request.ID().Tag()) | ||
rm.requestQueuedHooks.ProcessRequestQueuedHooks(p, request) | ||
ctx, cancelFn := context.WithCancel(rm.ctx) | ||
ctx, cancelFn := context.WithCancel(ctx) | ||
sub := notifications.NewTopicDataSubscriber(&subscriber{ | ||
p: key.p, | ||
request: request, | ||
|
@@ -176,6 +205,7 @@ func (rm *ResponseManager) processRequests(p peer.ID, requests []gsmsg.GraphSync | |
rm.inProgressResponses[key] = | ||
&inProgressResponseStatus{ | ||
ctx: ctx, | ||
span: responseSpan, | ||
cancelFn: cancelFn, | ||
subscriber: sub, | ||
request: request, | ||
|
@@ -204,6 +234,8 @@ func (rm *ResponseManager) taskDataForKey(key responseKey) queryexecutor.Respons | |
loader, traverser, isPaused, err := (&queryPreparer{rm.requestHooks, rm.responseAssembler, rm.linkSystem, rm.maxLinksPerRequest}).prepareQuery(response.ctx, key.p, response.request, response.signals, response.subscriber) | ||
if err != nil { | ||
response.state = graphsync.CompletingSend | ||
response.span.RecordError(err) | ||
response.span.SetStatus(codes.Error, err.Error()) | ||
return queryexecutor.ResponseTask{Empty: true} | ||
} | ||
response.loader = loader | ||
|
@@ -216,6 +248,7 @@ func (rm *ResponseManager) taskDataForKey(key responseKey) queryexecutor.Respons | |
response.state = graphsync.Running | ||
return queryexecutor.ResponseTask{ | ||
Ctx: response.ctx, | ||
Span: response.span, | ||
Empty: false, | ||
Subscriber: response.subscriber, | ||
Request: response.request, | ||
|
@@ -249,6 +282,8 @@ func (rm *ResponseManager) finishTask(task *peertask.Task, err error) { | |
log.Infow("graphsync response processing complete (messages stil sending)", "request id", key.requestID, "peer", key.p, "total time", time.Since(response.startTime)) | ||
|
||
if err != nil { | ||
response.span.RecordError(err) | ||
response.span.SetStatus(codes.Error, err.Error()) | ||
log.Infof("response failed: %w", err) | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.