Skip to content

Commit 5ee0fe3

Browse files
authored
Merge branch 'master' into hazat/getTransaction
2 parents 6779197 + 1f4772e commit 5ee0fe3

File tree

8 files changed

+413
-212
lines changed

8 files changed

+413
-212
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
- [core] feat: Export `makeMain` (#2665)
1010
- [core] fix: Call `bindClient` when creating new `Hub` to make integrations work automatically (#2665)
1111
- [gatsby] feat: Add @sentry/gatsby package (#2652)
12-
- [apm] feat: Add `scope.getTransaction` to return a Transaction if it exists (#2668)
13-
- [apm] ref: Deprecate `scope.setTransaction` in favor of `scope.setTransactionName` (#2668)
12+
- [tracing] feat: Add `scope.getTransaction` to return a Transaction if it exists (#2668)
13+
- [tracing] ref: Deprecate `scope.setTransaction` in favor of `scope.setTransactionName` (#2668)
1414
- [core] ref: Rename `whitelistUrls/blacklistUrls` to `allowUrls/denyUrls` (#2671)
15+
- [react] ref: Refactor Profiler to account for update and render (#2677)
16+
- [tracing] feat: Add ability to get span from activity using `getActivitySpan` (#2677)
1517

1618
## 5.17.0
1719

packages/apm/src/integrations/tracing.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// tslint:disable: max-file-line-count
12
import { Hub } from '@sentry/hub';
23
import { Event, EventProcessor, Integration, Severity, Span, SpanContext, TransactionContext } from '@sentry/types';
34
import {
@@ -628,7 +629,7 @@ export class Tracing implements Integration {
628629
resource.startTimestamp = timeOrigin + startTime;
629630
resource.endTimestamp = resource.startTimestamp + duration;
630631
// We remember the entry script end time to calculate the difference to the first init mark
631-
if (entryScriptStartEndTime === undefined && (entryScriptSrc || '').includes(resourceName)) {
632+
if (entryScriptStartEndTime === undefined && (entryScriptSrc || '').indexOf(resourceName) > -1) {
632633
entryScriptStartEndTime = resource.endTimestamp;
633634
}
634635
}
@@ -817,6 +818,9 @@ export class Tracing implements Integration {
817818

818819
/**
819820
* Removes activity and finishes the span in case there is one
821+
* @param id the id of the activity being removed
822+
* @param spanData span data that can be updated
823+
*
820824
*/
821825
public static popActivity(id: number, spanData?: { [key: string]: any }): void {
822826
// The !id is on purpose to also fail with 0
@@ -866,6 +870,20 @@ export class Tracing implements Integration {
866870
}, timeout);
867871
}
868872
}
873+
874+
/**
875+
* Get span based on activity id
876+
*/
877+
public static getActivitySpan(id: number): Span | undefined {
878+
if (!id) {
879+
return undefined;
880+
}
881+
const activity = Tracing._activities[id];
882+
if (activity) {
883+
return activity.span;
884+
}
885+
return undefined;
886+
}
869887
}
870888

871889
/**

packages/hub/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "./tsconfig.build.json",
3-
"include": ["src/**/*.ts", "test/**/*.ts", "../apm/test/span.test.ts"],
3+
"include": ["src/**/*.ts", "test/**/*.ts"],
44
"exclude": ["dist"],
55
"compilerOptions": {
66
"rootDir": ".",

packages/integrations/src/rewriteframes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class RewriteFrames implements Integration {
3030
// Check if the frame filename begins with `/` or a Windows-style prefix such as `C:\`
3131
const isWindowsFrame = /^[A-Z]:\\/.test(frame.filename);
3232
const startsWithSlash = /^\//.test(frame.filename);
33-
if (frame.filename && (isWindowsFrame || startsWithSlash)) {
33+
if (isWindowsFrame || startsWithSlash) {
3434
const filename = isWindowsFrame
3535
? frame.filename
3636
.replace(/^[A-Z]:/, '') // remove Windows-style prefix

packages/integrations/src/vue.ts

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ interface IntegrationOptions {
5454
logErrors: boolean;
5555

5656
/**
57-
* When set to `false`, disables tracking of components lifecycle performance.
58-
* By default, it tracks only when `Tracing` integration is also enabled.
57+
* When set to `true`, enables tracking of components lifecycle performance.
58+
* It requires `Tracing` integration to be also enabled.
5959
*/
6060
tracing: boolean;
6161

@@ -75,9 +75,10 @@ interface TracingOptions {
7575
timeout: number;
7676
/**
7777
* List of hooks to keep track of during component lifecycle.
78-
* Available hooks: https://vuejs.org/v2/api/#Options-Lifecycle-Hooks
78+
* Available hooks: 'activate' | 'create' | 'destroy' | 'mount' | 'update'
79+
* Based on https://vuejs.org/v2/api/#Options-Lifecycle-Hooks
7980
*/
80-
hooks: Hook[];
81+
hooks: Operation[];
8182
}
8283

8384
/** Optional metadata attached to Sentry Event */
@@ -103,19 +104,13 @@ type Hook =
103104

104105
type Operation = 'activate' | 'create' | 'destroy' | 'mount' | 'update';
105106

106-
// Mappings from lifecycle hook to corresponding operation,
107-
// used to track already started measurements.
108-
const OPERATIONS: { [key in Hook]: Operation } = {
109-
activated: 'activate',
110-
beforeCreate: 'create',
111-
beforeDestroy: 'destroy',
112-
beforeMount: 'mount',
113-
beforeUpdate: 'update',
114-
created: 'create',
115-
deactivated: 'activate',
116-
destroyed: 'destroy',
117-
mounted: 'mount',
118-
updated: 'update',
107+
// Mappings from operation to corresponding lifecycle hook.
108+
const HOOKS: { [key in Operation]: Hook[] } = {
109+
activate: ['activated', 'deactivated'],
110+
create: ['beforeCreate', 'created'],
111+
destroy: ['beforeDestroy', 'destroyed'],
112+
mount: ['beforeMount', 'mounted'],
113+
update: ['beforeUpdate', 'updated'],
119114
};
120115

121116
const COMPONENT_NAME_REGEXP = /(?:^|[-_/])(\w)/g;
@@ -152,10 +147,10 @@ export class Vue implements Integration {
152147
Vue: getGlobalObject<any>().Vue, // tslint:disable-line:no-unsafe-any
153148
attachProps: true,
154149
logErrors: false,
155-
tracing: true,
150+
tracing: false,
156151
...options,
157152
tracingOptions: {
158-
hooks: ['beforeMount', 'mounted', 'beforeUpdate', 'updated'],
153+
hooks: ['mount', 'update'],
159154
timeout: 2000,
160155
trackComponents: false,
161156
...options.tracingOptions,
@@ -252,19 +247,18 @@ export class Vue implements Integration {
252247
}
253248
};
254249

255-
const childHandler = (hook: Hook) => {
250+
const childHandler = (hook: Hook, operation: Operation) => {
256251
// Skip components that we don't want to track to minimize the noise and give a more granular control to the user
257252
const shouldTrack = Array.isArray(this._options.tracingOptions.trackComponents)
258-
? this._options.tracingOptions.trackComponents.includes(name)
253+
? this._options.tracingOptions.trackComponents.indexOf(name) > -1
259254
: this._options.tracingOptions.trackComponents;
260255

261256
if (!this._rootSpan || !shouldTrack) {
262257
return;
263258
}
264259

265260
const now = timestampWithMs();
266-
const op = OPERATIONS[hook];
267-
const span = spans[op];
261+
const span = spans[operation];
268262

269263
// On the first handler call (before), it'll be undefined, as `$once` will add it in the future.
270264
// However, on the second call (after), it'll be already in place.
@@ -274,27 +268,40 @@ export class Vue implements Integration {
274268
} else {
275269
vm.$once(`hook:${hook}`, () => {
276270
if (this._rootSpan) {
277-
spans[op] = this._rootSpan.startChild({
271+
spans[operation] = this._rootSpan.startChild({
278272
description: `Vue <${name}>`,
279-
op,
273+
op: operation,
280274
});
281275
}
282276
});
283277
}
284278
};
285279

286280
// Each compomnent has it's own scope, so all activities are only related to one of them
287-
this._options.tracingOptions.hooks.forEach(hook => {
288-
const handler = rootMount ? rootHandler.bind(this, hook) : childHandler.bind(this, hook);
289-
const currentValue = vm.$options[hook];
290-
291-
if (Array.isArray(currentValue)) {
292-
vm.$options[hook] = [handler, ...currentValue];
293-
} else if (typeof currentValue === 'function') {
294-
vm.$options[hook] = [handler, currentValue];
295-
} else {
296-
vm.$options[hook] = [handler];
281+
this._options.tracingOptions.hooks.forEach(operation => {
282+
// Retrieve corresponding hooks from Vue lifecycle.
283+
// eg. mount => ['beforeMount', 'mounted']
284+
const internalHooks = HOOKS[operation];
285+
286+
if (!internalHooks) {
287+
logger.warn(`Unknown hook: ${operation}`);
288+
return;
297289
}
290+
291+
internalHooks.forEach(internalHook => {
292+
const handler = rootMount
293+
? rootHandler.bind(this, internalHook)
294+
: childHandler.bind(this, internalHook, operation);
295+
const currentValue = vm.$options[internalHook];
296+
297+
if (Array.isArray(currentValue)) {
298+
vm.$options[internalHook] = [handler, ...currentValue];
299+
} else if (typeof currentValue === 'function') {
300+
vm.$options[internalHook] = [handler, currentValue];
301+
} else {
302+
vm.$options[internalHook] = [handler];
303+
}
304+
});
298305
});
299306
};
300307

packages/react/src/index.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import { addGlobalEventProcessor, SDK_VERSION } from '@sentry/browser';
22

33
function createReactEventProcessor(): void {
4-
addGlobalEventProcessor(event => {
5-
event.sdk = {
6-
...event.sdk,
7-
name: 'sentry.javascript.react',
8-
packages: [
9-
...((event.sdk && event.sdk.packages) || []),
10-
{
11-
name: 'npm:@sentry/react',
12-
version: SDK_VERSION,
13-
},
14-
],
15-
version: SDK_VERSION,
16-
};
4+
if (addGlobalEventProcessor) {
5+
addGlobalEventProcessor(event => {
6+
event.sdk = {
7+
...event.sdk,
8+
name: 'sentry.javascript.react',
9+
packages: [
10+
...((event.sdk && event.sdk.packages) || []),
11+
{
12+
name: 'npm:@sentry/react',
13+
version: SDK_VERSION,
14+
},
15+
],
16+
version: SDK_VERSION,
17+
};
1718

18-
return event;
19-
});
19+
return event;
20+
});
21+
}
2022
}
2123

2224
export * from '@sentry/browser';

0 commit comments

Comments
 (0)