-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(core): Add scope attribute APIs #18165
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
Open
Lms24
wants to merge
7
commits into
develop
Choose a base branch
from
lms/feat-core-scope-setAttributes
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+488
−8
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0d59feb
feat(core): Add `Scope::SetAttribute(s)` APIs
Lms24 c94bcd6
add attributes.ts
Lms24 6fe4b81
add removeAttribute method
Lms24 db448cc
fix lint
Lms24 1bde956
fix size limit
Lms24 49182eb
fix remove scope listener test
Lms24 b360e4b
be extra careful with typed attribute values
Lms24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,108 @@ | ||
| export type Attributes = Record<string, TypedAttributeValue>; | ||
|
|
||
| export type AttributeValueType = string | number | boolean | Array<string> | Array<number> | Array<boolean>; | ||
|
|
||
| export type TypedAttributeValue = ( | ||
| | { | ||
| value: string; | ||
| type: 'string'; | ||
| } | ||
| | { | ||
| value: number; | ||
| type: 'integer'; | ||
| } | ||
| | { | ||
| value: number; | ||
| type: 'double'; | ||
| } | ||
| | { | ||
| value: boolean; | ||
| type: 'boolean'; | ||
| } | ||
| | { | ||
| value: Array<string>; | ||
| type: 'string[]'; | ||
| } | ||
| | { | ||
| value: Array<number>; | ||
| type: 'integer[]'; | ||
| } | ||
| | { | ||
| value: Array<number>; | ||
| type: 'double[]'; | ||
| } | ||
| | { | ||
| value: Array<boolean>; | ||
| type: 'boolean[]'; | ||
| } | ||
| ) & { unit?: Units }; | ||
|
|
||
| type Units = 'ms' | 's' | 'bytes' | 'count' | 'percent'; | ||
|
|
||
| /** | ||
| * Converts an attribute value to a typed attribute value. | ||
| * | ||
| * Does not allow mixed arrays. In case of a mixed array, the value is stringified and the type is 'string'. | ||
| * | ||
| * @param value - The value of the passed attribute. | ||
| * @returns The typed attribute. | ||
| */ | ||
| export function attributeValueToTypedAttributeValue(value: AttributeValueType): TypedAttributeValue { | ||
| switch (typeof value) { | ||
| case 'number': | ||
| if (Number.isInteger(value)) { | ||
| return { | ||
| value, | ||
| type: 'integer', | ||
| }; | ||
| } | ||
| return { | ||
| value, | ||
| type: 'double', | ||
| }; | ||
| case 'boolean': | ||
| return { | ||
| value, | ||
| type: 'boolean', | ||
| }; | ||
| case 'string': | ||
| return { | ||
| value, | ||
| type: 'string', | ||
| }; | ||
| } | ||
|
|
||
| if (Array.isArray(value)) { | ||
| if (value.every(item => typeof item === 'string')) { | ||
| return { | ||
| value, | ||
| type: 'string[]', | ||
| }; | ||
| } | ||
| if (value.every(item => typeof item === 'number')) { | ||
| if (value.every(item => Number.isInteger(item))) { | ||
| return { | ||
| value, | ||
| type: 'integer[]', | ||
| }; | ||
| } else if (value.every(item => !Number.isInteger(item))) { | ||
| return { | ||
| value, | ||
| type: 'double[]', | ||
| }; | ||
| } | ||
| } | ||
| if (value.every(item => typeof item === 'boolean')) { | ||
| return { | ||
| value, | ||
| type: 'boolean[]', | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| // Fallback: stringify the passed value | ||
| return { | ||
| value: JSON.stringify(value), | ||
| type: 'string', | ||
| }; | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In contrast to logs and metrics attribute definitions and helper functions, this one already handles array attributes. My thinking is, we introduce this here then unify logs, metrics (+ spans eventually) to use the types and APIs here. While we'll have to change the used types for logs and metrics, I don't think this is breaking as theoretically logs and metrics support subsets of the attribute value types specified here.