Skip to content

Commit fe382e7

Browse files
HazATkamilogorek
authored andcommitted
feat: Add data/tags to span, Clear finishedSpans
1 parent 48da3f8 commit fe382e7

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

packages/hub/src/hub.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,20 @@ export class Hub implements HubInterface {
422422
return undefined;
423423
}
424424

425-
return this.captureEvent({
425+
const finishedSpans = span.finishedSpans.filter(s => s !== span);
426+
427+
const eventId = this.captureEvent({
426428
contexts: { trace: span.getTraceContext() },
427-
spans: span.finishedSpans.filter(s => s !== span),
429+
spans: finishedSpans,
428430
start_timestamp: span.startTimestamp,
429431
timestamp: span.timestamp,
430432
transaction: span.transaction,
431433
type: 'transaction',
432434
});
435+
436+
// After sending we reset the finishedSpans array
437+
span.finishedSpans = [];
438+
return eventId;
433439
}
434440
}
435441

packages/hub/src/span.ts

+24-4
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,30 @@ export class Span implements SpanInterface, SpanProps {
3838
public timestamp?: number;
3939

4040
/**
41-
* Set the transaction of the Span.
41+
* Transaction of the Span.
4242
*/
4343
public transaction?: string;
4444

4545
/**
46-
* Set the operation of the Span.
46+
* Operation of the Span.
4747
*/
4848
public op?: string;
4949

5050
/**
51-
* Set the description of the Span.
51+
* Description of the Span.
5252
*/
5353
public description?: string;
5454

55+
/**
56+
* Tags of the Span.
57+
*/
58+
public tags?: { [key: string]: string };
59+
60+
/**
61+
* Data of the Span.
62+
*/
63+
public data?: { [key: string]: any };
64+
5565
/**
5666
* List of spans that were finalized
5767
*/
@@ -83,13 +93,19 @@ export class Span implements SpanInterface, SpanProps {
8393
if (spanProps.description) {
8494
this.description = spanProps.description;
8595
}
96+
if (spanProps.data) {
97+
this.data = spanProps.data;
98+
}
99+
if (spanProps.tags) {
100+
this.tags = spanProps.tags;
101+
}
86102
}
87103

88104
/** JSDoc */
89105
public newSpan(spanProps?: Pick<SpanProps, Exclude<keyof SpanProps, 'spanId'>>): Span {
90106
const span = new Span({
91107
...spanProps,
92-
parentSpanId: this._parentSpanId,
108+
parentSpanId: this._spanId,
93109
sampled: this.sampled,
94110
traceId: this._traceId,
95111
});
@@ -140,10 +156,12 @@ export class Span implements SpanInterface, SpanProps {
140156
*/
141157
public getTraceContext(): object {
142158
return {
159+
data: this.data,
143160
description: this.description,
144161
op: this.op,
145162
parent_span_id: this._parentSpanId,
146163
span_id: this._spanId,
164+
tags: this.tags,
147165
trace_id: this._traceId,
148166
};
149167
}
@@ -153,12 +171,14 @@ export class Span implements SpanInterface, SpanProps {
153171
*/
154172
public toJSON(): object {
155173
return {
174+
data: this.data,
156175
description: this.description,
157176
op: this.op,
158177
parent_span_id: this._parentSpanId,
159178
sampled: this.sampled,
160179
span_id: this._spanId,
161180
start_timestamp: this.startTimestamp,
181+
tags: this.tags,
162182
timestamp: this.timestamp,
163183
trace_id: this._traceId,
164184
transaction: this.transaction,

packages/types/src/span.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ export interface SpanProps {
1717
spanId?: string;
1818
traceId?: string;
1919
transaction?: string;
20+
tags?: { [key: string]: string };
21+
data?: { [key: string]: any };
2022
}

0 commit comments

Comments
 (0)