Skip to content

Commit a93cfe3

Browse files
committed
log start and end of span
1 parent c7fc025 commit a93cfe3

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

packages/tracing/src/span.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable max-lines */
22
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';
44

55
/**
66
* Keeps track of finished spans for a given transaction
@@ -169,6 +169,18 @@ export class Span implements SpanInterface {
169169

170170
childSpan.transaction = this.transaction;
171171

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+
// TODO: It would be safer to shove this in metadata (would need to move `metadata` from the `Transaction` class
178+
// to the `Span` class)
179+
childSpan.data.__log_message__ = `[Tracing] Starting ${opStr} span on transaction ${nameStr} (${idStr}).`;
180+
181+
logger.log(childSpan.data.__log_message__);
182+
}
183+
172184
return childSpan;
173185
}
174186

@@ -220,6 +232,17 @@ export class Span implements SpanInterface {
220232
* @inheritDoc
221233
*/
222234
public finish(endTimestamp?: number): void {
235+
if (
236+
__DEBUG_BUILD__ &&
237+
this.transaction &&
238+
// We only want to log this for spans, not for transactions
239+
this.transaction.spanId !== this.spanId &&
240+
this.data.__log_message__
241+
) {
242+
logger.log((this.data.__log_message__ as string).replace('Starting', 'Finishing'));
243+
delete this.data.__log_message__;
244+
}
245+
223246
this.endTimestamp = typeof endTimestamp === 'number' ? endTimestamp : timestampWithMs();
224247
}
225248

0 commit comments

Comments
 (0)