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

use Date.now() for instrument recording timestamps #3514

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
* `telemetry.sdk.name`
* `telemetry.sdk.language`
* `telemetry.sdk.version`
* fix(sdk-metrics): use Date.now() for instrument recording timestamps [#3514](https://github.com/open-telemetry/opentelemetry-js/pull/3514) @MisterSquishy
* fix(selenium-tests): updated webpack version for selenium test issue [#3456](https://github.com/open-telemetry/opentelemetry-js/issues/3456) @SaumyaBhushan

### :books: (Refine Doc)
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentelemetry/core",
"version": "1.8.0",
"version": "1.8.1",
pichlermarc marked this conversation as resolved.
Show resolved Hide resolved
"description": "OpenTelemetry Core provides constants and utilities shared by all OpenTelemetry SDK packages.",
"main": "build/src/index.js",
"module": "build/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-core/src/common/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const SECOND_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS);
* This is represented in HrTime format as [1609504210, 150000000].
* @param epochMillis
*/
function numberToHrtime(epochMillis: number): api.HrTime {
export function numberToHrtime(epochMillis: number): api.HrTime {
const epochSeconds = epochMillis / 1000;
// Decimals only.
const seconds = Math.trunc(epochSeconds);
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk-metrics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentelemetry/sdk-metrics",
"version": "1.8.0",
"version": "1.8.1",
pichlermarc marked this conversation as resolved.
Show resolved Hide resolved
"description": "OpenTelemetry metrics SDK",
"main": "build/src/index.js",
"module": "build/esm/index.js",
Expand Down Expand Up @@ -77,7 +77,7 @@
"@opentelemetry/api": ">=1.3.0 <1.4.0"
},
"dependencies": {
"@opentelemetry/core": "1.8.0",
"@opentelemetry/core": "1.8.1",
pichlermarc marked this conversation as resolved.
Show resolved Hide resolved
"@opentelemetry/resources": "1.8.0",
"lodash.merge": "4.6.2"
},
Expand Down
9 changes: 7 additions & 2 deletions packages/sdk-metrics/src/Instruments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
ObservableGauge,
ObservableUpDownCounter,
} from '@opentelemetry/api';
import { hrTime } from '@opentelemetry/core';
import { numberToHrtime } from '@opentelemetry/core';
import { InstrumentDescriptor } from './InstrumentDescriptor';
import { ObservableRegistry } from './state/ObservableRegistry';
import {
Expand Down Expand Up @@ -57,7 +57,12 @@ export class SyncInstrument {
);
value = Math.trunc(value);
}
this._writableMetricStorage.record(value, attributes, context, hrTime());
this._writableMetricStorage.record(
value,
attributes,
context,
numberToHrtime(Date.now())
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/sdk-metrics/src/aggregator/LastValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
LastValue,
} from './types';
import { HrTime } from '@opentelemetry/api';
import { hrTime, hrTimeToMicroseconds } from '@opentelemetry/core';
import { numberToHrtime, hrTimeToMicroseconds } from '@opentelemetry/core';
import { DataPointType, GaugeMetricData } from '../export/MetricData';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Maybe } from '../utils';
Expand All @@ -37,7 +37,7 @@ export class LastValueAccumulation implements Accumulation {

record(value: number): void {
this._current = value;
this.sampleTime = hrTime();
this.sampleTime = numberToHrtime(Date.now());
}

setStartTime(startTime: HrTime): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk-metrics/src/state/MetricCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { hrTime } from '@opentelemetry/core';
import { numberToHrtime } from '@opentelemetry/core';
import { AggregationTemporalitySelector } from '../export/AggregationSelector';
import { CollectionResult } from '../export/MetricData';
import { MetricProducer, MetricCollectOptions } from '../export/MetricProducer';
Expand All @@ -36,7 +36,7 @@ export class MetricCollector implements MetricProducer {
) {}

async collect(options?: MetricCollectOptions): Promise<CollectionResult> {
const collectionTime = hrTime();
const collectionTime = numberToHrtime(Date.now());
const meterCollectionPromises = Array.from(
this._sharedState.meterSharedStates.values()
).map(meterSharedState =>
Expand Down