Skip to content
This repository was archived by the owner on Jun 14, 2023. It is now read-only.

Commit acee2ee

Browse files
authored
Add WithSpan (#153)
1 parent 44fc8f0 commit acee2ee

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ Get the `activeSpan` in the `Context`.
110110
go2sky.ActiveSpan(ctx)
111111
```
112112

113+
## With Span
114+
115+
Save the `activeSpan` to `Context`
116+
117+
```go
118+
go2sky.WithSpan(ctx, activeSpan)
119+
```
120+
113121
## Get Global Service Name
114122

115123
Get the `ServiceName` of the `activeSpan` in the `Context`.

trace_context.go

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ func ActiveSpan(ctx context.Context) Span {
8181
return nil
8282
}
8383

84+
func WithSpan(ctx context.Context, span Span) context.Context {
85+
return context.WithValue(ctx, ctxKeyInstance, span)
86+
}
87+
8488
func extractSpanString(ctx context.Context, noopResult string) (*segmentSpan, string, bool) {
8589
activeSpan := ctx.Value(ctxKeyInstance)
8690
if activeSpan != nil {

0 commit comments

Comments
 (0)