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

feat(js): Add docs for updateSpanName #11824

Merged
merged 5 commits into from
Dec 19, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,22 @@ Sentry maintains a [list of well known span operations](https://develop.sentry.d

### Updating the Span Name

_Available since: v8.46.0_
Lms24 marked this conversation as resolved.
Show resolved Hide resolved

You can update the name of a span at any time:

```javascript
const span = Sentry.getActiveSpan();
if (span) {
span.updateName("New Name");
Sentry.updateSpanName(span, "New Name");
}
```

Please note that in certain scenarios, the span name will be overwritten by the SDK. This is the case for spans with any of the following attribute combinations:
Prior to v8.39.0, you had to use `span.updateName('New Name')`, which had some limitations in `@sentry/node` and SDKs depending on it (for example, `@sentry/nextjs`):

- Spans with `http.method` or `http.request.method` attributes would automatically have their name set to the method + the URL path.
- Spans with `db.system` attributes would automatically have their name set to the system + the statement.

Using `Sentry.updateSpanName()` ensures that the name is updated correctly and no longer overwritten in these cases.

* Spans with `http.method` or `http.request.method` attributes will automatically have their name set to the method + the URL path
* Spans with `db.system` attributes will automatically have their name set to the system + the statement
If you use `@sentry/browser`, `@sentry/react`, and so on in browser environments, `span.updateName()` and `Sentry.updateSpanName()` will function identically, so you can use either one of them.
Loading