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: Custom User-Agent strings #221

Closed
wants to merge 1 commit into from
Closed

feat: Custom User-Agent strings #221

wants to merge 1 commit into from

Conversation

gkats
Copy link
Member

@gkats gkats commented Feb 6, 2024

Added a new configuration option for our Backend so that users can specify a suffix for the User-Agent string that's included in every request headers.

Added a new configuration option for our Backend so that users can
specify a suffix for the User-Agent string that's included in every
request headers.
@gkats gkats requested a review from a team as a code owner February 6, 2024 17:54
@@ -219,7 +224,11 @@ func (b *defaultBackend) newRequest(ctx context.Context, apiReq *APIRequest) (*h
}
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", secretKey))
req.Header.Add("Content-Type", "application/json")
req.Header.Add("User-Agent", fmt.Sprintf("Clerk/%s SDK-Go/%s", clerkAPIVersion, sdkVersion))
userAgent := fmt.Sprintf("Clerk/%s SDK-Go/%s", clerkAPIVersion, sdkVersion)
Copy link
Contributor

Choose a reason for hiding this comment

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

ℹ️ Just mentioning that Cloudflare analytics group by user agent, but I guess we can always filter by prefix!

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I didn't know that. Do you think it's better to drop this change.

An alternative solution would be to leave the User-Agent string as is and maybe send a custom header instead. Would that be better?

Copy link
Member

Choose a reason for hiding this comment

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

@georgepsarakis Can't we just use the X-Clerk-SDK header?

Copy link
Member Author

Choose a reason for hiding this comment

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

The X-Clerk-SDK is already used, but we could add another one for debugging purposes, or to uniquely identify a consumer, like one of our partners or us.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, what I had in mind was to let the user set the User-Agent to whatever, not just the suffix, and rely on the X-Clerk-SDK for wherever we need to identify if it came from the SDK.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. That could work. However, I think we should have control over the User-Agent header, since it's a "standard" header but be loose in what we accept for custom ones.

Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit skeptical of this capability in general. Feels a bit weird to want to hijack the user agent header of an SDK. Do we have any requests about this? If not, then I'd go for what you proposed here @gkats:

An alternative solution would be to leave the User-Agent string as is and maybe send a custom header instead.

i.e., let the user add whatever extra headers they want in their requests.

Copy link
Contributor

Choose a reason for hiding this comment

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

@agis we are following this approach in for BAPI requests by setting the request user-agent to {packageName}@{packageVersion}.

ref: https://github.com/clerk/javascript/blob/main/packages/backend/src/constants.ts#L4

Copy link
Member Author

Choose a reason for hiding this comment

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

Here's an alternative, which uses a custom header. #252

clerk_test.go Show resolved Hide resolved
@gkats
Copy link
Member Author

gkats commented Feb 7, 2024

Closing this PR in favor of a solution which adds a custom header.

@gkats gkats closed this Feb 7, 2024
@gkats gkats deleted the core-1641-user-agent branch February 7, 2024 14:23
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.

5 participants