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

OTEL tweaks #428

Merged
merged 4 commits into from
Dec 17, 2023
Merged

OTEL tweaks #428

merged 4 commits into from
Dec 17, 2023

Conversation

ash2k
Copy link
Contributor

@ash2k ash2k commented Dec 17, 2023

First commit: it's good to avoid mutable public fields because they encourage poor user behavior. It's possible to configure the histogram buckets via options, no need to make the default value mutable.

Second commit: it's better to fail early if OTEL library returned an error rather than discard an error, store nil in the field and then panic with NPE later. There will be no way to find out why the field was nil because the error was discarded. Also, it'd be better if WithClient() just returned an error.

Third commit: Second() does something weird instead of just division. It loses precision that way. OpenTelementry libraries just use division, e.g. https://github.com/open-telemetry/opentelemetry-go-contrib/blob/8e44cea6d4fe181343500b6cb680bd501b3d24aa/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go#L343-L344

Overall I think it's not the best choice to have both WithClient() and NewClient(). Why not have a single function and let the user configure if they want metrics, traces, both, and with what options. If we want to keep two functions, names are really not clear. They should be WithTracing() and WithMetrics() or something like that.

But IMO it's better to have a single function. If someone doesn't want e.g. metrics, they can provide a NOOP MeterProvider. Same with tracing - there is a NOOP TracerProvider.

@codecov-commenter
Copy link

codecov-commenter commented Dec 17, 2023

Codecov Report

Attention: 17 lines in your changes are missing coverage. Please review.

Comparison is base (8124203) 96.00% compared to head (5479ac3) 95.96%.
Report is 2 commits behind head on main.

Files Patch % Lines
rueidisotel/metrics.go 34.78% 12 Missing and 3 partials ⚠️
rueidisotel/trace.go 33.33% 1 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #428      +/-   ##
==========================================
- Coverage   96.00%   95.96%   -0.05%     
==========================================
  Files          77       77              
  Lines       32392    32403      +11     
==========================================
- Hits        31099    31095       -4     
- Misses       1103     1113      +10     
- Partials      190      195       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ash2k ash2k changed the title Otel tweaks OTEL tweaks Dec 17, 2023
rueidisotel/metrics.go Outdated Show resolved Hide resolved
@rueian
Copy link
Collaborator

rueian commented Dec 17, 2023

Hi @ash2k,

Third commit: Second() does something weird instead of just division. It loses precision that way. OpenTelementry libraries just use division.

Thank you for the reference. Good to know this fun fact.

But IMO it's better to have a single function. If someone doesn't want e.g. metrics, they can provide a NOOP MeterProvider. Same with tracing - there is a NOOP TracerProvider.

Totally agreed. I forgot to mark WithClient as deprecated when introducing the new NewClient. Would you like to help me mark WithClient as deprecated?

@ash2k
Copy link
Contributor Author

ash2k commented Dec 17, 2023

Done!

@rueian
Copy link
Collaborator

rueian commented Dec 17, 2023

Thanks @ash2k!

@rueian rueian merged commit 65f705a into redis:main Dec 17, 2023
@ash2k ash2k deleted the otel-tweaks branch December 17, 2023 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants