Skip to content

Commit 115477d

Browse files
SylvainJugetiffany76opentelemetrybot
authored
Document java explicit span name with @WithSpan annotation (#6641)
Co-authored-by: Tiffany Hrabusa <[email protected]> Co-authored-by: opentelemetrybot <[email protected]>
1 parent 7d5ed46 commit 115477d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

content/en/docs/zero-code/java/agent/annotations.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public class MyClass {
6060

6161
Each time the application invokes the annotated method, it creates a span that
6262
denotes its duration and provides any thrown exceptions. By default, the span
63-
name will be `<className>.<methodName>`, unless a name is provided as an
64-
argument to the annotation.
63+
name will be `<className>.<methodName>`, unless a name is provided through the
64+
`value` annotation parameter.
6565

6666
If the return type of the method annotated by `@WithSpan` is one of the
6767
[future- or promise-like](https://en.wikipedia.org/wiki/Futures_and_promises)
@@ -87,16 +87,22 @@ customization of spans:
8787

8888
| name | type | default | description |
8989
| ---------------- | ----------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
90+
| `value` | `String` | `""` | The span name. If not specified, the default `<className>.<methodName>` is used. |
9091
| `kind` | `SpanKind` (enum) | `INTERNAL` | The [kind of span](/docs/specs/otel/trace/api/#spankind). |
9192
| `inheritContext` | `boolean` | `true` | Since 2.14.0. Controls whether or not the new span will be parented in the existing (current) context. If `false`, a new context is created. |
9293

9394
Example parameter usage:
9495

9596
```java
96-
@WithSpan(kind = SpanKind.CLIENT, inheritContext = false)
97+
@WithSpan(kind = SpanKind.CLIENT, inheritContext = false, value = "my span name")
9798
public void myMethod() {
9899
<...>
99100
}
101+
102+
@WithSpan("my span name")
103+
public void myOtherMethod() {
104+
<...>
105+
}
100106
```
101107

102108
## Adding attributes to the span with `@SpanAttribute`

0 commit comments

Comments
 (0)