|
| 1 | +// tslint:disable: max-file-line-count |
1 | 2 | import { Hub } from '@sentry/hub';
|
2 | 3 | import { Event, EventProcessor, Integration, Severity, Span, SpanContext, TransactionContext } from '@sentry/types';
|
3 | 4 | import {
|
@@ -116,6 +117,7 @@ interface Activity {
|
116 | 117 |
|
117 | 118 | const global = getGlobalObject<Window>();
|
118 | 119 | const defaultTracingOrigins = ['localhost', /^\//];
|
| 120 | +const SPAN_IGNORE_KEY = '__sentry_delete_span'; |
119 | 121 |
|
120 | 122 | /**
|
121 | 123 | * Tracing Integration
|
@@ -474,6 +476,11 @@ export class Tracing implements Integration {
|
474 | 476 | return span;
|
475 | 477 | }
|
476 | 478 |
|
| 479 | + // if a span is supposed to be ignored, don't add it to the transaction |
| 480 | + if (span.data[SPAN_IGNORE_KEY]) { |
| 481 | + return false; |
| 482 | + } |
| 483 | + |
477 | 484 | // We cancel all pending spans with status "cancelled" to indicate the idle transaction was finished early
|
478 | 485 | if (!span.endTimestamp) {
|
479 | 486 | span.endTimestamp = endTimestamp;
|
@@ -764,7 +771,7 @@ export class Tracing implements Integration {
|
764 | 771 | }
|
765 | 772 |
|
766 | 773 | /**
|
767 |
| - * Starts tracking for a specifc activity |
| 774 | + * Starts tracking for a specific activity |
768 | 775 | *
|
769 | 776 | * @param name Name of the activity, can be any string (Only used internally to identify the activity)
|
770 | 777 | * @param spanContext If provided a Span with the SpanContext will be created.
|
@@ -866,6 +873,31 @@ export class Tracing implements Integration {
|
866 | 873 | }, timeout);
|
867 | 874 | }
|
868 | 875 | }
|
| 876 | + |
| 877 | + /** |
| 878 | + * Cancels an activity if it exists |
| 879 | + */ |
| 880 | + public static cancelActivity(id: number): void { |
| 881 | + if (!id) { |
| 882 | + return; |
| 883 | + } |
| 884 | + |
| 885 | + const activity = Tracing._activities[id]; |
| 886 | + |
| 887 | + if (activity) { |
| 888 | + Tracing._log(`[Tracing] cancelActivity ${activity.name}#${id}`); |
| 889 | + if (activity.span) { |
| 890 | + // Ignore the span in the transaction |
| 891 | + activity.span.setData(SPAN_IGNORE_KEY, true); |
| 892 | + } |
| 893 | + |
| 894 | + // tslint:disable-next-line: no-dynamic-delete |
| 895 | + delete Tracing._activities[id]; |
| 896 | + |
| 897 | + const count = Object.keys(Tracing._activities).length; |
| 898 | + Tracing._log('[Tracing] activies count', count); |
| 899 | + } |
| 900 | + } |
869 | 901 | }
|
870 | 902 |
|
871 | 903 | /**
|
|
0 commit comments