skywalking @Tags
时间: 2024-12-26 14:22:21 浏览: 7
### SkyWalking Tags Usage and Examples
In the context of SkyWalking, tags are utilized extensively within tracing mechanisms to provide additional metadata about spans or traces. The `IgnoredException` annotation mentioned serves as one method for configuring which exceptions should be disregarded during trace processing[^1]. This functionality allows developers to control how certain exceptional flows impact monitoring data.
For tagging operations specifically:
When using SkyWalking's API directly, one can add custom tags to a span with methods provided by the tracer interface. Below demonstrates adding simple key-value pairs that describe aspects of service interactions more precisely.
```java
Span span = tracer.createExitSpan("/service/method", destination);
span.setTag("http.status_code", "200");
span.setTag("db.instance", "main_db");
```
Additionally, when integrating via instrumentation modules (like Spring Boot), annotations play a significant role in specifying behavior without modifying application logic explicitly. For instance, marking services or methods so they automatically report specific metrics upon invocation.
#### Using Annotations for Tagging
To apply predefined sets of tags consistently across multiple endpoints, consider leveraging built-in or custom annotations supported by SkyWalking APM. An example might involve annotating REST controller actions to include operation names automatically.
```java
@Tag(key="operation.name", value="${method.name}")
@GetMapping("/api/resource/{id}")
public ResponseEntity<Resource> getResource(@PathVariable String id) {
// Method implementation...
}
```
This approach ensures every request handled through this endpoint will carry along useful contextual information like its name, aiding later analysis efforts significantly.
--related questions--
1. How does setting up ignored exceptions influence overall system observability?
2. What other types of metadata besides HTTP status codes could enhance trace diagnostics?
3. Can you explain how to create custom annotations tailored for specialized tagging needs?
4. In what scenarios would it be beneficial to use programmatic tag addition over declarative approaches?
阅读全文