Skip to content

Commit

Permalink
feat(js): Add docs for updateSpanName
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Nov 14, 2024
1 parent c29c9f0 commit f7cbbe7
Showing 1 changed file with 10 additions and 4 deletions.
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.39.0_

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 (e.g. `@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()` instead of `span.updateName()` ensures that the name is updated correctly and no longer overwritten in all 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
In browser environments (if you use `@sentry/browser`, `@sentry/react`, etc), `span.updateName()` and `Sentry.updateSpanName()` are identical and you can use either of them.

0 comments on commit f7cbbe7

Please sign in to comment.