@@ -60,19 +60,86 @@ type EventLogger interface {
60
60
// DEPRECATED
61
61
EventBegin (ctx context.Context , event string , m ... Loggable ) * EventInProgress
62
62
63
+ // Start starts an opentracing span with `name`, using
64
+ // any Span found within `ctx` as a ChildOfRef. If no such parent could be
65
+ // found, Start creates a root (parentless) Span.
66
+ //
67
+ // The return value is a context.Context object built around the
68
+ // returned Span.
69
+ //
70
+ // Example usage:
71
+ //
72
+ // SomeFunction(ctx context.Context, ...) {
73
+ // ctx := log.Start(ctx, "SomeFunction")
74
+ // defer log.Finish(ctx)
75
+ // ...
76
+ // }
63
77
Start (ctx context.Context , name string ) context.Context
78
+
79
+ // StartFromParentState starts an opentracing span with `name`, using
80
+ // any Span found within `ctx` as a ChildOfRef. If no such parent could be
81
+ // found, StartSpanFromParentState creates a root (parentless) Span.
82
+ //
83
+ // StartFromParentState will attempt to deserialize a SpanContext from `parent`,
84
+ // using any Span found within to continue the trace
85
+ //
86
+ // The return value is a context.Context object built around the
87
+ // returned Span.
88
+ //
89
+ // An error is returned when `parent` cannot be deserialized to a SpanContext
90
+ //
91
+ // Example usage:
92
+ //
93
+ // SomeFunction(ctx context.Context, bParent []byte) {
94
+ // ctx := log.StartFromParentState(ctx, "SomeFunction", bParent)
95
+ // defer log.Finish(ctx)
96
+ // ...
97
+ // }
64
98
StartFromParentState (ctx context.Context , name string , parent []byte ) (context.Context , error )
65
99
100
+ // Finish completes the span associated with `ctx`.
101
+ //
102
+ // Finish() must be the last call made to any span instance, and to do
103
+ // otherwise leads to undefined behavior.
104
+ // Finish will do its best to notify (log) when used in correctly
105
+ // .e.g called twice, or called on a spanless `ctx`
66
106
Finish (ctx context.Context )
107
+
108
+ // FinishWithErr completes the span associated with `ctx` and also calls
109
+ // SetErr if `err` is non-nil
110
+ //
111
+ // FinishWithErr() must be the last call made to any span instance, and to do
112
+ // otherwise leads to undefined behavior.
113
+ // FinishWithErr will do its best to notify (log) when used in correctly
114
+ // .e.g called twice, or called on a spanless `ctx`
67
115
FinishWithErr (ctx context.Context , err error )
68
116
117
+ // SetErr tags the span associated with `ctx` to reflect an error occured, and
118
+ // logs the value `err` under key `error`.
69
119
SetErr (ctx context.Context , err error )
70
120
121
+ // LogKV records key:value logging data about an event stored in `ctx`
122
+ // Eexample:
123
+ // log.LogKV(
124
+ // "error", "resolve failure",
125
+ // "type", "cache timeout",
126
+ // "waited.millis", 1500)
71
127
LogKV (ctx context.Context , alternatingKeyValues ... interface {})
72
128
129
+ // SetTag tags key `k` and value `v` on the span associated with `ctx`
73
130
SetTag (ctx context.Context , key string , value interface {})
131
+
132
+ // SetTags tags keys from the `tags` maps on the span associated with `ctx`
133
+ // Example:
134
+ // log.SetTags(ctx, map[string]{
135
+ // "type": bizStruct,
136
+ // "request": req,
137
+ // })
74
138
SetTags (ctx context.Context , tags map [string ]interface {})
75
139
140
+ // SerializeContext takes the SpanContext instance stored in `ctx` and Seralizes
141
+ // it to bytes. An error is returned if the `ctx` cannot be serialized to
142
+ // a bytes array
76
143
SerializeContext (ctx context.Context ) ([]byte , error )
77
144
}
78
145
@@ -100,46 +167,12 @@ type eventLogger struct {
100
167
// TODO add log-level
101
168
}
102
169
103
- // Start starts an opentracing span with `operationName`, using
104
- // any Span found within `ctx` as a ChildOfRef. If no such parent could be
105
- // found, StartSpanFromContext creates a root (parentless) Span.
106
- //
107
- // The return value is a context.Context object built around the
108
- // returned Span.
109
- //
110
- // Example usage:
111
- //
112
- // SomeFunction(ctx context.Context, ...) {
113
- // ctx := log.Start(ctx, "SomeFunction")
114
- // defer log.Finish(ctx)
115
- // ...
116
- // }
117
170
func (el * eventLogger ) Start (ctx context.Context , operationName string ) context.Context {
118
171
span , ctx := opentrace .StartSpanFromContext (ctx , operationName )
119
172
span .SetTag ("system" , el .system )
120
173
return ctx
121
174
}
122
175
123
- // TODO: need clearer examples and description
124
- // StartFromParentState starts an opentracing span with `operationName`, using
125
- // any Span found within `ctx` as a ChildOfRef. If no such parent could be
126
- // found, StartSpanFromContext creates a root (parentless) Span.
127
- //
128
- // StartFromParentState will attempt to deserialize a SpanContext from `parent`,
129
- // using any Span found within to continue the trace
130
- //
131
- // The return value is a context.Context object built around the
132
- // returned Span.
133
- //
134
- // An error is returned when `parent` cannot be deserialized to a SpanContext
135
- //
136
- // Example usage:
137
- //
138
- // SomeFunction(ctx context.Context, ...) {
139
- // ctx := log.StartFromParentState(ctx, "SomeFunction", bParent)
140
- // defer log.Finish(ctx)
141
- // ...
142
- // }
143
176
func (el * eventLogger ) StartFromParentState (ctx context.Context , operationName string , parent []byte ) (context.Context , error ) {
144
177
sc , err := deserializeContext (parent )
145
178
if err != nil {
@@ -152,8 +185,6 @@ func (el *eventLogger) StartFromParentState(ctx context.Context, operationName s
152
185
return ctx , nil
153
186
}
154
187
155
- // SerializeContext takes the SpanContext instance stored in `ctx`, and Seralizes
156
- // it to bytes.
157
188
func (el * eventLogger ) SerializeContext (ctx context.Context ) ([]byte , error ) {
158
189
gTracer := opentrace .GlobalTracer ()
159
190
b := make ([]byte , 0 )
@@ -165,12 +196,6 @@ func (el *eventLogger) SerializeContext(ctx context.Context) ([]byte, error) {
165
196
return carrier .Bytes (), nil
166
197
}
167
198
168
- // LogKV records key:value logging data about an event stored in `ctx`
169
- // Eexample:
170
- // log.LogKV(
171
- // "error", "resolve failure",
172
- // "type", "cache timeout",
173
- // "waited.millis", 1500)
174
199
func (el * eventLogger ) LogKV (ctx context.Context , alternatingKeyValues ... interface {}) {
175
200
span := opentrace .SpanFromContext (ctx )
176
201
if span == nil {
@@ -181,7 +206,6 @@ func (el *eventLogger) LogKV(ctx context.Context, alternatingKeyValues ...interf
181
206
span .LogKV (alternatingKeyValues ... )
182
207
}
183
208
184
- // SetTag tags key `k` and value `v` on the span associated with `ctx`
185
209
func (el * eventLogger ) SetTag (ctx context.Context , k string , v interface {}) {
186
210
span := opentrace .SpanFromContext (ctx )
187
211
if span == nil {
@@ -192,12 +216,6 @@ func (el *eventLogger) SetTag(ctx context.Context, k string, v interface{}) {
192
216
span .SetTag (k , v )
193
217
}
194
218
195
- // SetTags tags keys from the `tags` maps on the span associated with `ctx`
196
- // Example:
197
- // log.SetTags(ctx, map[string]{
198
- // "tag": bizStruct,
199
- // "bar": fizStruct,
200
- // })
201
219
func (el * eventLogger ) SetTags (ctx context.Context , tags map [string ]interface {}) {
202
220
span := opentrace .SpanFromContext (ctx )
203
221
if span == nil {
@@ -210,8 +228,6 @@ func (el *eventLogger) SetTags(ctx context.Context, tags map[string]interface{})
210
228
}
211
229
}
212
230
213
- // SetErr tags the span associated with `ctx` to reflect an error occured, and
214
- // logs the value `err` under key `error`
215
231
func (el * eventLogger ) SetErr (ctx context.Context , err error ) {
216
232
span := opentrace .SpanFromContext (ctx )
217
233
if span == nil {
@@ -227,13 +243,6 @@ func (el *eventLogger) SetErr(ctx context.Context, err error) {
227
243
span .LogKV ("error" , err .Error ())
228
244
}
229
245
230
- // Finish completes the span associated with `ctx` by
231
- // setting the end timestamp and finalizing the Span state.
232
- //
233
- // Finish() must be the last call made to any span instance, and to do
234
- // otherwise leads to undefined behavior.
235
- // Finish will do its best to notify (log) when used in correctly
236
- // .e.g called twice, or called on a spanless `ctx`
237
246
func (el * eventLogger ) Finish (ctx context.Context ) {
238
247
span := opentrace .SpanFromContext (ctx )
239
248
if span == nil {
@@ -244,14 +253,6 @@ func (el *eventLogger) Finish(ctx context.Context) {
244
253
span .Finish ()
245
254
}
246
255
247
- // FinishWithErr completes the span associated with `ctx` by
248
- // setting the end timestamp and finalizing the Span state, in addition to
249
- // calling the `SetErr` method first
250
- //
251
- // FinishWithErr() must be the last call made to any span instance, and to do
252
- // otherwise leads to undefined behavior.
253
- // FinishWithErr will do its best to notify (log) when used in correctly
254
- // .e.g called twice, or called on a spanless `ctx`
255
256
func (el * eventLogger ) FinishWithErr (ctx context.Context , err error ) {
256
257
el .SetErr (ctx , err )
257
258
el .Finish (ctx )
0 commit comments