Skip to content

Commit

Permalink
Make sure option is set correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad committed Aug 26, 2021
1 parent ef452d6 commit fae9e68
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/tracing/src/browser/browsertracing.ts
Expand Up @@ -149,7 +149,7 @@ export class BrowserTracing implements Integration {
tracingOrigins,
};

this._metrics = new MetricsInstrumentation({ ...this.options._metricOptions, ...DEFAULT_METRICS_INSTR_OPTIONS });
this._metrics = new MetricsInstrumentation({ ...DEFAULT_METRICS_INSTR_OPTIONS, ...this.options._metricOptions });
}

/**
Expand Down
30 changes: 30 additions & 0 deletions packages/tracing/test/browser/browsertracing.test.ts
Expand Up @@ -11,6 +11,7 @@ import {
getHeaderContext,
getMetaContent,
} from '../../src/browser/browsertracing';
import { DEFAULT_METRICS_INSTR_OPTIONS, MetricsInstrumentation } from '../../src/browser/metrics';
import { defaultRequestInstrumentationOptions } from '../../src/browser/request';
import { instrumentRoutingWithDefaults } from '../../src/browser/router';
import * as hubExtensions from '../../src/hubextensions';
Expand All @@ -32,6 +33,8 @@ jest.mock('@sentry/utils', () => {
};
});

jest.mock('../../src/browser/metrics');

const { logger } = jest.requireActual('@sentry/utils');
const warnSpy = jest.spyOn(logger, 'warn');

Expand Down Expand Up @@ -493,4 +496,31 @@ describe('BrowserTracing', () => {
);
});
});

describe('metrics', () => {
beforeEach(() => {
// @ts-ignore mock clear
MetricsInstrumentation.mockClear();
});

it('creates metrics instrumentation', () => {
createBrowserTracing(true, {});

expect(MetricsInstrumentation).toHaveBeenCalledTimes(1);
expect(MetricsInstrumentation).toHaveBeenLastCalledWith(DEFAULT_METRICS_INSTR_OPTIONS);
});

it('creates metrics instrumentation with custom options', () => {
createBrowserTracing(true, {
_metricOptions: {
_reportAllChanges: true,
},
});

expect(MetricsInstrumentation).toHaveBeenCalledTimes(1);
expect(MetricsInstrumentation).toHaveBeenLastCalledWith({
_reportAllChanges: true,
});
});
});
});

0 comments on commit fae9e68

Please sign in to comment.