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 the ability to set status or record exception to a Span #928

Closed
roeycarmi opened this issue Aug 27, 2024 · 4 comments
Closed

Add the ability to set status or record exception to a Span #928

roeycarmi opened this issue Aug 27, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@roeycarmi
Copy link

roeycarmi commented Aug 27, 2024

What feature do you want to see added?

In java, i can do the following:

try {
    // Code that might throw an exception
} catch (Exception e) {
    span.recordException(e);
    span.setStatus(StatusCode.ERROR, "Exception occurred");
}

But the plugin function (i.e setSpanAttributes, withSpanAttribute, withSpanAttributes) only allow me to set attributes.

Upstream changes

No response

Are you interested in contributing this feature?

No response

@roeycarmi roeycarmi added the enhancement New feature or request label Aug 27, 2024
@kuisathaverat
Copy link
Contributor

🤔 Can you give more details about the use case for this?

@roeycarmi
Copy link
Author

I am running a python script that may return a variaty of exit codes.
In the groovy code I would like to decide for each return code whether to mark the span with status OK or ERROR.
Plus, I may want to put my own Exception message.
For example: my python script may return code 2 and I'll want to set the status to ERROR and record an exception "InfrastructureException Occured"

@kuisathaverat
Copy link
Contributor

I think you can achieve that with something like this, to playing with try-catch or catcherror blocks in groovy, or even better using post stages.

script {
      ret = sh(script: 'exit $(echo "$RANDOM%4" |bc)', returnStatus: true)
      if(ret == 1){
         error("Error 1")
      } else if (ret == 2){
         error("Error 2")
      } else if (ret == 3){
         error("Error 3")
      } else if (ret == 4){
         error("Error 4")
      } else {
         error("Error unknow")
      }
}

@roeycarmi
Copy link
Author

Great answer, thanks for the response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants