fix(sentry_webhook): convert OS values to allowed picklist values (#1467)

* fix(sentry_webhook): convert OS values to allowed picklist values

* Make `Linux` the fallback.
This commit is contained in:
Sander Bruens 2024-01-04 10:40:18 -05:00 committed by GitHub
parent 90e8e57b3f
commit 6c433ed6fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View file

@ -92,7 +92,7 @@ describe('postSentryEventToSalesforce', () => {
message: 'my message',
tags: [
['category', 'test category'],
['os.name', 'test os'],
['os.name', 'Mac OS X'],
['sentry:release', 'test version'],
['unknown:tag', 'foo'],
],
@ -109,7 +109,7 @@ describe('postSentryEventToSalesforce', () => {
'&description=my%20message' +
'&type=Outline%20client' +
'&00N0b00000BqOA2=test%20category' +
'&00N0b00000BqOfW=test%20os' +
'&00N0b00000BqOfW=macOs' +
'&00N0b00000BqOfR=test%20version'
);
expect(mockRequest.end).toHaveBeenCalled();

View file

@ -142,7 +142,7 @@ function getSalesforceFormData(
if (event.tags) {
const tags = new Map<string, string>(event.tags);
form.push(encodeFormData(formFields.category, tags.get('category')));
form.push(encodeFormData(formFields.os, tags.get('os.name')));
form.push(encodeFormData(formFields.os, toOSPicklistValue(tags.get('os.name'))));
form.push(encodeFormData(formFields.version, tags.get('sentry:release')));
if (!isClient) {
form.push(encodeFormData(formFields.cloudProvider, tags.get('cloudProvider')));
@ -151,6 +151,29 @@ function getSalesforceFormData(
return form.join('&');
}
// Returns a picklist value that is allowed by SalesForce for the OS record.
function toOSPicklistValue(value: string | undefined): string | undefined {
if (!value) {
console.warn('No OS found');
return undefined;
}
const normalizedValue = value.toLowerCase();
if (normalizedValue.includes('android')) {
return 'Android';
}
if (normalizedValue.includes('ios')) {
return 'iOS';
}
if (normalizedValue.includes('windows')) {
return 'Windows';
}
if (normalizedValue.includes('mac')) {
return 'macOs';
}
return 'Linux';
}
function encodeFormData(field: string, value?: string) {
return `${encodeURIComponent(field)}=${encodeURIComponent(value || '')}`;
}