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: Capture request, response headers and body #9

Merged
merged 5 commits into from
Jun 5, 2024

Conversation

ernestii
Copy link

@ernestii ernestii commented May 29, 2024

  • test on android
  • test on ios

@ernestii ernestii requested a review from wrn14897 May 29, 2024 22:02
@ernestii ernestii force-pushed the ei/HDX-771-r branch 2 times, most recently from 17e67de to 06baa31 Compare May 29, 2024 22:33
const [key, value] = args;
const xhrMem = _xhrMem.get(this);
if (xhrMem && key && value) {
const newKey = `http.request.header.${key.toLowerCase()}`;

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

updated!

'http.request.body',
typeof requestBody === 'string'
? requestBody
: JSON.stringify(requestBody)

Choose a reason for hiding this comment

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

better to handle the case when stringify throws. also I wonder if we want to set a cap on body size ?

Copy link
Author

Choose a reason for hiding this comment

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

added!

@@ -753,7 +780,28 @@ export function instrumentXHR(config: XhrConfig) {
}
}
} else if (this.readyState === XMLHttpRequest.DONE) {
endSpan(EventNames.EVENT_READY_STATE_CHANGE, this);
if (config.networkBodyCapture && this.responseType === 'blob') {
try {

Choose a reason for hiding this comment

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

curious what this try-catch is for

Copy link
Author

Choose a reason for hiding this comment

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

probably leftover from experimenting, removed

@ernestii ernestii requested a review from wrn14897 May 31, 2024 19:23
currentSpan.setAttribute('http.response.body', text);
})
.finally(() => {
endSpan(EventNames.EVENT_READY_STATE_CHANGE, this);
Copy link

Choose a reason for hiding this comment

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

just double check. the span would never end before this ?

Copy link
Author

Choose a reason for hiding this comment

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

it shouldn't

Copy link

@wrn14897 wrn14897 left a comment

Choose a reason for hiding this comment

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

Super excited about this! 🚢 🚢 🚢

@@ -47,11 +47,14 @@ import type { PropagateTraceHeaderCorsUrls } from '@opentelemetry/sdk-trace-web/

const parseUrl = (url: string) => new URL(url);

const MAX_BODY_LENGTH = 5 * 1024; // 5KB
Copy link

Choose a reason for hiding this comment

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

5k seems a bit too strict. maybe something like 2MB to start with is okay

Copy link
Author

Choose a reason for hiding this comment

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

updated

@ernestii ernestii merged commit d549200 into release-next Jun 5, 2024
1 check passed
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.

2 participants