feat!: Update cloud-spanner to minimum Node version of 22 - #9291
feat!: Update cloud-spanner to minimum Node version of 22#9291alkatrivedi wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request upgrades OpenTelemetry dependencies to v2, bumps the Node engine requirement to >=22, removes the deprecated @google-cloud/opentelemetry-resource-util package in favor of @opentelemetry/resource-detector-gcp and a local MonitoredResource interface, and updates metric view configurations and resource instantiations. The reviewer pointed out that in OpenTelemetry JS SDK v2, View and Aggregation are still classes rather than plain objects/options, and suggested reverting the plain object view configurations back to using new View and Aggregation.ExplicitBucketHistogram to prevent TypeScript compilation and runtime errors.
| View, | ||
| ExplicitBucketHistogramAggregation, | ||
| } from '@opentelemetry/sdk-metrics'; | ||
| import {AggregationType, ViewOptions} from '@opentelemetry/sdk-metrics'; |
There was a problem hiding this comment.
In OpenTelemetry JS SDK v2, View is still a class and MeterProvider expects an array of View instances rather than ViewOptions plain objects. Additionally, Aggregation is an abstract class, so plain objects cannot be assigned to it.
Please import View and Aggregation to define the views and aggregations properly.
| import {AggregationType, ViewOptions} from '@opentelemetry/sdk-metrics'; | |
| import {Aggregation, View} from '@opentelemetry/sdk-metrics'; |
| const HISTOGRAM_AGGREGATION = { | ||
| type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM as const, | ||
| options: {boundaries: HISTOGRAM_BUCKET_BOUNDARIES}, | ||
| }; | ||
|
|
||
| export const OPERATION_LATENCY_VIEW: ViewOptions = { | ||
| instrumentName: METRIC_NAME_OPERATION_LATENCIES, | ||
| aggregation: new ExplicitBucketHistogramAggregation( | ||
| HISTOGRAM_BUCKET_BOUNDARIES, | ||
| ), | ||
| }); | ||
| aggregation: HISTOGRAM_AGGREGATION, | ||
| }; | ||
|
|
||
| export const ATTEMPT_LATENCY_VIEW = new View({ | ||
| export const ATTEMPT_LATENCY_VIEW: ViewOptions = { | ||
| instrumentName: METRIC_NAME_ATTEMPT_LATENCIES, | ||
| aggregation: new ExplicitBucketHistogramAggregation( | ||
| HISTOGRAM_BUCKET_BOUNDARIES, | ||
| ), | ||
| }); | ||
| aggregation: HISTOGRAM_AGGREGATION, | ||
| }; | ||
|
|
||
| export const GFE_LATENCY_VIEW = new View({ | ||
| export const GFE_LATENCY_VIEW: ViewOptions = { | ||
| instrumentName: METRIC_NAME_GFE_LATENCIES, | ||
| aggregation: new ExplicitBucketHistogramAggregation( | ||
| HISTOGRAM_BUCKET_BOUNDARIES, | ||
| ), | ||
| }); | ||
| aggregation: HISTOGRAM_AGGREGATION, | ||
| }; | ||
|
|
||
| export const AFE_LATENCY_VIEW = new View({ | ||
| export const AFE_LATENCY_VIEW: ViewOptions = { | ||
| instrumentName: METRIC_NAME_AFE_LATENCIES, | ||
| aggregation: new ExplicitBucketHistogramAggregation( | ||
| HISTOGRAM_BUCKET_BOUNDARIES, | ||
| ), | ||
| }); | ||
| aggregation: HISTOGRAM_AGGREGATION, | ||
| }; |
There was a problem hiding this comment.
In OpenTelemetry JS SDK v2, Aggregation is an abstract class and cannot be represented as a plain object. Instead, use the static factory method Aggregation.ExplicitBucketHistogram(boundaries) to create the aggregation instance, and instantiate the views using new View(...).
This avoids TypeScript compilation errors and potential runtime failures since MeterProvider expects actual View and Aggregation instances.
| const HISTOGRAM_AGGREGATION = { | |
| type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM as const, | |
| options: {boundaries: HISTOGRAM_BUCKET_BOUNDARIES}, | |
| }; | |
| export const OPERATION_LATENCY_VIEW: ViewOptions = { | |
| instrumentName: METRIC_NAME_OPERATION_LATENCIES, | |
| aggregation: new ExplicitBucketHistogramAggregation( | |
| HISTOGRAM_BUCKET_BOUNDARIES, | |
| ), | |
| }); | |
| aggregation: HISTOGRAM_AGGREGATION, | |
| }; | |
| export const ATTEMPT_LATENCY_VIEW = new View({ | |
| export const ATTEMPT_LATENCY_VIEW: ViewOptions = { | |
| instrumentName: METRIC_NAME_ATTEMPT_LATENCIES, | |
| aggregation: new ExplicitBucketHistogramAggregation( | |
| HISTOGRAM_BUCKET_BOUNDARIES, | |
| ), | |
| }); | |
| aggregation: HISTOGRAM_AGGREGATION, | |
| }; | |
| export const GFE_LATENCY_VIEW = new View({ | |
| export const GFE_LATENCY_VIEW: ViewOptions = { | |
| instrumentName: METRIC_NAME_GFE_LATENCIES, | |
| aggregation: new ExplicitBucketHistogramAggregation( | |
| HISTOGRAM_BUCKET_BOUNDARIES, | |
| ), | |
| }); | |
| aggregation: HISTOGRAM_AGGREGATION, | |
| }; | |
| export const AFE_LATENCY_VIEW = new View({ | |
| export const AFE_LATENCY_VIEW: ViewOptions = { | |
| instrumentName: METRIC_NAME_AFE_LATENCIES, | |
| aggregation: new ExplicitBucketHistogramAggregation( | |
| HISTOGRAM_BUCKET_BOUNDARIES, | |
| ), | |
| }); | |
| aggregation: HISTOGRAM_AGGREGATION, | |
| }; | |
| export const OPERATION_LATENCY_VIEW = new View({ | |
| instrumentName: METRIC_NAME_OPERATION_LATENCIES, | |
| aggregation: Aggregation.ExplicitBucketHistogram(HISTOGRAM_BUCKET_BOUNDARIES), | |
| }); | |
| export const ATTEMPT_LATENCY_VIEW = new View({ | |
| instrumentName: METRIC_NAME_ATTEMPT_LATENCIES, | |
| aggregation: Aggregation.ExplicitBucketHistogram(HISTOGRAM_BUCKET_BOUNDARIES), | |
| }); | |
| export const GFE_LATENCY_VIEW = new View({ | |
| instrumentName: METRIC_NAME_GFE_LATENCIES, | |
| aggregation: Aggregation.ExplicitBucketHistogram(HISTOGRAM_BUCKET_BOUNDARIES), | |
| }); | |
| export const AFE_LATENCY_VIEW = new View({ | |
| instrumentName: METRIC_NAME_AFE_LATENCIES, | |
| aggregation: Aggregation.ExplicitBucketHistogram(HISTOGRAM_BUCKET_BOUNDARIES), | |
| }); |
3846226 to
290ea16
Compare
Upgrade the Node version from 18 to 22.
#8985
The PR also contains the OpenTelemetry package upgradation to v2 as part of this customer request.