-
Notifications
You must be signed in to change notification settings - Fork 421
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 client and server tracing interceptors #1756
Conversation
|
||
class TracingTestCase: XCTestCase { | ||
override class func setUp() { | ||
InstrumentationSystem.bootstrap(TestTracer()) |
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.
Does this blow up like logging/metrics?
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.
You mean if it fails when called more than once? If so, yes, and that's why I had to do it here, so that it's called just once.
tracer.inject( | ||
serviceContext, | ||
into: &request, | ||
using: ClientRequestInjector() |
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.
Two questions here:
- Should we create the
ClientRequestInjector
only once in the init of this struct? - Is there a case where the user might want to provide their own injector here?
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.
- 👍 - had to change the
Carrier
type to beMetadata
to avoid generics hell. - I don't think so, really - these injectors are provided as part of the basic interceptor we present here. If users need more control I think they could just create their own interceptors.
return try await tracer.withSpan(context.descriptor.fullyQualifiedMethod, context: serviceContext, ofKind: .client) { span in | ||
span.addEvent("Sending request") | ||
let response = try await next(request, context) | ||
span.addEvent("Received response") |
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.
So this is interesting because we might be streaming here. We should definitely rename this to something like Received response end
or similar. Next, should we provide a mode of this interceptor that emits events on every single message?
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.
Agreed about changing the event name. With regards to emitting events on each message - I agree it could be useful. I think the only way of doing this is by creating a new RPCWriter
wrapping the passed one, so I'll take this approach for both client and server interceptors.
using: ClientRequestInjector() | ||
) | ||
|
||
return try await tracer.withSpan(context.descriptor.fullyQualifiedMethod, context: serviceContext, ofKind: .client) { span in |
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.
Are there other attributes that we might want to add to the span from the request?
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't think of anything else that would be universal to all requests
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.
LGTM! One missing final
nit
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.
This looks in pretty good shape, I mostly left nits but there are a couple of things that I think do need fixing before we can merge this.
...reTests/Call/Client/Internal/ClientRPCExecutorTestSupport/ClientRPCExecutorTestHarness.swift
Outdated
Show resolved
Hide resolved
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.
Looks good! Left one small question.
Motivation
With v2 of gRPC, we want to provide tracing interceptors for both the client and server sides.
Modifications
This change adds tracing interceptors implementations for both the client and the server, using
swift-distributed-tracing
.Result
We've got tracing interceptors.