From f7f18d7661917f430580c5da878a6a27f6e2b53f Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Fri, 29 May 2020 09:18:36 +0200 Subject: [PATCH 1/2] feat: Add helper for old api --- packages/apm/src/hubextensions.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/apm/src/hubextensions.ts b/packages/apm/src/hubextensions.ts index 9d1f3fb4847d..8bb744b45ecc 100644 --- a/packages/apm/src/hubextensions.ts +++ b/packages/apm/src/hubextensions.ts @@ -27,6 +27,18 @@ function traceHeaders(this: Hub): { [key: string]: string } { * @param context Properties with which the span should be created */ function startSpan(this: Hub, context: SpanContext | TransactionContext): Transaction | Span { + /** + * @deprecated + * We have this here as a fallback to not break users upgrading to the new API + */ + if ((context as any).transaction) { + logger.warn( + `Please use \`Sentry.startTransaction({name: ${(context as any).transaction}})\` to start a Transaction.`, + ); + (context as TransactionContext).name = (context as any).transaction as string; + (context as TransactionContext)._isTransaction = true; + } + // This is our safeguard so people always get a Transaction in return. // We set `_isTransaction: true` in {@link Sentry.startTransaction} to have a runtime check // if the user really wanted to create a Transaction. From ad0a452e31ddaade5c44d6317e5d826c0446a9b1 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Fri, 29 May 2020 12:07:03 +0200 Subject: [PATCH 2/2] fix: Wording and condition check --- packages/apm/src/hubextensions.ts | 17 ++++++----------- packages/types/src/hub.ts | 4 ++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/packages/apm/src/hubextensions.ts b/packages/apm/src/hubextensions.ts index 8bb744b45ecc..46bdf0088d16 100644 --- a/packages/apm/src/hubextensions.ts +++ b/packages/apm/src/hubextensions.ts @@ -20,21 +20,15 @@ function traceHeaders(this: Hub): { [key: string]: string } { } /** - * This functions starts a span. If there is already a `Span` on the Scope, - * the created Span with the SpanContext will have a reference to it and become it's child. - * Otherwise it'll crete a new `Span`. - * - * @param context Properties with which the span should be created + * {@see Hub.startSpan} */ function startSpan(this: Hub, context: SpanContext | TransactionContext): Transaction | Span { /** * @deprecated * We have this here as a fallback to not break users upgrading to the new API */ - if ((context as any).transaction) { - logger.warn( - `Please use \`Sentry.startTransaction({name: ${(context as any).transaction}})\` to start a Transaction.`, - ); + if ((context as any).transaction !== undefined) { + logger.warn(`Use \`Sentry.startTransaction({name: ${(context as any).transaction}})\` to start a Transaction.`); (context as TransactionContext).name = (context as any).transaction as string; (context as TransactionContext)._isTransaction = true; } @@ -44,8 +38,9 @@ function startSpan(this: Hub, context: SpanContext | TransactionContext): Transa // if the user really wanted to create a Transaction. if ((context as TransactionContext)._isTransaction && !(context as TransactionContext).name) { logger.warn('You are trying to start a Transaction but forgot to provide a `name` property.'); - logger.warn('Will fall back to , use `transaction.setName()` to change it.'); - (context as TransactionContext).name = ''; + const name = ''; + logger.warn(`Will fall back to \`${name}\``); + (context as TransactionContext).name = name; } if ((context as TransactionContext).name) { diff --git a/packages/types/src/hub.ts b/packages/types/src/hub.ts index 1db098d89c46..b994d00d6898 100644 --- a/packages/types/src/hub.ts +++ b/packages/types/src/hub.ts @@ -174,8 +174,8 @@ export interface Hub { traceHeaders(): { [key: string]: string }; /** - * This functions starts either a Span or a Transaction (depending on the argument passed). - * If there is a Span on the Scope we use the `trace_id` for all other created Transactions / Spans as a reference. + * This functions starts either a Span or a Transaction (depending on the context). + * If there is a Span on the Scope, the created Span will be a child. * * @param context Properties with which the Transaction/Span should be created */