-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
stats/opentelemetry: Add OpenTelemetry instrumentation component #7166
Conversation
func (csh *clientStatsHandler) perCallMetrics(ctx context.Context, err error, startTime time.Time, ci *callInfo) { | ||
s := status.Convert(err) | ||
callLatency := float64(time.Since(startTime)) / float64(time.Second) | ||
if csh.clientMetrics.callDuration != nil { |
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 implement a nop
version of all these metric types and put them into the struct when the metric is disabled so we don't need all these special nil
checks? Maybe some already exist in otel?
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.
I remember having discussions with Yash last year with respect to this performance wise since it's on the RPC path. I think the argument is that a function call is much slower than a branch (who knows, maybe the compiler will inline)? Do you agree or disagree?
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.
It will be an indirect call, so an extra load and a call/return, too. I wouldn't worry about that and optimize for the way you want the code to look. This would not be measurable next to everything else, probably. If you disabled all the metrics (why? wouldn't you disable the recorder instead?), I'd assume the difference in performance between the two approaches would still be negligible.
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.
Sounds fine behavior wise. You can check the implementation to make sure there are no locks being taken.
Thanks for the pass. Got to all comments. |
stats/opentelemetry/opentelemetry.go
Outdated
@@ -248,37 +249,40 @@ type serverMetrics struct { | |||
} | |||
|
|||
func createInt64Counter(setOfMetrics map[Metric]bool, metricName Metric, meter metric.Meter, options ...metric.Int64CounterOption) metric.Int64Counter { | |||
nop := noop.Int64Counter{} |
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.
Super minor thing, but it's a little unusual to have this variable scoped here and instantiated even when you don't end up using it. Just return noop.Int64Counter{}
? Or if you wanted you could make a global nop counter for each type and ref them in the return instead.
Nice that they already had a nop implementation though!
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.
Alright I'll return inline. I was wondering the nicest way to do this too. I'd rather not make these globals to not populate namespace where only time you need it is these create functions. Thanks for the passes, this looks much better than when it started!
This PR implements the gRPC-Go instrumentation component for OpenTelemetry, as outlined in https://github.com/grpc/proposal/blob/master/A66-otel-stats.md.
RELEASE NOTES: N/A