-
Notifications
You must be signed in to change notification settings - Fork 821
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(opentelemetry-sdk-trace-base): implemented option to limit length of values of attributes #2418
feat(opentelemetry-sdk-trace-base): implemented option to limit length of values of attributes #2418
Conversation
…th of values of attributes Signed-off-by: Banothu Ramesh Naik <[email protected]>
|
Codecov Report
@@ Coverage Diff @@
## main #2418 +/- ##
==========================================
+ Coverage 92.14% 92.68% +0.53%
==========================================
Files 120 137 +17
Lines 3998 4990 +992
Branches 844 1054 +210
==========================================
+ Hits 3684 4625 +941
- Misses 314 365 +51
|
* @returns truncated attribute value if required, otherwise same value | ||
*/ | ||
private _truncateToSize(value?: SpanAttributeValue): SpanAttributeValue | undefined { | ||
const limit = this._spanLimits.attributeValueLengthLimit! |
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.
Why is the !
assertion needed here?
|
||
// Check type of values | ||
// Allowed types are string, array of strings | ||
if (value == null || (typeof value != 'string' && !Array.isArray(value))) { |
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.
This will already fall through to the return at the end
if (value == null || (typeof value != 'string' && !Array.isArray(value))) { | |
if (value == null) { |
…ovements Signed-off-by: Banothu Ramesh Naik <[email protected]>
} | ||
|
||
// Array of strings | ||
if (this._isArrayOfStrings(value)) { |
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.
spec doesn't allow to have array of different type. Imagine the situation when you have 1k of attributes and only one is a number and the rest will still be string. From a user perspective I would assume that all 999 attributes should be truncated and the rest not. Having this both things in mind I would get rid of function _isArrayOfStrings
and would simply do.
return (value as []).map(val => {
typeof val === 'string' ? this._truncateToLimitUtil(val, limit)) : val;
}
This way code will not break and the attributes that can be limited will be limited.
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.
I implemented the same way at the first glance.
but later added array of strings check since spec here specially says apply these truncate only for strings
and array of strings
otherwise ignore.
Let me change back as you mentioned.
const limit = this._spanLimits.attributeValueLengthLimit; | ||
// Check limit | ||
// undefined limit means do not truncate | ||
if (typeof limit != 'number' || limit <= 0) { |
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.
please use strict typing
if (typeof limit != 'number' || limit <= 0) { | |
if (typeof limit !== 'number' || limit <= 0) { |
or even do
if (!(limit > 0))
?
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.
OT: Why is lint not complaining about this?
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.
that's a good question, maybe some rule is missing, as some time ago we updated lint, wondering if that was on purpose then or it was missed.
attributeCountLimit: 100, | ||
eventCountLimit: 128, | ||
linkCountLimit: 128, | ||
}); | ||
}); | ||
|
||
it('should construct an instance with customized attributeValueLengthLimit span limits', () => { |
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.
I'm having difficulties with understanding this description and what is happening here, consider this
it('should construct an instance with customized attributeValueLengthLimit span limits', () => { | |
// earlier | |
describe('"spanLimits"', ()=> { | |
... | |
describe('when "attributeValueLengthLimit" is defined', ()=> { | |
it('should truncate value which length exceeds this limit', () => { | |
}); | |
}); | |
describe('when "attributeCountLimit" is defined', ()=> { | |
it('should remove / drop all remaining values after the number of values exceeds this limit, () => { | |
}); | |
} | |
// etc. etc. just use more natural language to describe it with 'when' -> 'then' approach | |
.... |
WDYT ?
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.
Yes, I agree. It's adds better readability also 👍
I followed existing code test cases pattern since its my first contribution to open source
I will make changes here
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.
@obecny I made test cases as you mentioned.
Signed-off-by: Banothu Ramesh Naik <[email protected]>
Signed-off-by: Banothu Ramesh Naik <[email protected]>
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.
lgtm, thx for changing tests it is much readable now :)
span.setAttribute('array<string>', ['str1', 'str2']); | ||
span.setAttribute('array<number>', [1, 2]); | ||
span.setAttribute('array<bool>', [true, false]); | ||
it('should able to overwrite attributes', () => { |
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.
?
it('should able to overwrite attributes', () => { | |
it('should be able to overwrite attributes', () => { |
SpanKind.CLIENT | ||
); | ||
describe('setAttributes', () => { | ||
it('should able to set multiple attributes', () => { |
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.
it('should able to set multiple attributes', () => { | |
it('should be able to set multiple attributes', () => { |
Signed-off-by: Banothu Ramesh Naik <[email protected]>
* @param value Attribute value | ||
* @returns truncated attribute value if required, otherwise same value | ||
*/ | ||
private _truncateToSize(value?: SpanAttributeValue): SpanAttributeValue | undefined { |
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.
private _truncateToSize(value?: SpanAttributeValue): SpanAttributeValue | undefined { | |
private _truncateToSize(value: SpanAttributeValue): SpanAttributeValue { |
Signed-off-by: Banothu Ramesh Naik <[email protected]>
Which problem is this PR solving?
Short description of the changes