You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/en/development-and-contribution/development-guide.md
+24
Original file line number
Diff line number
Diff line change
@@ -347,6 +347,8 @@ After creating a Span, you can perform additional operations on it.
347
347
```go
348
348
// Span for plugin API
349
349
type Span interface {
350
+
// AsyncSpan for the async API
351
+
AsyncSpan
350
352
// Tag set the Tag of the Span
351
353
Tag(Tag, string)
352
354
// SetSpanLayer set the SpanLayer of the Span
@@ -364,6 +366,28 @@ type Span interface {
364
366
}
365
367
```
366
368
369
+
#### Async Span
370
+
371
+
There is a set of advanced APIs in Span which is specifically designed for async use cases.
372
+
When setting name, tags, logs, and other operations (including end span) of the span in another goroutine, you should use these APIs.
373
+
374
+
```go
375
+
typeAsyncSpaninterface {
376
+
// PrepareAsync the span finished at current tracing context, but current span is still alive until AsyncFinish called
377
+
PrepareAsync()
378
+
// AsyncFinish to finished current async span
379
+
AsyncFinish()
380
+
}
381
+
```
382
+
383
+
Following the previous API define, you should following these steps to use the async API:
384
+
1. Call `span.PrepareAsync()` to prepare the span to do any operation in another goroutine.
385
+
2. Use `Span.End()` in the original goroutine when your job in the current goroutine is complete.
386
+
3. Propagate the span to any other goroutine in your plugin.
387
+
4. Once the above steps are all set, call `span.AsyncFinish()` in any goroutine.
388
+
5. When the `span.AsyncFinish()` is complete for all spans, the all spans would be finished and report to the backend.
389
+
390
+
367
391
## Import Plugin
368
392
369
393
Once you have finished developing the plugin, you need to import the completed module into the Agent program and [define it in the corresponding file](../../../tools/go-agent/instrument/plugins/register.go).
0 commit comments