-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(perf): Requests module SDK instrumentation documentation (#9963)
* Link to custom instrumentation docs * Add JavaScript platform docs * Add Python platform docs --------- Co-authored-by: Liza Mock <liza.mock@sentry.io>
- Loading branch information
1 parent
2ecc9a4
commit 3dfba33
Showing
3 changed files
with
102 additions
and
11 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
docs/platforms/javascript/common/performance/instrumentation/requests-module.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: Custom Instrumentation for Requests Module | ||
sidebar_order: 9999 | ||
description: "Learn how to manually instrument your code to use Sentry's Requests module." | ||
--- | ||
|
||
As a prerequisite to setting up [Requests](/product/performance/requests/), you’ll need to first <PlatformLink to="/performance/">set up performance monitoring</PlatformLink>. Once this is done, the JavaScript SDK will automatically instrument outgoing HTTP requests. If that doesn't fit your use case, you can set up using [custom instrumentation](#custom-instrumentation). | ||
|
||
## Custom Instrumentation | ||
|
||
For detailed information about which data can be set, see the [Requests Module developer specifications](https://develop.sentry.dev/sdk/performance/modules/requests/). | ||
|
||
### Initialize Sentry | ||
|
||
<PlatformContent includePath="getting-started-config" /> | ||
|
||
### Wrap The HTTP Requests in a Span | ||
|
||
NOTE: Refer to [HTTP Span Data Conventions](https://develop.sentry.dev/sdk/performance/span-data-conventions/#http) for a full list of the span data attributes. | ||
|
||
Here is an example of an instrumented function that makes HTTP requests: | ||
|
||
```javascript | ||
async function makeRequest(method, url) { | ||
return await Sentry.startSpan( | ||
{op: 'http.client', name: `${method} ${url}`}, | ||
async span => { | ||
const parsedURL = new URL(url, location.origin); | ||
|
||
const response = await fetch(url, { | ||
method, | ||
}); | ||
|
||
span?.setAttribute('http.request.method', method); | ||
|
||
span?.setAttribute('server.address', parsedURL.hostname); | ||
span?.setAttribute('server.port', parsedURL.port || undefined); | ||
|
||
span?.setAttribute('http.response.status_code', response.status); | ||
span?.setAttribute( | ||
'http.response_content_length', | ||
Number(response.headers.get('content-length')) | ||
); | ||
|
||
// A good place to set other span attributes | ||
|
||
return response; | ||
} | ||
); | ||
} | ||
``` |
49 changes: 49 additions & 0 deletions
49
docs/platforms/python/performance/instrumentation/requests-module.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: Custom Instrumentation for Requests Module | ||
sidebar_order: 9999 | ||
description: "Learn how to manually instrument your code to use Sentry's Requests module." | ||
--- | ||
|
||
As a prerequisite to setting up [Requests](/product/performance/requests/), you’ll need to first <PlatformLink to="/performance/">set up performance monitoring</PlatformLink>. Once this is done, the Python SDK will automatically instrument outgoing HTTP requests made via `HTTPConnection`. If that doesn't fit your use case, you can set up using [custom instrumentation](#custom-instrumentation). | ||
|
||
## Custom Instrumentation | ||
|
||
For detailed information about which data can be set, see the [Requests Module developer specifications](https://develop.sentry.dev/sdk/performance/modules/requests/). | ||
|
||
### Initialize Sentry | ||
|
||
<PlatformContent includePath="getting-started-config" /> | ||
|
||
### Wrap The HTTP Requests in a Span | ||
|
||
NOTE: Refer to [HTTP Span Data Conventions](https://develop.sentry.dev/sdk/performance/span-data-conventions/#http) for a full list of the span data attributes. | ||
|
||
Here is an example of an instrumented function that makes HTTP requests: | ||
|
||
```python | ||
from urllib.parse import urlparse | ||
import requests | ||
|
||
def make_request(method, url): | ||
span = sentry_sdk.start_span( | ||
op="http.client", | ||
description="%s %s" % (method, url), | ||
) | ||
|
||
span.set_data("http.request.method", method) | ||
|
||
parsed_url = urlparse(url) | ||
span.set_data("url", url) | ||
span.set_data("server.address", parsed_url.hostname) | ||
span.set_data("server.port", parsed_url.port) | ||
|
||
response = requests.request(method=method, url=url) | ||
|
||
span.set_data("http.response.status_code", response.status_code) | ||
span.set_data("http.response_content_length", response.headers["content-length"]) | ||
|
||
span.finish() | ||
|
||
return response | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters