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

Add WithSpan #153

Merged
merged 2 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain a little more about the use case? Is this span from some other context?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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