Skip to content

Commit 707e622

Browse files
committed
feat: Add data before finish span
1 parent 3e28014 commit 707e622

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

packages/hub/src/span.ts

+5-15
Original file line numberDiff line numberDiff line change
@@ -210,49 +210,39 @@ export class Span implements SpanInterface, SpanContext {
210210
}
211211

212212
/**
213-
* Sets the tag attribute on the current span
214-
* @param key Tag key
215-
* @param value Tag value
213+
* @inheritDoc
216214
*/
217215
public setTag(key: string, value: string): this {
218216
this.tags = { ...this.tags, [key]: value };
219217
return this;
220218
}
221219

222220
/**
223-
* Sets the data attribute on the current span
224-
* @param key Data key
225-
* @param value Data value
221+
* @inheritDoc
226222
*/
227223
public setData(key: string, value: any): this {
228224
this.data = { ...this.data, [key]: value };
229225
return this;
230226
}
231227

232228
/**
233-
* Sets the data attribute on the current span
234-
* @param key Data key
235-
* @param value Data value
229+
* @inheritDoc
236230
*/
237231
public setFailure(): this {
238232
this.setTag('status', 'failure');
239233
return this;
240234
}
241235

242236
/**
243-
* Sets the data attribute on the current span
244-
* @param key Data key
245-
* @param value Data value
237+
* @inheritDoc
246238
*/
247239
public setSuccess(): this {
248240
this.setTag('status', 'success');
249241
return this;
250242
}
251243

252244
/**
253-
* Sets the data attribute on the current span
254-
* @param key Data key
255-
* @param value Data value
245+
* @inheritDoc
256246
*/
257247
public isSuccess(): boolean {
258248
return this.tags.status !== 'failure';

packages/integrations/src/transactionactivity.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,22 @@ export class TransactionActivity implements Integration {
214214
/**
215215
* Removes activity and finishes the span in case there is one
216216
*/
217-
public static popActivity(id: number): void {
217+
public static popActivity(id: number, spanData?: { [key: string]: any }): void {
218218
if (!TransactionActivity._isEnabled()) {
219219
// Tracing is not enabled
220220
return;
221221
}
222222

223223
const activity = TransactionActivity._activities[id];
224224
if (activity) {
225-
if (activity.span) {
226-
activity.span.finish();
225+
const span = activity.span;
226+
if (span) {
227+
if (spanData) {
228+
Object.keys(spanData).forEach((key: string) => {
229+
span.setData(key, spanData[key]);
230+
});
231+
}
232+
span.finish();
227233
}
228234
// tslint:disable-next-line: no-dynamic-delete
229235
delete TransactionActivity._activities[id];
@@ -247,7 +253,7 @@ export class TransactionActivity implements Integration {
247253
function xhrCallback(handlerData: { [key: string]: any }): void {
248254
// tslint:disable: no-unsafe-any
249255
if (handlerData.requestComplete && handlerData.xhr.__sentry_xhr_activity_id__) {
250-
TransactionActivity.popActivity(handlerData.xhr.__sentry_xhr_activity_id__);
256+
TransactionActivity.popActivity(handlerData.xhr.__sentry_xhr_activity_id__, handlerData.xhr.__sentry_xhr__);
251257
return;
252258
}
253259
// We only capture complete, non-sentry requests

packages/types/src/span.ts

+35
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,41 @@ export interface Span {
88
getTraceContext(): object;
99
/** Convert the object to JSON */
1010
toJSON(): object;
11+
12+
/**
13+
* Sets the tag attribute on the current span
14+
* @param key Tag key
15+
* @param value Tag value
16+
*/
17+
setTag(key: string, value: string): this;
18+
19+
/**
20+
* Sets the data attribute on the current span
21+
* @param key Data key
22+
* @param value Data value
23+
*/
24+
setData(key: string, value: any): this;
25+
26+
/**
27+
* Sets the data attribute on the current span
28+
* @param key Data key
29+
* @param value Data value
30+
*/
31+
setFailure(): this;
32+
33+
/**
34+
* Sets the data attribute on the current span
35+
* @param key Data key
36+
* @param value Data value
37+
*/
38+
setSuccess(): this;
39+
40+
/**
41+
* Sets the data attribute on the current span
42+
* @param key Data key
43+
* @param value Data value
44+
*/
45+
isSuccess(): boolean;
1146
}
1247

1348
/** Interface holder all properties that can be set on a Span on creation. */

0 commit comments

Comments
 (0)