From dc7b761b75787edacd3e2caf9f17864846c6e911 Mon Sep 17 00:00:00 2001 From: legendecas Date: Mon, 7 Feb 2022 14:18:21 +0800 Subject: [PATCH] test(sdk-trace-base): pin core.hrtime dependencies on timeOrigin --- karma.webpack.js | 2 +- .../test/common/Span.test.ts | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/karma.webpack.js b/karma.webpack.js index bc8eb3a790..559d129b65 100644 --- a/karma.webpack.js +++ b/karma.webpack.js @@ -22,7 +22,7 @@ module.exports = { target: 'web', output: { filename: 'bundle.js' }, resolve: { extensions: ['.ts', '.js'] }, - devtool: 'inline-source-map', + devtool: 'eval-source-map', module: { rules: [ { test: /\.ts$/, use: 'ts-loader' }, diff --git a/packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts index 9f6c8e416f..2a81b4c42f 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts @@ -21,22 +21,32 @@ import { SpanContext, SpanKind, TraceFlags, + HrTime, } from '@opentelemetry/api'; import { DEFAULT_ATTRIBUTE_COUNT_LIMIT, DEFAULT_ATTRIBUTE_VALUE_LENGTH_LIMIT, - hrTime, hrTimeDuration, hrTimeToMilliseconds, hrTimeToNanoseconds, + otperformance as performance, } from '@opentelemetry/core'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; +import * as sinon from 'sinon'; import { BasicTracerProvider, Span, SpanProcessor } from '../../src'; -const performanceTimeOrigin = hrTime(); +const performanceTimeOrigin: HrTime = [1, 1]; describe('Span', () => { + beforeEach(() => { + sinon.stub(performance, 'timeOrigin') + .value(hrTimeToMilliseconds(performanceTimeOrigin)); + }); + afterEach(() => { + sinon.restore(); + }); + const tracer = new BasicTracerProvider({ spanLimits: { attributeValueLengthLimit: 100,