Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
async function run() {
Sentry.startSpan({ name: 'parent_span' }, () => {
Sentry.startSpan({ name: 'child_span', attributes: { someAttribute: '' } }, () => {
// whatever a user would do here
});
});
}

(async () => {
await run();
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect } from '@playwright/test';

import { sentryTest } from '../../../../utils/fixtures';
import {
envelopeRequestParser,
shouldSkipTracingTest,
waitForTransactionRequestOnUrl,
} from '../../../../utils/helpers';

sentryTest('sends an empty string attribute', async ({ getLocalTestPath, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}

const url = await getLocalTestPath({ testDir: __dirname });
const req = await waitForTransactionRequestOnUrl(page, url);
const transaction = envelopeRequestParser(req);

const childSpan = transaction.spans?.[0];
expect(childSpan?.data?.someAttribute).toBe('');
});
5 changes: 5 additions & 0 deletions packages/browser-utils/src/metrics/browserMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ export interface ResourceEntry extends Record<string, unknown> {
encodedBodySize?: number;
decodedBodySize?: number;
renderBlockingStatus?: string;
deliveryType?: string;
}

/** Create resource-related spans */
Expand All @@ -539,6 +540,10 @@ export function _addResourceSpans(
setResourceEntrySizeData(attributes, entry, 'encodedBodySize', 'http.response_content_length');
setResourceEntrySizeData(attributes, entry, 'decodedBodySize', 'http.decoded_response_content_length');

if (entry.deliveryType != null) {
attributes['http.response_delivery_type'] = entry.deliveryType || 'default';
Copy link
Member Author

@Lms24 Lms24 Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm falling back to "default" here because it seems like we drop attributes with empty string values (which is the actual default of the property) during ingest. Ideally we wouldn't need to do this but I don't see a better way at the moment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an explaining comment to the code why this is needed

}

if ('renderBlockingStatus' in entry) {
attributes['resource.render_blocking_status'] = entry.renderBlockingStatus;
}
Expand Down
47 changes: 47 additions & 0 deletions packages/browser-utils/test/browser/browserMetrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,53 @@ describe('_addResourceSpans', () => {
}),
);
});

// resource delivery types: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/deliveryType
// i.e. better but not yet widely supported way to check for browser cache hit
it.each(['cache', 'navigational-prefetch'])(
'attaches delivery type ("%s") to resource spans if available',
deliveryType => {
const spans: Span[] = [];

getClient()?.on('spanEnd', span => {
spans.push(span);
});

const entry: ResourceEntry = {
initiatorType: 'css',
transferSize: 0,
encodedBodySize: 0,
decodedBodySize: 0,
deliveryType,
};

_addResourceSpans(span, entry, resourceEntryName, 100, 23, 345);

expect(spans).toHaveLength(1);
expect(spanToJSON(spans[0]!).data).toMatchObject({ 'http.response_delivery_type': deliveryType });
},
);

it('attaches "default" as delivery if the empty string ("") default value is set', () => {
const spans: Span[] = [];

getClient()?.on('spanEnd', span => {
spans.push(span);
});

const entry: ResourceEntry = {
initiatorType: 'css',
transferSize: 0,
encodedBodySize: 0,
decodedBodySize: 0,
deliveryType: '',
};

_addResourceSpans(span, entry, resourceEntryName, 100, 23, 345);

expect(spans).toHaveLength(1);
expect(spanToJSON(spans[0]!).data).toMatchObject({ 'http.response_delivery_type': 'default' });
});
});

const setGlobalLocation = (location: Location) => {
Expand Down
Loading