forked from reddit/baseplate.go
/
finish_option.go
41 lines (35 loc) · 976 Bytes
/
finish_option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package tracing
import (
"context"
opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/log"
)
const (
ctxKey = "context"
// Note that this must be the same as
// https://github.com/opentracing/opentracing-go/blob/v1.1.0/log/field.go#L128
errorKey = "error"
)
// FinishOptions are the options to be converted into opentracing.FinishOptions.
//
// All fields are optional.
type FinishOptions struct {
Ctx context.Context
Err error
}
// Convert converts FinishOptions into opentracing.FinishOptions which can be
// used in Span.FinishWithOptions().
func (fo FinishOptions) Convert() opentracing.FinishOptions {
var opts opentracing.FinishOptions
var lr opentracing.LogRecord
if fo.Ctx != nil {
lr.Fields = append(lr.Fields, log.Object(ctxKey, fo.Ctx))
}
if fo.Err != nil {
lr.Fields = append(lr.Fields, log.Error(fo.Err))
}
if len(lr.Fields) > 0 {
opts.LogRecords = append(opts.LogRecords, lr)
}
return opts
}