From 1669c842c4536429f9ad51d19315af7d41507112 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Wed, 19 Feb 2020 10:24:11 +0100 Subject: [PATCH 1/3] ref: Mark transaction as failed on error --- packages/apm/src/integrations/tracing.ts | 27 +++++++++++++++--------- packages/types/src/span.ts | 4 ++-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/apm/src/integrations/tracing.ts b/packages/apm/src/integrations/tracing.ts index 8e1a30299545..38676cbe60c7 100644 --- a/packages/apm/src/integrations/tracing.ts +++ b/packages/apm/src/integrations/tracing.ts @@ -202,16 +202,23 @@ export class Tracing implements Integration { return event; } - if ( - Tracing.options.maxTransactionDuration !== 0 && - Tracing._isEnabled() && - event.type === 'transaction' && - event.timestamp && - event.start_timestamp && - (event.timestamp - event.start_timestamp > Tracing.options.maxTransactionDuration || - event.timestamp - event.start_timestamp < 0) - ) { - return null; + if (Tracing._isEnabled()) { + if ( + Tracing.options.maxTransactionDuration !== 0 && + event.type === 'transaction' && + event.timestamp && + event.start_timestamp && + (event.timestamp - event.start_timestamp > Tracing.options.maxTransactionDuration || + event.timestamp - event.start_timestamp < 0) + ) { + return null; + } + + // TODO: Once we have session this should change + // If an event is level fatal we consider the transaction failed + if (event.type !== 'transaction' && event.level === 'fatal') { + Tracing.setTransactionStatus(SpanStatus.InternalError); + } } return event; diff --git a/packages/types/src/span.ts b/packages/types/src/span.ts index 0c7a9383b1da..4bb18a38fb74 100644 --- a/packages/types/src/span.ts +++ b/packages/types/src/span.ts @@ -91,7 +91,7 @@ export enum SpanStatus { /** The operation completed successfully. */ Ok = 'ok', /** Deadline expired before operation could complete. */ - DealineExceeded = 'deadline_exceeded', + DeadlineExceeded = 'deadline_exceeded', /** 401 Unauthorized (actually does mean unauthenticated according to RFC 7235) */ Unauthenticated = 'unauthenticated', /** 403 Forbidden */ @@ -164,7 +164,7 @@ export namespace SpanStatus { case 503: return SpanStatus.Unavailable; case 504: - return SpanStatus.DealineExceeded; + return SpanStatus.DeadlineExceeded; default: return SpanStatus.InternalError; } From 5e90412ec102ba3e2ff827ff87e4b128606f028c Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Wed, 19 Feb 2020 10:52:48 +0100 Subject: [PATCH 2/3] ref: Remove transaction status --- packages/apm/src/integrations/tracing.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/packages/apm/src/integrations/tracing.ts b/packages/apm/src/integrations/tracing.ts index 38676cbe60c7..3e136e4f5bc7 100644 --- a/packages/apm/src/integrations/tracing.ts +++ b/packages/apm/src/integrations/tracing.ts @@ -203,21 +203,14 @@ export class Tracing implements Integration { } if (Tracing._isEnabled()) { - if ( - Tracing.options.maxTransactionDuration !== 0 && - event.type === 'transaction' && + const isOutdatedTransaction = event.timestamp && event.start_timestamp && (event.timestamp - event.start_timestamp > Tracing.options.maxTransactionDuration || - event.timestamp - event.start_timestamp < 0) - ) { - return null; - } + event.timestamp - event.start_timestamp < 0); - // TODO: Once we have session this should change - // If an event is level fatal we consider the transaction failed - if (event.type !== 'transaction' && event.level === 'fatal') { - Tracing.setTransactionStatus(SpanStatus.InternalError); + if (Tracing.options.maxTransactionDuration !== 0 && event.type === 'transaction' && isOutdatedTransaction) { + return null; } } From d8cf0dc257b44b57e468a33f0e2f1668ff6375b3 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Wed, 19 Feb 2020 11:22:06 +0100 Subject: [PATCH 3/3] fix: Don't set status if UnknownError --- packages/apm/src/span.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/apm/src/span.ts b/packages/apm/src/span.ts index 2fca37e62188..d473d04cbb45 100644 --- a/packages/apm/src/span.ts +++ b/packages/apm/src/span.ts @@ -238,7 +238,10 @@ export class Span implements SpanInterface, SpanContext { */ public setHttpStatus(httpStatus: number): this { this.setTag('http.status_code', String(httpStatus)); - this.setStatus(SpanStatus.fromHttpCode(httpStatus)); + const spanStatus = SpanStatus.fromHttpCode(httpStatus); + if (spanStatus !== SpanStatus.UnknownError) { + this.setStatus(spanStatus); + } return this; }