Skip to content

Commit 3f49d0f

Browse files
committed
update with master
1 parent 3b68f51 commit 3f49d0f

File tree

2 files changed

+123
-4
lines changed

2 files changed

+123
-4
lines changed

packages/tracing/src/integrations/tracing.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { Span as SpanClass } from '../span';
1515
import { SpanStatus } from '../spanstatus';
1616
import { Transaction } from '../transaction';
1717

18+
import { Location } from './types';
19+
1820
/**
1921
* Options for Tracing integration
2022
*/
@@ -283,6 +285,44 @@ export class Tracing implements Integration {
283285
});
284286
}
285287

288+
/**
289+
* Returns a new Transaction either continued from sentry-trace meta or a new one
290+
*/
291+
private static _getNewTransaction(hub: Hub, transactionContext: TransactionContext): Transaction {
292+
let traceId;
293+
let parentSpanId;
294+
let sampled;
295+
296+
const header = Tracing._getMeta('sentry-trace');
297+
if (header) {
298+
const span = SpanClass.fromTraceparent(header);
299+
if (span) {
300+
traceId = span.traceId;
301+
parentSpanId = span.parentSpanId;
302+
sampled = span.sampled;
303+
Tracing._log(
304+
`[Tracing] found 'sentry-meta' '<meta />' continuing trace with: trace_id: ${traceId} span_id: ${parentSpanId}`,
305+
);
306+
}
307+
}
308+
309+
return hub.startTransaction({
310+
parentSpanId,
311+
sampled,
312+
traceId,
313+
trimEnd: true,
314+
...transactionContext,
315+
}) as Transaction;
316+
}
317+
318+
/**
319+
* Returns the value of a meta tag
320+
*/
321+
private static _getMeta(metaName: string): string | null {
322+
const el = document.querySelector(`meta[name=${metaName}]`);
323+
return el ? el.getAttribute('content') : null;
324+
}
325+
286326
/**
287327
* Pings the heartbeat
288328
*/
@@ -454,10 +494,7 @@ export class Tracing implements Integration {
454494
return undefined;
455495
}
456496

457-
Tracing._activeTransaction = hub.startTransaction({
458-
trimEnd: true,
459-
...transactionContext,
460-
}) as Transaction;
497+
Tracing._activeTransaction = Tracing._getNewTransaction(hub, transactionContext);
461498

462499
// We set the transaction here on the scope so error events pick up the trace context and attach it to the error
463500
hub.configureScope(scope => scope.setSpan(Tracing._activeTransaction));
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* The location (URL) of the object it is linked to. Changes done on it are reflected on the object it relates to.
3+
* Both the Document and Window interface have such a linked Location, accessible via Document.location and Window.location respectively.
4+
*
5+
* Copy Location interface so that user's dont have to include dom typings with Tracing integration
6+
* Based on https://github.com/microsoft/TypeScript/blob/4cf0afe2662980ebcd8d444dbd13d8f47d06fcd5/lib/lib.dom.d.ts#L9691
7+
*/
8+
export interface Location {
9+
/**
10+
* Returns a DOMStringList object listing the origins of the ancestor browsing contexts, from the parent browsing context to the top-level browsing context.
11+
*/
12+
readonly ancestorOrigins: DOMStringList;
13+
/**
14+
* Returns the Location object's URL's fragment (includes leading "#" if non-empty).
15+
*
16+
* Can be set, to navigate to the same URL with a changed fragment (ignores leading "#").
17+
*/
18+
hash: string;
19+
/**
20+
* Returns the Location object's URL's host and port (if different from the default port for the scheme).
21+
*
22+
* Can be set, to navigate to the same URL with a changed host and port.
23+
*/
24+
host: string;
25+
/**
26+
* Returns the Location object's URL's host.
27+
*
28+
* Can be set, to navigate to the same URL with a changed host.
29+
*/
30+
hostname: string;
31+
/**
32+
* Returns the Location object's URL.
33+
*
34+
* Can be set, to navigate to the given URL.
35+
*/
36+
href: string;
37+
// tslint:disable-next-line: completed-docs
38+
toString(): string;
39+
/**
40+
* Returns the Location object's URL's origin.
41+
*/
42+
readonly origin: string;
43+
/**
44+
* Returns the Location object's URL's path.
45+
*
46+
* Can be set, to navigate to the same URL with a changed path.
47+
*/
48+
pathname: string;
49+
/**
50+
* Returns the Location object's URL's port.
51+
*
52+
* Can be set, to navigate to the same URL with a changed port.
53+
*/
54+
port: string;
55+
/**
56+
* Returns the Location object's URL's scheme.
57+
*
58+
* Can be set, to navigate to the same URL with a changed scheme.
59+
*/
60+
protocol: string;
61+
/**
62+
* Returns the Location object's URL's query (includes leading "?" if non-empty).
63+
*
64+
* Can be set, to navigate to the same URL with a changed query (ignores leading "?").
65+
*/
66+
search: string;
67+
/**
68+
* Navigates to the given URL.
69+
*/
70+
assign(url: string): void;
71+
/**
72+
* Reloads the current page.
73+
*/
74+
reload(): void;
75+
/** @deprecated */
76+
// tslint:disable-next-line: unified-signatures completed-docs
77+
reload(forcedReload: boolean): void;
78+
/**
79+
* Removes the current page from the session history and navigates to the given URL.
80+
*/
81+
replace(url: string): void;
82+
}

0 commit comments

Comments
 (0)