Skip to content
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

feat(browser): Add http.response_delivery_type attribute to resource spans #14056

Merged
merged 5 commits into from
Oct 31, 2024

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Oct 23, 2024

This PR adds the deliveryType field of a ResourcePeformanceEntry to our resource spans. This attribute can give a definitive answer if a resource was retrieved from the browser cache or if the request was actually made to the resource src.

Unfortunately, deliveryType is not yet supported in all browsers but where it is, it should give us more reliable indicators of browser cache hits/misses.

The alternative way of checking for cache hits/misses (which is to check for transfer and decoded body sizes of a response) has a flaw: It only works for requests to 3rd party origins if that origin returns the Allow-Resource-Timing http header with a matching value. Otherwise, we can't determine the cache hit/miss status for 3rd party requests for certain.

One important thing: The deliveryType value indicating that a request was actually made (i.e. cache miss) is the empty string "". We adjusted Relay to forward empty string values (getsentry/relay#4174) to ensure this value is ingested correctly.

Idea for Product Improvement

Extracted to getsentry/sentry#79651

Copy link
Contributor

github-actions bot commented Oct 23, 2024

size-limit report 📦

Path Size % Change Change
@sentry/browser 22.74 KB - -
@sentry/browser - with treeshaking flags 21.53 KB - -
@sentry/browser (incl. Tracing) 35.14 KB +0.05% +17 B 🔺
@sentry/browser (incl. Tracing, Replay) 71.86 KB +0.03% +20 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 62.29 KB +0.03% +16 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 76.17 KB +0.03% +19 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 88.97 KB +0.03% +21 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback, metrics) 90.81 KB +0.02% +15 B 🔺
@sentry/browser (incl. metrics) 26.99 KB - -
@sentry/browser (incl. Feedback) 39.89 KB - -
@sentry/browser (incl. sendFeedback) 27.39 KB - -
@sentry/browser (incl. FeedbackAsync) 32.18 KB - -
@sentry/react 25.5 KB - -
@sentry/react (incl. Tracing) 38.1 KB +0.05% +16 B 🔺
@sentry/vue 26.89 KB - -
@sentry/vue (incl. Tracing) 37.02 KB +0.05% +16 B 🔺
@sentry/svelte 22.88 KB - -
CDN Bundle 24.1 KB - -
CDN Bundle (incl. Tracing) 36.96 KB +0.06% +21 B 🔺
CDN Bundle (incl. Tracing, Replay) 71.62 KB +0.03% +21 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 76.96 KB +0.03% +21 B 🔺
CDN Bundle - uncompressed 70.64 KB - -
CDN Bundle (incl. Tracing) - uncompressed 109.71 KB +0.07% +72 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 222.23 KB +0.04% +72 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 235.45 KB +0.03% +72 B 🔺
@sentry/nextjs (client) 38.18 KB +0.06% +21 B 🔺
@sentry/sveltekit (client) 35.75 KB +0.05% +16 B 🔺
@sentry/node 129.6 KB - -
@sentry/node - without tracing 94.3 KB - -
@sentry/aws-serverless 105.17 KB - -

View base workflow run

@Lms24 Lms24 self-assigned this Oct 23, 2024
@@ -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

Copy link
Member

@s1gr1d s1gr1d left a comment

Choose a reason for hiding this comment

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

Nice addition!

@@ -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

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

@Lms24
Copy link
Member Author

Lms24 commented Oct 24, 2024

Thx for the reviews! I added a comment in the code as to why I add default as a fallback value. However, I'm gonna hold off from merging this PR because it seems like empty string values should actually be allowed (at least during ingest). If it turns out we can fix this product-side, I'd like to avoid adding "default" but simply forward the empty string to stay consistent with what the browser hands to us.

@Lms24
Copy link
Member Author

Lms24 commented Oct 28, 2024

Gonna hold off from merging this until getsentry/relay#4174 is out. I think it's way better for us to forward the empty string value instead if "default", so it makes sense to wait on this.

@Lms24
Copy link
Member Author

Lms24 commented Oct 31, 2024

getsentry/relay#4174 is merged and deployed so we can merge this PR now 🎉

@Lms24 Lms24 enabled auto-merge (squash) October 31, 2024 11:37
@Lms24 Lms24 merged commit d2a9826 into develop Oct 31, 2024
148 checks passed
@Lms24 Lms24 deleted the lms/feat-resource-deliverytype branch October 31, 2024 11:46
alexandresoro pushed a commit to alexandresoro/ouca that referenced this pull request Nov 9, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@sentry/node](https://github.com/getsentry/sentry-javascript/tree/master/packages/node) ([source](https://github.com/getsentry/sentry-javascript)) | dependencies | minor | [`8.36.0` -> `8.37.1`](https://renovatebot.com/diffs/npm/@sentry%2fnode/8.36.0/8.37.1) |
| [@sentry/react](https://github.com/getsentry/sentry-javascript/tree/master/packages/react) ([source](https://github.com/getsentry/sentry-javascript)) | dependencies | minor | [`8.36.0` -> `8.37.1`](https://renovatebot.com/diffs/npm/@sentry%2freact/8.36.0/8.37.1) |

---

### Release Notes

<details>
<summary>getsentry/sentry-javascript (@&#8203;sentry/node)</summary>

### [`v8.37.1`](https://github.com/getsentry/sentry-javascript/blob/HEAD/CHANGELOG.md#8371)

[Compare Source](getsentry/sentry-javascript@8.37.0...8.37.1)

-   feat(deps): Bump [@&#8203;opentelemetry/instrumentation](https://github.com/opentelemetry/instrumentation) from 0.53.0 to 0.54.0 for [@&#8203;sentry/opentelemetry](https://github.com/sentry/opentelemetry) ([#&#8203;14187](getsentry/sentry-javascript#14187))

### [`v8.37.0`](https://github.com/getsentry/sentry-javascript/blob/HEAD/CHANGELOG.md#8370)

[Compare Source](getsentry/sentry-javascript@8.36.0...8.37.0)

##### Important Changes

-   **feat(nuxt): Add `piniaIntegration` ([#&#8203;14138](getsentry/sentry-javascript#14138

The Nuxt SDK now allows you to track Pinia state for captured errors. To enable the Pinia plugin, add the `piniaIntegration` to your client config:

```ts
// sentry.client.config.ts
import { usePinia } from '#imports';

Sentry.init({
  integrations: [
    Sentry.piniaIntegration(usePinia(), {
      /* optional Pinia plugin options */
    }),
  ],
});
```

-   **feat: Deprecate metrics API ([#&#8203;14157](getsentry/sentry-javascript#14157

The Sentry Metrics beta has ended in favour of revisiting metrics in another form at a later date.

This new approach will include different APIs, making the current metrics API unnecessary. This release
deprecates the metrics API with the plan to remove in the next SDK major version. If you currently use the
metrics API in your code, you can safely continue to do so but sent data will no longer be processed by Sentry.

[Learn more](https://sentry.zendesk.com/hc/en-us/articles/26369339769883-Metrics-Beta-Ended-on-October-7th) about the end of the Metrics beta.

##### Other Changes

-   feat(browser): Add `http.response_delivery_type` attribute to resource spans ([#&#8203;14056](getsentry/sentry-javascript#14056))
-   feat(browser): Add `skipBrowserExtensionCheck` escape hatch option ([#&#8203;14147](getsentry/sentry-javascript#14147))
-   feat(deps): Bump [@&#8203;opentelemetry/instrumentation](https://github.com/opentelemetry/instrumentation) from 0.53.0 to 0.54.0 ([#&#8203;14174](getsentry/sentry-javascript#14174))
-   feat(deps): Bump [@&#8203;opentelemetry/instrumentation-fastify](https://github.com/opentelemetry/instrumentation-fastify) from 0.40.0 to 0.41.0 ([#&#8203;14175](getsentry/sentry-javascript#14175))
-   feat(deps): Bump [@&#8203;opentelemetry/instrumentation-graphql](https://github.com/opentelemetry/instrumentation-graphql) from 0.43.0 to 0.44.0 ([#&#8203;14173](getsentry/sentry-javascript#14173))
-   feat(deps): Bump [@&#8203;opentelemetry/instrumentation-mongodb](https://github.com/opentelemetry/instrumentation-mongodb) from 0.47.0 to 0.48.0 ([#&#8203;14171](getsentry/sentry-javascript#14171))
-   feat(deps): Bump [@&#8203;opentelemetry/propagator-aws-xray](https://github.com/opentelemetry/propagator-aws-xray) from 1.25.1 to 1.26.0 ([#&#8203;14172](getsentry/sentry-javascript#14172))
-   feat(nuxt): Add `asyncFunctionReExports` to define re-exported server functions ([#&#8203;14104](getsentry/sentry-javascript#14104))
-   feat(nuxt): Add `piniaIntegration` ([#&#8203;14138](getsentry/sentry-javascript#14138))
-   fix(browser): Avoid recording long task spans starting before their parent span ([#&#8203;14183](getsentry/sentry-javascript#14183))
-   fix(core): Ensure errors thrown in async cron jobs bubble up ([#&#8203;14182](getsentry/sentry-javascript#14182))
-   fix(core): Silently fail `maybeInstrument` ([#&#8203;14140](getsentry/sentry-javascript#14140))
-   fix(nextjs): Resolve path for dynamic webpack import ([#&#8203;13751](getsentry/sentry-javascript#13751))
-   fix(node): Make sure `modulesIntegration` does not crash esm apps ([#&#8203;14169](getsentry/sentry-javascript#14169))

Work in this release was contributed by [@&#8203;rexxars](https://github.com/rexxars). Thank you for your contribution!

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4xNDIuNyIsInVwZGF0ZWRJblZlciI6IjM4LjE0Mi43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiXX0=-->

Reviewed-on: https://git.tristess.app/alexandresoro/ouca/pulls/299
Reviewed-by: Alexandre Soro <code@soro.dev>
Co-authored-by: renovate <renovate@git.tristess.app>
Co-committed-by: renovate <renovate@git.tristess.app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants