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

chore: Add http requests to custom instrumentation #12258

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

tommasini
Copy link
Contributor

@tommasini tommasini commented Nov 12, 2024

Description

This PR adds custom instrumentation for http requests.

performance e2e: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/17c729b7-7979-4d02-bc56-de709b38bac8?tab=workflows

Android QA: https://app.bitrise.io/build/fbbcf003-58c5-4771-bfef-391f8e8cc84d?tab=log

Related issues

Fixes:

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

IOS:
image

Android:
image

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@tommasini tommasini added needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) Run Smoke E2E Triggers smoke e2e on Bitrise team-tiger Tiger team (for tech debt reduction + performance improvements) labels Nov 12, 2024
@tommasini tommasini requested a review from a team as a code owner November 12, 2024 13:06
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

Copy link
Contributor

github-actions bot commented Nov 12, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 5398f3e
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/c9754da4-3f45-4c8b-996e-9fcfc3e4e128

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@MajorLift
Copy link
Contributor

MajorLift commented Nov 12, 2024

  • How would you feel about including the full url in the name like the automatically-generated spans, and then adding the hostname as a tag? That way we can filter by hostname without losing extra information about endpoints and query strings.

  • Also, regarding span operation names, Sentry recommends the following:

Sentry maintains a list of well known span operations and it is recommended that you use one of those operations if it is applicable to your span.
https://docs.sentry.io/platforms/react-native/tracing/instrumentation/custom-instrumentation/#adding-span-operations-op

Taking that into consideration, how about e.g. http.client and http.client.no_basic_functionality for the trace operation names? Prepending those with custom. also seems reasonable if it's more readable for the team.

  • We could also automatically attach additional information about each request using the span.setAttribute() method as seen here:

https://docs.sentry.io/platforms/javascript/tracing/instrumentation/custom-instrumentation/requests-module/#wrap-http-requests-in-a-span

Edit: The code snippet above stores the hostname as the server.address attribute, so looks like we wouldn't need to use a tag for that.

@tommasini
Copy link
Contributor Author

Hey @MajorLift , loved your review! More curious to understand how would we use the span.setAttribute in this scenario

I added the operations name suggestion I think it makes super sense!

@tommasini tommasini marked this pull request as ready for review November 12, 2024 20:47
@tommasini tommasini added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Nov 12, 2024
Copy link
Contributor

github-actions bot commented Nov 12, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: e627d42
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/6d15a23a-4fba-4ad8-b514-70f25b1dc53f

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@tommasini tommasini changed the title chore: Add custom instrumentation to hostnames chore: Add http requests to custom instrumentation Nov 12, 2024
Cal-L
Cal-L previously approved these changes Nov 12, 2024
Copy link
Contributor

@Cal-L Cal-L left a comment

Choose a reason for hiding this comment

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

LGTM

@Cal-L
Copy link
Contributor

Cal-L commented Nov 12, 2024

I agree with showing the full url

MarioAslau
MarioAslau previously approved these changes Nov 13, 2024
Copy link
Contributor

@MarioAslau MarioAslau left a comment

Choose a reason for hiding this comment

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

Looks great @tommasini ! 🎉

@MajorLift
Copy link
Contributor

I did some digging on setAttribute, and looks like Attributes replace Tags in Sentry v8. Tags are now only supposed to be attached to scopes and not spans.

Previously, the model had the concepts of Data, Tags, and Context, which could be used for different things. However, this had two main downsides: Firstly, it was not always clear which concept should be used in a given situation. Secondly, these concepts were not displayed the same way for transactions or spans.

To address these issues, the new model only has Attributes that can be set on spans. Broadly speaking, they map to what was formerly known as Data.

If you still really need to set tags or context, you can do so on the scope before starting a span

https://docs.sentry.io/platforms/javascript/migration/v7-to-v8/v8-new-performance-api/#attributes-vs-data-vs-tags-vs-context

This explains why the Sentry.Span interface doesn't have a setTag method in extension, which is on v8.

Mobile @sentry/types is v7, while @sentry/react-native is on the latest major version. I'm not sure whether this is a hard breaking change, but it looks like we'll have to move away from using tags eventually.

@tommasini
Copy link
Contributor Author

I believe the reason why we move tags until now, is because they are queryable on dashboards, nevertheless, I'm not 100% sure of this, will need to re-check!

@MajorLift
Copy link
Contributor

MajorLift commented Nov 13, 2024

Edit: There is no need to switch to Attributes in this PR. Both extension and mobile are set up to attach Tags to Scopes. We can keep using that set-up for the time being.

I believe the reason why we move tags until now, is because they are queryable on dashboards,

It would appear that Attributes are a full replacement for Tags, meaning they should also be searchable. The docs don't seem fully updated on that point, though.

But more importantly, the migration guide seems to show span.tags and span.setTag as being removed from the Span schema, which would force us to make the switch.

https://docs.sentry.io/platforms/javascript/migration/v7-to-v8/v8-new-performance-api/#the-span-schema

There's also a functional benefit to switching:

Tags over the 200 character limit will become truncated, losing potentially important information.

Instead of using tags, it is recommended to add data to spans as attributes. Using span.setAttribute() allows to add data with arbitrary length to a span. You can add as many attributes to your span as you want.

https://docs.sentry.io/platforms/javascript/tracing/troubleshooting/#control-data-truncation

@tommasini tommasini removed the Run Smoke E2E Triggers smoke e2e on Bitrise label Nov 13, 2024
@tommasini tommasini added the Run Smoke E2E Triggers smoke e2e on Bitrise label Nov 13, 2024
Copy link

sonarcloud bot commented Nov 13, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) Run Smoke E2E Triggers smoke e2e on Bitrise team-mobile-platform team-tiger Tiger team (for tech debt reduction + performance improvements)
Projects
Status: Review finalised - Ready to be merged
Development

Successfully merging this pull request may close these issues.

5 participants