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

recordException should allow additional attributes #4070

Open
dvoytenko opened this issue Aug 16, 2023 · 5 comments · Fixed by #4071
Open

recordException should allow additional attributes #4070

dvoytenko opened this issue Aug 16, 2023 · 5 comments · Fixed by #4071

Comments

@dvoytenko
Copy link
Contributor

Is your feature request related to a problem? Please describe.

The recordException API only accepts the exception and time arguments.

Describe the solution you'd like

The specification appears to require that this API also allows a user to pass additional attributes. The relevant excerpt:

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.

The potential API update would be:

recordException(exception: Exception, attributes: Attributes, time?: TimeInput): void;
recordException(exception: Exception, time?: TimeInput): void;
@dvoytenko
Copy link
Contributor Author

Could you pls reopen this issue?

@pichlermarc pichlermarc reopened this Oct 4, 2023
@Zirak
Copy link
Contributor

Zirak commented Nov 27, 2023

I'm interested in picking this back up. I think the original PR was great, it seems like the only thing missing to be backwards-compatible with type signatures as well was:

   recordException(
     exception: Exception,
-    attributes?: SpanAttributes,
+    attributes?: SpanAttributes | TimeInput,
     time?: TimeInput

In some local testing after applying that change, it's possible to define an interface such as:

interface OtherSpan extends Span {
  recordException(exception: Exception, time?: TimeInput): void;
}

Which, if I understand correctly, looks like the original downstream use.

@dvoytenko
Copy link
Contributor Author

@Zirak this sounds great!

@smoke
Copy link

smoke commented Jan 31, 2024

What would be the way forward to introduce that feature?
The PR #4071 is pretty decent, beside the braking change for DD trace

One easy, but arguable option to not introduce braking changes would be to make the methods optional.

Instead of https://github.com/dvoytenko/opentelemetry-js/blob/96df3fa8c8e980833a549b821aaaeba4cec872f6/api/src/trace/span.ts#L122C1-L141C11
to have

  /**
   * Sets exception as a span event
   * @param exception the exception the only accepted values are string or Error
   * @param [time] the time to set as Span's event time. If not provided,
   *     use the current time.
   */
  recordException?(exception: Exception, time?: TimeInput): void;

  /**
   * Sets exception as a span event
   * @param exception the exception the only accepted values are string or Error
   * @param [attributes] the attributes that will be added to the error event.
   * @param [time] the time to set as Span's event time. If not provided,
   *     use the current time.
   */
  recordException?(
    exception: Exception,
    attributes?: SpanAttributes,
    time?: TimeInput
  ): void;

Another option is to update the DD trace types definitions https://github.com/DataDog/dd-trace-js/blob/0e9fc0afa6fc7692a95496fa579c0c435db277fd/index.d.ts#L1899-L1905
they are eitherway not properly implementing the method and discarding the extra arguments https://github.com/DataDog/dd-trace-js/blob/0e9fc0afa6fc7692a95496fa579c0c435db277fd/packages/dd-trace/src/opentelemetry/span.js#L230-L236

Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

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

Successfully merging a pull request may close this issue.

4 participants