Skip to content

fix: Dont require transaction to be on the scope to be delivered correctly #2353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Unreleased

Coming soon...
- [apm] fix: Always attach `contexts.trace` to finished transaction (#2353)

- [integrations] fix: Make RewriteFrame integration process all exceptions (#2362)

Expand Down
3 changes: 3 additions & 0 deletions packages/apm/src/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ export class Span implements SpanInterface, SpanContext {
}

return this._hub.captureEvent({
contexts: {
trace: this.getTraceContext(),
},
spans: finishedSpans,
start_timestamp: this.startTimestamp,
tags: this.tags,
Expand Down
27 changes: 22 additions & 5 deletions packages/apm/test/span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,31 +164,48 @@ describe('Span', () => {
expect(span.timestamp).toBeGreaterThan(1);
});

test('finish a scope span without transaction', () => {
test('finish a span without transaction', () => {
const spy = jest.spyOn(hub as any, 'captureEvent');
const span = new Span({}, hub);
span.finish();
expect(spy).not.toHaveBeenCalled();
});

test('finish a scope span with transaction', () => {
test('finish a span with transaction', () => {
const spy = jest.spyOn(hub as any, 'captureEvent') as any;
const span = new Span({ transaction: 'test', sampled: false }, hub);
span.initFinishedSpans();
span.finish();
expect(spy).toHaveBeenCalled();
expect(spy.mock.calls[0][0].spans).toHaveLength(0);
expect(spy.mock.calls[0][0].contexts.trace).toEqual(span.getTraceContext());
});

test('finish a scope span with transaction + child span', () => {
test('finish a span with transaction + child span', () => {
const spy = jest.spyOn(hub as any, 'captureEvent') as any;
const parentSpan = new Span({ transaction: 'test', sampled: false }, hub);
parentSpan.initFinishedSpans();
const childSpan = parentSpan.child();
childSpan.finish();
parentSpan.finish();
expect(spy).toHaveBeenCalled();
expect(spy.mock.calls[0][0].spans).toHaveLength(1);
expect(spy.mock.calls[0][0].contexts.trace).toEqual(parentSpan.getTraceContext());
});

test('finish a span with another one on the scope shouldnt override contexts.trace', () => {
const spy = jest.spyOn(hub as any, 'captureEvent') as any;

const spanOne = new Span({ transaction: 'testOne', sampled: false }, hub);
spanOne.initFinishedSpans();
const childSpanOne = spanOne.child();
childSpanOne.finish();
hub.configureScope((scope) => { scope.setSpan(spanOne) })

const spanTwo = new Span({ transaction: 'testTwo', sampled: false }, hub);
spanTwo.initFinishedSpans();
spanTwo.finish();

expect(spy.mock.calls[0][0].spans).toHaveLength(0);
expect(spy.mock.calls[0][0].contexts.trace).toEqual(spanTwo.getTraceContext());
});
});

Expand Down
4 changes: 0 additions & 4 deletions packages/hub/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,6 @@ export class Scope implements ScopeInterface {
if (this._transaction) {
event.transaction = this._transaction;
}
if (this._span) {
event.contexts = event.contexts || {};
event.contexts.trace = this._span.getTraceContext();
}

this._applyFingerprint(event);

Expand Down