|
1 | 1 | /* eslint-disable max-lines */ |
2 | 2 | import { Primitive, Span as SpanInterface, SpanContext, Transaction } from '@sentry/types'; |
3 | | -import { dropUndefinedKeys, timestampWithMs, uuid4 } from '@sentry/utils'; |
| 3 | +import { dropUndefinedKeys, logger, timestampWithMs, uuid4 } from '@sentry/utils'; |
4 | 4 |
|
5 | 5 | /** |
6 | 6 | * Keeps track of finished spans for a given transaction |
@@ -169,6 +169,16 @@ export class Span implements SpanInterface { |
169 | 169 |
|
170 | 170 | childSpan.transaction = this.transaction; |
171 | 171 |
|
| 172 | + if (__DEBUG_BUILD__ && childSpan.transaction) { |
| 173 | + const opStr = (spanContext && spanContext.op) || '< unknown op >'; |
| 174 | + const nameStr = childSpan.transaction.name || '< unknown name >'; |
| 175 | + const idStr = childSpan.transaction.spanId; |
| 176 | + |
| 177 | + const logMessage = `[Tracing] Starting '${opStr}' span on transaction '${nameStr}' (${idStr}).`; |
| 178 | + childSpan.transaction.metadata.spanMetadata[childSpan.spanId] = { logMessage }; |
| 179 | + logger.log(logMessage); |
| 180 | + } |
| 181 | + |
172 | 182 | return childSpan; |
173 | 183 | } |
174 | 184 |
|
@@ -220,6 +230,18 @@ export class Span implements SpanInterface { |
220 | 230 | * @inheritDoc |
221 | 231 | */ |
222 | 232 | public finish(endTimestamp?: number): void { |
| 233 | + if ( |
| 234 | + __DEBUG_BUILD__ && |
| 235 | + // Don't call this for transactions |
| 236 | + this.transaction && |
| 237 | + this.transaction.spanId !== this.spanId |
| 238 | + ) { |
| 239 | + const { logMessage } = this.transaction.metadata.spanMetadata[this.spanId]; |
| 240 | + if (logMessage) { |
| 241 | + logger.log((logMessage as string).replace('Starting', 'Finishing')); |
| 242 | + } |
| 243 | + } |
| 244 | + |
223 | 245 | this.endTimestamp = typeof endTimestamp === 'number' ? endTimestamp : timestampWithMs(); |
224 | 246 | } |
225 | 247 |
|
|
0 commit comments