Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

feat: allow setting attributes when recording exceptions #97

Closed

Conversation

vreynolds
Copy link

  • span.recordException needs to allow settings event attributes per spec

If RecordException is provided, the method MUST accept an optional parameter to provide any additional event attributes (this SHOULD be done in the same way as for the AddEvent method). If attributes with the same name would be generated by the method already, the additional attributes take precedence.

@codecov
Copy link

codecov bot commented Jun 23, 2021

Codecov Report

Merging #97 (5f24c7e) into main (7441fea) will decrease coverage by 0.15%.
The diff coverage is 75.00%.

❗ Current head 5f24c7e differs from pull request most recent head 81fc4d3. Consider uploading reports for the commit 81fc4d3 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main      #97      +/-   ##
==========================================
- Coverage   94.84%   94.69%   -0.16%     
==========================================
  Files          42       42              
  Lines         563      565       +2     
  Branches       87       87              
==========================================
+ Hits          534      535       +1     
- Misses         29       30       +1     
Impacted Files Coverage Δ
src/trace/NonRecordingSpan.ts 95.45% <75.00%> (-4.55%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7441fea...81fc4d3. Read the comment docs.

* @param [time] the time to set as Span's event time. If not provided,
* use the current time.
*/
recordException(exception: Exception, time?: TimeInput): void;
recordException(
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we use an overload here to be more specific? e.g. like this:

recordException(exception: Exception, time?: TimeInput): void;
recordException(exception: Exception, attributes: SpanAttributes, time?: TimeInput): void;

Copy link
Author

Choose a reason for hiding this comment

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

I like that. For symmetry, I would change the addEvent as well, since they're pretty much identical interfaces.

Copy link
Author

Choose a reason for hiding this comment

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

Updated in new commit

@dyladan
Copy link
Member

dyladan commented Jun 25, 2021

Generally I like the change. Before approving and merging I'm trying to get guidance from the TC on the backport policy. Since this will require us to go to 1.1.x, will we need to backport fixes to 1.0.x in the future.

@dyladan
Copy link
Member

dyladan commented Jun 25, 2021

From https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md#api-support

Bug and security fixes will be backported. Additional feature development is NOT RECOMMENDED.

Seems backporting fixes will be required for the duration of the 1.x lifecycle, and it is not recommended to make changes if possible. I think this change is not high enough priority to break this recommendation. A user can simply call recordException and then call addAttributes.

* @param [startTime] start time of the event.
*/
addEvent(
name: string,
attributesOrStartTime?: SpanAttributes | TimeInput,
attributes?: SpanAttributes,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
attributes?: SpanAttributes,
attributes: SpanAttributes,

No need to make this optional here. The other overload allows already a call with name only.

*/
recordException(
exception: Exception,
attributes?: SpanAttributes,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
attributes?: SpanAttributes,
attributes: SpanAttributes,

* @param [startTime] start time of the event.
*/
addEvent(
name: string,
attributesOrStartTime?: SpanAttributes | TimeInput,
attributes?: SpanAttributes,
Copy link
Member

Choose a reason for hiding this comment

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

strictly speaking this is a breaking change for a typescript user as addEvent(name, timeInput, timeInput) is no longer allowed now.

Copy link
Author

Choose a reason for hiding this comment

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

Ha, that's an interseting edge case! Closing this PR either way, but thanks for catching.

@vreynolds vreynolds closed this Jun 25, 2021
@vreynolds vreynolds deleted the update-span-record-exception branch June 25, 2021 15:07
@longility
Copy link

From https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md#api-support

Bug and security fixes will be backported. Additional feature development is NOT RECOMMENDED.

Seems backporting fixes will be required for the duration of the 1.x lifecycle, and it is not recommended to make changes if possible. I think this change is not high enough priority to break this recommendation. A user can simply call recordException and then call addAttributes.

@dyladan I didn't see an addAttributes to where the attributes are part of the span event created by recordException. Is your comment stating that it would be setAttributes and the attributes will be on the span that the span event created by recordException? I'm trying to see if I overlooked where this addAttributes is.

@dyladan
Copy link
Member

dyladan commented Jan 19, 2022

It was just a typo. I meant setAttributes.

Re-reading the issue and my response though has made me realize that the feature request was to add attributes to the event, not the span. recordException doesn't return the event or provide any mechanism for this. Now that we have agreed to start developing new features (1.1 release will come soon) I think this should be reconsidered.

@longility
Copy link

I definitely would like this to be reconsidered! I have multiple use cases that need this.

@longility
Copy link

@dyladan I’m not familiar with process of getting certain work in particular releases or who is needed to get alignment. Any next steps I can help with? I didn’t want to miss this going in next minor release. Let me know.

@dyladan
Copy link
Member

dyladan commented Jan 20, 2022

There is no exact process. At the last couple SIG meetings we had decided to release 1.1 when #147, #142, and #129 were merged which has now happened. Now we're preparing the SDK so that the release can be as close to the same time as possible. If you want to make an argument that 1.1 should be held for this feature, I would suggest you make a feature request issue (or a PR I guess) and tag the JS maintainers team. If it is not in 1.1, it will have to wait for 1.2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Span.recordException must allow additional attributes according to spec
4 participants