-
Notifications
You must be signed in to change notification settings - Fork 821
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tracing): support for truncation of span attribute values
- Loading branch information
1 parent
46f31dd
commit 139bfcc
Showing
7 changed files
with
208 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,47 @@ export function isAttributeValue(val: unknown): val is AttributeValue { | |
return isValidPrimitiveAttributeValue(val); | ||
} | ||
|
||
export function truncateValueIfTooLong( | ||
value: AttributeValue, | ||
limit: number | null, | ||
truncationWarningCallback = () => {} | ||
): AttributeValue { | ||
if (limit === null) { | ||
return value; | ||
} | ||
|
||
if (limit < 32) { | ||
throw new Error('Value size limit cannot be lower than 32.'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jtmalinowski
Author
Contributor
|
||
} | ||
|
||
if (typeof value === 'boolean' || typeof value === 'number') { | ||
// these types can't exceed the attribute value size limit | ||
return value; | ||
} | ||
|
||
if (Array.isArray(value)) { | ||
// note: this is potentially incompatible with a given exporter | ||
const serialized = JSON.stringify(value); | ||
|
||
if (serialized.length > limit) { | ||
return truncateValueIfTooLong( | ||
serialized, | ||
limit, | ||
truncationWarningCallback | ||
); | ||
} | ||
|
||
return value; | ||
} | ||
|
||
if (value.length > limit) { | ||
truncationWarningCallback(); | ||
return value.substring(0, limit); | ||
} | ||
|
||
return value; | ||
} | ||
|
||
function isHomogeneousAttributeValueArray(arr: unknown[]): boolean { | ||
let type: string | undefined; | ||
|
||
|
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
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
Why such limit, is there a spec which forces that ?,
Besides that Api cannot throw any error that could break the user app