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

Commit

Permalink
Add WithSpan (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
arugal authored Mar 2, 2022
1 parent 44fc8f0 commit acee2ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ Get the `activeSpan` in the `Context`.
go2sky.ActiveSpan(ctx)
```

## With Span

Save the `activeSpan` to `Context`

```go
go2sky.WithSpan(ctx, activeSpan)
```

## Get Global Service Name

Get the `ServiceName` of the `activeSpan` in the `Context`.
Expand Down
4 changes: 4 additions & 0 deletions trace_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func ActiveSpan(ctx context.Context) Span {
return nil
}

func WithSpan(ctx context.Context, span Span) context.Context {
return context.WithValue(ctx, ctxKeyInstance, span)
}

func extractSpanString(ctx context.Context, noopResult string) (*segmentSpan, string, bool) {
activeSpan := ctx.Value(ctxKeyInstance)
if activeSpan != nil {
Expand Down

0 comments on commit acee2ee

Please sign in to comment.