-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(google-cloud-serverless)!: Use http.client span op for GCP HTTP requests
#22660
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| import type * as common from '@google-cloud/common'; | ||
| import { HTTP_REQUEST_METHOD, SENTRY_OP, SERVER_ADDRESS, URL_FULL } from '@sentry/conventions/attributes'; | ||
| import { WEB_SERVER_HTTP_CLIENT_SPAN_OP } from '@sentry/conventions/op'; | ||
| import type { Client, IntegrationFn } from '@sentry/core'; | ||
| import { | ||
| defineIntegration, | ||
| fill, | ||
| getClient, | ||
| isURLObjectRelative, | ||
| parseStringToURLObject, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, | ||
| SentryNonRecordingSpan, | ||
| } from '@sentry/core'; | ||
|
|
@@ -54,9 +58,12 @@ function wrapRequestFunction(orig: RequestFunction): RequestFunction { | |
| ? startInactiveSpan({ | ||
| name: `${httpMethod} ${reqOpts.uri}`, | ||
| onlyIfParent: true, | ||
| op: `http.client.${identifyService(this.apiEndpoint)}`, | ||
| attributes: { | ||
| [SENTRY_OP]: WEB_SERVER_HTTP_CLIENT_SPAN_OP, | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.serverless', | ||
| [HTTP_REQUEST_METHOD]: httpMethod, | ||
| [SERVER_ADDRESS]: getServerAddress(this.apiEndpoint), | ||
| [URL_FULL]: reqOpts.uri, | ||
|
msonnb marked this conversation as resolved.
msonnb marked this conversation as resolved.
|
||
| }, | ||
| }) | ||
| : new SentryNonRecordingSpan(); | ||
|
|
@@ -67,8 +74,8 @@ function wrapRequestFunction(orig: RequestFunction): RequestFunction { | |
| }; | ||
| } | ||
|
|
||
| /** Identifies service by its base url */ | ||
| function identifyService(apiEndpoint: string): string { | ||
| const match = apiEndpoint.match(/^https:\/\/(\w+)\.googleapis.com$/); | ||
| return match?.[1] || apiEndpoint.replace(/^(http|https)?:\/\//, ''); | ||
| /** Extracts the host of the API endpoint the request is sent to */ | ||
| function getServerAddress(apiEndpoint: string): string { | ||
| const url = parseStringToURLObject(apiEndpoint); | ||
| return url && !isURLObjectRelative(url) ? url.host : apiEndpoint; | ||
|
Comment on lines
+78
to
+80
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The code uses Suggested FixTo ensure compliance with OpenTelemetry conventions and maintain consistency within the codebase, change Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.