-
-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: resolve useragent source and add as source label to metrics (#7883
- Loading branch information
Showing
6 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
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
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
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,29 @@ | ||
import { determineIntegrationSource } from './integration-headers'; | ||
|
||
test('resolves known user agents to source labels', () => { | ||
expect(determineIntegrationSource('axios/0.27.2')).toBe('Axios'); | ||
expect(determineIntegrationSource('axios/1.4.0')).toBe('Axios'); | ||
expect(determineIntegrationSource('curl/8.6.0')).toBe('Curl'); | ||
expect(determineIntegrationSource('node-fetch/1.0.0')).toBe('Node'); | ||
expect(determineIntegrationSource('node')).toBe('Node'); | ||
expect(determineIntegrationSource('python-requests/2.31.0')).toBe('Python'); | ||
expect(determineIntegrationSource('Terraform-Provider-Unleash/1.1.1')).toBe( | ||
'TerraformUnleash', | ||
); | ||
expect(determineIntegrationSource('Jira-Cloud-Unleash')).toBe( | ||
'JiraCloudUnleash', | ||
); | ||
expect(determineIntegrationSource('OpenAPI-Generator/1.0.0/go')).toBe( | ||
'OpenAPIGO', | ||
); | ||
expect( | ||
determineIntegrationSource('Apache-HttpClient/4.5.13 (Java/11.0.22)'), | ||
).toBe('Java'); | ||
expect(determineIntegrationSource('Go-http-client/1.1')).toBe('Go'); | ||
expect( | ||
determineIntegrationSource( | ||
'rest-client/2.0.2 (linux-gnu x86_64) ruby/2.1.7p400', | ||
), | ||
).toBe('RestClientRuby'); | ||
expect(determineIntegrationSource('No-http-client')).toBe('Other'); | ||
}); |
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,34 @@ | ||
import type { Request } from 'express'; | ||
|
||
const ORIGIN = 'origin'; | ||
const httpMatcher = /^https?:\/\//; | ||
const userAgentMatches = [ | ||
{ label: 'Axios', matcher: /^axios/ }, | ||
{ label: 'Curl', matcher: /^curl/ }, | ||
{ label: 'Go', matcher: /^Go-http-client/ }, | ||
{ label: 'Python', matcher: /^python-requests/ }, | ||
{ label: 'Node', matcher: /^node/ }, | ||
{ label: 'Java', matcher: /^Apache-HttpClient.*Java/ }, | ||
{ label: 'JiraCloudUnleash', matcher: /^Jira-Cloud-Unleash/ }, | ||
{ label: 'TerraformUnleash', matcher: /^Terraform-Provider-Unleash/ }, | ||
{ label: 'OpenAPIGO', matcher: /^OpenAPI-Generator\/.*\/go/ }, | ||
{ label: 'RestClientRuby', matcher: /^rest-client\/.*ruby/ }, | ||
]; | ||
|
||
export const getFilteredOrigin = (request: Request): string | undefined => { | ||
const origin = request.headers[ORIGIN]; | ||
if (origin && httpMatcher.test(origin)) { | ||
return origin; | ||
} | ||
|
||
return undefined; | ||
}; | ||
|
||
export const determineIntegrationSource = ( | ||
userAgent: string, | ||
): string | undefined => { | ||
return ( | ||
userAgentMatches.find((candidate) => candidate.matcher.test(userAgent)) | ||
?.label ?? 'Other' | ||
); | ||
}; |
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
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