Skip to content

Commit

Permalink
Add http.response.status_code to span.data (#8366)
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich authored Jun 28, 2023
1 parent b3ee89e commit da295ff
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/core/src/tracing/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export class Span implements SpanInterface {
*/
public setHttpStatus(httpStatus: number): this {
this.setTag('http.status_code', String(httpStatus));
this.setData('http.response.status_code', httpStatus);
const spanStatus = spanStatusfromHttpCode(httpStatus);
if (spanStatus !== 'unknown_error') {
this.setStatus(spanStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ test('should correctly instrument `fetch` for performance tracing', async ({ pag
url: 'http://example.com',
type: 'fetch',
'http.response_content_length': expect.any(Number),
'http.response.status_code': 200,
},
description: 'GET http://example.com',
op: 'http.client',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ describe('CommonJS API Endpoints', () => {
op: 'http.server',
status: 'ok',
tags: { 'http.status_code': '200' },
data: {
'http.response.status_code': 200,
},
},
},
transaction: `GET ${unwrappedRoute}`,
Expand Down Expand Up @@ -51,6 +54,9 @@ describe('CommonJS API Endpoints', () => {
op: 'http.server',
status: 'ok',
tags: { 'http.status_code': '200' },
data: {
'http.response.status_code': 200,
},
},
},
transaction: `GET ${wrappedRoute}`,
Expand Down Expand Up @@ -84,6 +90,9 @@ describe('CommonJS API Endpoints', () => {
op: 'http.server',
status: 'ok',
tags: { 'http.status_code': '200' },
data: {
'http.response.status_code': 200,
},
},
},
transaction: `GET ${route}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ describe('Error API Endpoints', () => {
op: 'http.server',
status: 'internal_error',
tags: { 'http.status_code': '500' },
data: {
'http.response.status_code': 500,
},
},
},
transaction: 'GET /api/error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ describe('Tracing 200', () => {
op: 'http.server',
status: 'ok',
tags: { 'http.status_code': '200' },
data: {
'http.response.status_code': 200,
},
},
},
transaction: 'GET /api/users',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ describe('Tracing 500', () => {
op: 'http.server',
status: 'internal_error',
tags: { 'http.status_code': '500' },
data: {
'http.response.status_code': 500,
},
},
},
transaction: 'GET /api/broken',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ describe('Tracing HTTP', () => {
op: 'http.server',
status: 'ok',
tags: { 'http.status_code': '200' },
data: {
'http.response.status_code': 200,
},
},
},
spans: [
Expand All @@ -28,6 +31,9 @@ describe('Tracing HTTP', () => {
op: 'http.client',
status: 'ok',
tags: { 'http.status_code': '200' },
data: {
'http.response.status_code': 200,
},
},
],
transaction: 'GET /api/http',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test('should create and send transactions for Express routes and spans for middl
trace: {
data: {
url: '/test/express',
'http.response.status_code': 200,
},
op: 'http.server',
status: 'ok',
Expand Down Expand Up @@ -43,6 +44,7 @@ test('should set a correct transaction name for routes specified in RegEx', asyn
trace: {
data: {
url: '/test/regex',
'http.response.status_code': 200,
},
op: 'http.server',
status: 'ok',
Expand Down Expand Up @@ -71,6 +73,7 @@ test.each([['array1'], ['array5']])(
trace: {
data: {
url: `/test/${segment}`,
'http.response.status_code': 200,
},
op: 'http.server',
status: 'ok',
Expand Down Expand Up @@ -107,6 +110,7 @@ test.each([
trace: {
data: {
url: `/test/${segment}`,
'http.response.status_code': 200,
},
op: 'http.server',
status: 'ok',
Expand Down
1 change: 1 addition & 0 deletions packages/node/test/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ describe('tracingHandler', () => {
expect(finishTransaction).toHaveBeenCalled();
expect(transaction.status).toBe('ok');
expect(transaction.tags).toEqual(expect.objectContaining({ 'http.status_code': '200' }));
expect(transaction.data).toEqual(expect.objectContaining({ 'http.response.status_code': 200 }));
done();
});
});
Expand Down
16 changes: 8 additions & 8 deletions packages/node/test/integrations/undici.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ conditionalTest({ min: 16 })('Undici integration', () => {
{
description: 'GET http://localhost:18099/',
op: 'http.client',
data: {
data: expect.objectContaining({
'http.method': 'GET',
},
}),
},
],
[
Expand All @@ -68,10 +68,10 @@ conditionalTest({ min: 16 })('Undici integration', () => {
{
description: 'GET http://localhost:18099/',
op: 'http.client',
data: {
data: expect.objectContaining({
'http.method': 'GET',
'http.query': '?foo=bar',
},
}),
},
],
[
Expand All @@ -80,9 +80,9 @@ conditionalTest({ min: 16 })('Undici integration', () => {
{ method: 'POST' },
{
description: 'POST http://localhost:18099/',
data: {
data: expect.objectContaining({
'http.method': 'POST',
},
}),
},
],
[
Expand All @@ -91,9 +91,9 @@ conditionalTest({ min: 16 })('Undici integration', () => {
{ method: 'POST' },
{
description: 'POST http://localhost:18099/',
data: {
data: expect.objectContaining({
'http.method': 'POST',
},
}),
},
],
[
Expand Down
21 changes: 21 additions & 0 deletions packages/remix/test/integration/test/server/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
tags: {
'http.status_code': '500',
},
data: {
'http.response.status_code': 500,
},
},
},
});
Expand Down Expand Up @@ -160,6 +163,9 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
method: 'POST',
'http.status_code': '302',
},
data: {
'http.response.status_code': 302,
},
},
},
tags: {
Expand All @@ -176,6 +182,9 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
method: 'GET',
'http.status_code': '500',
},
data: {
'http.response.status_code': 500,
},
},
},
tags: {
Expand Down Expand Up @@ -226,6 +235,9 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
method: 'POST',
'http.status_code': '500',
},
data: {
'http.response.status_code': 500,
},
},
},
tags: {
Expand Down Expand Up @@ -276,6 +288,9 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
method: 'POST',
'http.status_code': '500',
},
data: {
'http.response.status_code': 500,
},
},
},
tags: {
Expand Down Expand Up @@ -326,6 +341,9 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
method: 'POST',
'http.status_code': '500',
},
data: {
'http.response.status_code': 500,
},
},
},
tags: {
Expand Down Expand Up @@ -376,6 +394,9 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
method: 'POST',
'http.status_code': '500',
},
data: {
'http.response.status_code': 500,
},
},
},
tags: {
Expand Down
9 changes: 9 additions & 0 deletions packages/remix/test/integration/test/server/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ describe.each(['builtin', 'express'])('Remix API Loaders with adapter = %s', ada
tags: {
'http.status_code': '500',
},
data: {
'http.response.status_code': 500,
},
},
},
});
Expand Down Expand Up @@ -97,6 +100,9 @@ describe.each(['builtin', 'express'])('Remix API Loaders with adapter = %s', ada
method: 'GET',
'http.status_code': '302',
},
data: {
'http.response.status_code': 302,
},
},
},
tags: {
Expand All @@ -113,6 +119,9 @@ describe.each(['builtin', 'express'])('Remix API Loaders with adapter = %s', ada
method: 'GET',
'http.status_code': '500',
},
data: {
'http.response.status_code': 500,
},
},
},
tags: {
Expand Down
1 change: 1 addition & 0 deletions packages/replay/test/fixtures/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function Transaction(traceId?: string, obj?: Partial<Event>): any {
method: 'GET',
url: '/api/0/projects/sentry-emerging-tech/billy-test/replays/c11bd625b0e14081a0827a22a0a9be4e/',
type: 'fetch',
'http.response.status_code': 200,
},
description: 'GET /api/0/projects/sentry-emerging-tech/billy-test/replays/c11bd625b0e14081a0827a22a0a9be4e/',
op: 'http.client',
Expand Down
1 change: 1 addition & 0 deletions packages/tracing/test/span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe('Span', () => {
span.setHttpStatus(404);
expect((span.getTraceContext() as any).status).toBe('not_found');
expect(span.tags['http.status_code']).toBe('404');
expect(span.data['http.response.status_code']).toBe(404);
});

test('isSuccess', () => {
Expand Down

0 comments on commit da295ff

Please sign in to comment.