Skip to content

Commit dcf4c7f

Browse files
committed
meta: Cleanup
1 parent d8c7574 commit dcf4c7f

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

packages/apm/src/hub.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Hub as BaseHub } from '@sentry/hub';
1+
import { getCurrentHub, Hub as BaseHub, makeMain } from '@sentry/hub';
22
import { Hub as BaseHubInterface, SpanContext } from '@sentry/types';
33

44
import { Span } from './span';
@@ -82,3 +82,11 @@ export class Hub extends BaseHub implements ApmHubInterface {
8282
return span;
8383
}
8484
}
85+
86+
/**
87+
* This will make the APM Hub the main one while maintaining the client and scope of the current hub
88+
*/
89+
export function makeApmHubMain(): void {
90+
const hub = getCurrentHub();
91+
makeMain(new Hub(hub.getClient(), hub.getScope()));
92+
}

packages/apm/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as ApmIntegrations from './integrations';
22

3-
export { Hub } from './hub';
3+
export { Hub, makeApmHubMain as makeMain } from './hub';
44
export { ApmIntegrations as Integrations };
55
export { Span, TRACEPARENT_REGEXP } from './span';

packages/apm/src/integrations/express.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { logger } from '@sentry/utils';
33
// tslint:disable-next-line:no-implicit-dependencies
44
import { Application, ErrorRequestHandler, NextFunction, Request, RequestHandler, Response } from 'express';
55

6-
import { Hub } from '../hub';
6+
import { Hub, makeApmHubMain } from '../hub';
77

88
/**
99
* Express integration
@@ -32,6 +32,7 @@ export class Express implements Integration {
3232
*/
3333
public constructor(options: { app?: Application } = {}) {
3434
this._app = options.app;
35+
makeApmHubMain();
3536
}
3637

3738
/**

packages/apm/src/integrations/tracing.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { makeMain } from '@sentry/hub';
21
import { EventProcessor, Integration } from '@sentry/types';
32
import { fill, getGlobalObject, isMatchingPattern, logger, supportsNativeFetch } from '@sentry/utils';
43

5-
import { Hub } from '../hub';
4+
import { Hub, makeApmHubMain } from '../hub';
65

76
/** JSDoc */
87
interface TracingOptions {
@@ -38,8 +37,7 @@ export class Tracing implements Integration {
3837
* @param _options TracingOptions
3938
*/
4039
public constructor(private readonly _options: TracingOptions = {}) {
41-
// TODO
42-
makeMain(new Hub());
40+
makeApmHubMain();
4341
if (!Array.isArray(_options.tracingOrigins) || _options.tracingOrigins.length === 0) {
4442
const defaultTracingOrigins = ['localhost', /^\//];
4543
logger.warn(

packages/apm/src/integrations/transactionactivity.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { makeMain } from '@sentry/hub';
21
import { EventProcessor, Integration, Span, SpanContext } from '@sentry/types';
32
import { getGlobalObject } from '@sentry/utils';
43

5-
import { Hub } from '../hub';
4+
import { Hub, makeApmHubMain } from '../hub';
65

76
/** JSDoc */
87
interface TransactionActivityOptions {
@@ -56,8 +55,7 @@ export class TransactionActivity implements Integration {
5655
* @inheritDoc
5756
*/
5857
public constructor(public readonly _options?: Partial<TransactionActivityOptions>) {
59-
// TODO
60-
makeMain(new Hub());
58+
makeApmHubMain();
6159
const defaults = {
6260
idleTimeout: 500,
6361
startTransactionOnLocationChange: true,

0 commit comments

Comments
 (0)