-
Notifications
You must be signed in to change notification settings - Fork 444
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
feat(nodejs-autoinstrumentation): enable overriding default histogram buckets #3448
base: main
Are you sure you want to change the base?
Conversation
@open-telemetry/javascript-maintainers could you have a look? I'm reluctant to introduce non-standard environment variables for instrumentations that only the operator supports. |
Yes, it would be nice to get an SDK maintainer's opinion. 👍 Fixing the unit mismatch is one thing, but we also need to allow specifying a custom list of buckets. The nodejs SDK already supports providing a list of views. As you suggested in the issue, we could alternatively specify it as an attribute on the Instrumentation CR instead of an environment variable 👍 |
@CCOLLOT is |
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.
Is the env var documented anywhere?
If it is operator specific it makes more sense to expose the setting as CR option.
It is indeed operator-specific. In the case of nodejs we need autoinstrumentation.ts to pick up the custom bucket list to pass the view to the NodeSDK. @pavolloffay An alternative would be to just rename the environment variable to make it obvious that it is operator-specific. Maybe something like OTEL_OPERATOR_NODEJS_HISTOGRAM_BUCKETS or OTEL_OPERATOR_NODEJS_INIT_CONTAINER_HISTOGRAM_BUCKETS? |
I don't like using The env vars are there for upstream auto-instrumentation features or SDK, not features that the operator implements. |
@pavolloffay |
function getView() { | ||
const buckets = process.env.OTEL_METRICS_EXPLICIT_BUCKET_HISTOGRAM; | ||
const defaultHistogramBuckets = [ | ||
0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10, |
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 follow https://opentelemetry.io/docs/specs/semconv/http/http-metrics/#http-server ?
Passing through env var is fine, but in the CR I would expect people using CR properties. Could you please as well ping someone from nodejs team to review? |
As others on this PR have said before this is a non-standard env var. If the PR was opened today against the OTel JS (or contrib) repos I'd reject it for that reason. It'd have to go through the specification process first, only then we'd accept the PR. It is somewhat common practice that implementation specific non-standard env vars end up with a naming like FWIW, the next release of |
Another thought: changing all histogram buckets with a view is likely not what users would want, because it overrides the instrument advisory parameter for each instrument, so one will end up with a lot of non-nonsensical data for any histograms that specify non-default buckets, which I expect to become the norm now that the feature has become stable. Instrument advisory parameters fro this are also implemented in OTel JS already. There's plenty of histogram data that one could write that's not seconds (request sizes for instance). Any option to override all of them (like the View in the PR does) I'd consider quite harmful, actually. |
Indeed, after taking a closer look at the spec I agree that overriding all of them is radical, to say the least. spec:
nodejs:
histogramBuckets:
- instrumentName: "http.server.duration.bucket"
buckets: [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10]
- instrumentName: "some.string.*"
buckets: [x,y,z] We would then inject an OTEL_OPERATOR_NODEJS_HISTOGRAM_BUCKETS env var to pass it to autoinstrumentation.ts, and create a view for each element of this array and pass the views to the NodeSDK. In that case, we would by default use the SDK's default values and it would be the end-user's responsibility and freedom to override what they need. |
@CCOLLOT Hmm, is there any other instrument other than the If If that's not what you're looking for, OpenTelemetry Declarative configuration will eventually be the more sustainable solution to the issue at hand because it includes all that functionality and more. |
It's good news that the SDK will fix the unit mismatch with better bucket defaults. However, I still think that users of the auto instrumentation injection should be able to control the exact bucket list through the I updated the PR with the following changes:
As a result, I've achieved the desired behavior with the following Instrumentation CR: ---
apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
name: default
spec:
env:
- name: OTEL_METRIC_EXPORT_INTERVAL
value: "30000"
exporter:
endpoint: http://otel-collector.opentelemetry.svc:4317
propagators:
- tracecontext
- baggage
nodejs:
histogramBuckets:
- instrumentName: http*
buckets: [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10]
sampler:
type: parentbased_traceidratio
argument: "1" I believe this implementation is better than the one I proposed earlier. For default buckets, it's using the SDK's defaults, which is a better separation of concerns. |
Description
Fixes #3436 (default metrics are in seconds but default buckets are in ms)
I implemented this patch to specify a new list of buckets (seconds) for the nodejs autoinstrumentation NodeSDK:
OTEL_METRICS_EXPLICIT_BUCKET_HISTOGRAM
environment variable (comma-separated list)Testing:: tested with opentelemetry operator 0.112.0 and got the expected bucket list:
Documentation: I will add the necessary documentation if the change is accepted