Skip to content

Commit

Permalink
format doc
Browse files Browse the repository at this point in the history
  • Loading branch information
dagmom committed Jul 29, 2020
1 parent 9f81b88 commit d9a4a33
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# apm-toolkit-trace

* 使用maven或gradle引入toolkit依赖。

```xml
<dependency>
<groupId>org.apache.skywalking</groupId>
Expand All @@ -7,19 +10,19 @@
</dependency>
```

* 使用 `TraceContext.traceId()` API得到traceId
* 使用 `TraceContext.traceId()` API 得到 traceId

```java
import TraceContext;
...

modelAndView.addObject("traceId", TraceContext.traceId());
// 仅为示例代码
```
_仅为示例代码_

* 在你想追踪的方法上添加`@Trace`注解。添加后,你就可以在方法调用栈中查看到span的信息。
* 如果标签处没有有效跨度,则用@Tag注释的方法将尝试使用给定键(`Tag#key()`)和(`Tag#value()`)标记**当前有效跨度**
若有,此注释不起作用。可以重复使用@Tag,并且可以与@Trace结合使用,请参见下面的示例。
“标签”的“值”与[自定义增强跟踪](Customize-enhance-trace.md)中支持的值相同。
* 如果标签处没有有效跨度,则用`@Tag`注释的方法将尝试使用给定键(`Tag#key()`)和(`Tag#value()`)标记**当前有效跨度**
若有,此注释不起作用。可以重复使用`@Tag`,并且可以与`@Trace`结合使用,请参见下面的示例。“标签”的“值”与[自定义增强跟踪](Customize-enhance-trace.md)中支持的值相同。
* 在跟踪方法的上下文中添加自定义标签, `ActiveSpan.tag("key", "val")`.

* `ActiveSpan.error()` 将当前跨度标记为错误状态。
Expand All @@ -40,8 +43,8 @@ ActiveSpan.debug("Test-debug-Msg");

/**
* The codes below will generate a span,
* and two types of tags,
one type tag: keys are `tag1` and `tag2`, values are the passed-in parameters, respectively,
* and two types of tags,
one type tag: keys are `tag1` and `tag2`, values are the passed-in parameters, respectively,
the other type tag: keys are `username` and `age`, values are the return value in User, respectively
*/
@Trace
Expand All @@ -56,13 +59,17 @@ public User methodYouWantToTrace(String param1, String param2) {
```

* 使用 `TraceContext.putCorrelation()` API将自定义数据放入跟踪上下文。

```java
Optional<String> previous = TraceContext.putCorrelation("customKey", "customValue");
```

当值为`null`或为空时,CorrelationContext将删除该项目。

* 使用 `TraceContext.getCorrelation()` 获取自定义数据的API。

```java
Optional<String> value = TraceContext.getCorrelation("customKey");
```

可以在[代理配置](README.md#table-of-agent-configuration-properties)文件中找到CorrelationContext配置描述,前缀为`correlation.`

0 comments on commit d9a4a33

Please sign in to comment.