Skip to content
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

add optional parameter to record_exception method #1242

Merged
merged 9 commits into from
Nov 3, 2020

Conversation

shreyagupta30
Copy link
Contributor

This fixes #1102.
I have added two additional attributes to record_exception method. Those are

attributes: types.Attributes = None,
timestamp: typing.Optional[int] = None,

I have applied the tox lint checks.

@shreyagupta30 shreyagupta30 requested review from a team, codeboten and toumorokoshi and removed request for a team October 14, 2020 18:06
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 14, 2020

CLA Check
The committers are authorized under a signed CLA.

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shreyagupta30 for the PR, the same change will be needed in the SDK here:

def record_exception(self, exception: Exception) -> None:

Please add an entry to opentelemetry-api/changelog and opentelemetry-sdk/changelog to note the change.

@codeboten codeboten self-assigned this Oct 14, 2020
@shreyagupta30
Copy link
Contributor Author

@codeboten I have made required changes but somehow almost all the tests are failed. What do you suggest me to do now?

@codeboten
Copy link
Contributor

@shreyagupta30
Copy link
Contributor Author

@codeboten kindly let me know if any further changes are required.

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my previous comments, please add a test to ensure that attributes and timestamp parameters are used when record_exception is called with the additional parameters.

exception: Exception,
attributes: types.Attributes = None,
timestamp: Optional[int] = None,
) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the additional parameters here (attributes, timestamp) should be used in the method below. As per the spec:

If attributes with the same name would be generated by the method already, the additional attributes take precedence

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codeboten Can you please guide me on how to do this. I am not able to figure out what exactly needs to be done here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shreyagupta30 you'll want to pass in the timestamp argument into add_event, you can see what it looks like by looking at the method signature here:

def add_event(
self,
name: str,
attributes: types.Attributes = None,
timestamp: Optional[int] = None,

You'll also want to pass the attributes parameter in the add_event call below, ensuring that any attributes passed into this method overrides any of the default attributes, the way i'd approach it is probably to create a dict with the default attributes seen below, then loop through the attributes arg and set any values in the dict that way.

attributes={
"exception.type": exception.__class__.__name__,
"exception.message": str(exception),
"exception.stacktrace": stacktrace,
},

Last but not least, adding a test like the one below to ensure the attributes are set as expected

def test_record_exception(self):
span = trace._Span("name", mock.Mock(spec=trace_api.SpanContext))
try:
raise ValueError("invalid")
except ValueError as err:
span.record_exception(err)
exception_event = span.events[0]
self.assertEqual("exception", exception_event.name)
self.assertEqual(
"invalid", exception_event.attributes["exception.message"]
)
self.assertEqual(
"ValueError", exception_event.attributes["exception.type"]
)
self.assertIn(
"ValueError: invalid",
exception_event.attributes["exception.stacktrace"],
)

@codeboten codeboten added the release:required-for-ga To be resolved before GA release label Oct 15, 2020
Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to @codeboten's PR: the SDK is not honoring the intended behavior and adding the event.

@codeboten
Copy link
Contributor

@shreyagupta30 will you have time to look at this PR, the issue it's addressing is time sensitive.

@codeboten codeboten added the rc1 label Oct 29, 2020
@shreyagupta30
Copy link
Contributor Author

I am so sorry @codeboten, I got busy with other work. I will definitely get back to it. I was looking into unit tests as I am not very familiar with it.

@codeboten
Copy link
Contributor

No worries @shreyagupta30, if you're ok with it, we can merge this PR as is and then get the other PR #1314 committed over top of it to address the unit tests and implementation details.

@shreyagupta30
Copy link
Contributor Author

Sure @codeboten Thanks a lot :D

@toumorokoshi
Copy link
Member

if you're ok with it, we can merge this PR as is and then get the other PR #1314 committed over top of it to address the unit tests and implementation details.

If that's the strategy you'd like to take @codeboten, i'll switch mine to an approval then.

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved based on the conversation, with merging in unit tests and behavior quickly after.

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, let's merge this and get the other PR merged quickly after

@codeboten codeboten merged commit 4acad01 into open-telemetry:master Nov 3, 2020
@shreyagupta30 shreyagupta30 deleted the record-exception branch November 6, 2020 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:required-for-ga To be resolved before GA release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RecordException with extra parameters
4 participants