Skip to content
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

Merged
merged 5 commits into from
Apr 25, 2024

Conversation

zasweq
Copy link
Contributor

@zasweq zasweq commented Apr 23, 2024

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

@zasweq zasweq requested a review from dfawley April 23, 2024 18:29
@zasweq zasweq added the Type: Feature New features or improvements in behavior label Apr 23, 2024
@zasweq zasweq added this to the 1.64 Release milestone Apr 23, 2024
stats/opentelemetry/client_metrics.go Outdated Show resolved Hide resolved
stats/opentelemetry/client_metrics.go Outdated Show resolved Hide resolved
stats/opentelemetry/client_metrics.go Outdated Show resolved Hide resolved
stats/opentelemetry/client_metrics.go Outdated Show resolved Hide resolved
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 {
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

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.

stats/opentelemetry/server_metrics.go Outdated Show resolved Hide resolved
stats/opentelemetry/e2e_test.go Show resolved Hide resolved
stats/opentelemetry/e2e_test.go Outdated Show resolved Hide resolved
stats/opentelemetry/e2e_test.go Outdated Show resolved Hide resolved
stats/opentelemetry/e2e_test.go Outdated Show resolved Hide resolved
@dfawley dfawley assigned zasweq and unassigned dfawley Apr 24, 2024
@zasweq zasweq assigned dfawley and unassigned zasweq Apr 25, 2024
@zasweq
Copy link
Contributor Author

zasweq commented Apr 25, 2024

Thanks for the pass. Got to all comments.

@dfawley dfawley assigned zasweq and unassigned dfawley Apr 25, 2024
@@ -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{}
Copy link
Member

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!

Copy link
Contributor Author

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!

@zasweq zasweq merged commit 1e8b9b7 into grpc:master Apr 25, 2024
12 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Feature New features or improvements in behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants