Skip to content

Commit

Permalink
fix: if not kratos context then panic will result (#1338)
Browse files Browse the repository at this point in the history
* fix: if not kratos context panic

当ctx不是kratos的context,则app.Name()会导致panic
  • Loading branch information
fifsky committed Aug 15, 2021
1 parent 3f68c9a commit 80378ca
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions middleware/tracing/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ var _ propagation.TextMapPropagator = Metadata{}

// Inject sets metadata key-values from ctx into the carrier.
func (b Metadata) Inject(ctx context.Context, carrier propagation.TextMapCarrier) {
app, _ := kratos.FromContext(ctx)
carrier.Set(serviceHeader, app.Name())
app, ok := kratos.FromContext(ctx)
if ok {
carrier.Set(serviceHeader, app.Name())
}
}

// Extract returns a copy of parent with the metadata from the carrier added.
Expand Down

0 comments on commit 80378ca

Please sign in to comment.