Skip to content

Commit c257488

Browse files
authored
update tracing stuff (#1472)
* jaeger deprecated config stuff * add call_id trace tag, proper app and fn trace span attributes turns out the tag keys don't get added to the trace span attributes, have to annotate them differently, kinda sucks but whatever... these are useful for debugging (particularly call id for me right now, anyway)
1 parent 34f5ff2 commit c257488

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

api/agent/agent.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/sirupsen/logrus"
2626
"go.opencensus.io/plugin/ochttp"
2727
"go.opencensus.io/stats"
28+
"go.opencensus.io/tag"
2829
"go.opencensus.io/trace"
2930
"go.opencensus.io/trace/propagation"
3031
)
@@ -232,19 +233,24 @@ func (a *agent) Close() error {
232233

233234
func (a *agent) Submit(callI Call) error {
234235
call := callI.(*call)
235-
ctx, span := trace.StartSpan(call.req.Context(), "agent_submit")
236-
defer span.End()
237236

238-
statsCalls(ctx)
237+
ctx := call.req.Context()
239238

240-
if !a.shutWg.AddSession(1) {
241-
statsTooBusy(ctx)
242-
return models.ErrCallTimeoutServerBusy
239+
callIDKey, err := tag.NewKey("agent.call_id")
240+
if err != nil {
241+
return err
242+
}
243+
ctx, err = tag.New(ctx, tag.Insert(callIDKey, call.ID))
244+
if err != nil {
245+
return err
243246
}
244-
defer a.shutWg.DoneSession()
245247

246-
err := a.submit(ctx, call)
247-
return err
248+
ctx, span := trace.StartSpan(ctx, "agent_submit")
249+
defer span.End()
250+
251+
span.AddAttributes(trace.StringAttribute("agent.call_id", call.ID))
252+
253+
return a.submit(ctx, call)
248254
}
249255

250256
func (a *agent) startStateTrackers(ctx context.Context, call *call) {
@@ -256,6 +262,14 @@ func (a *agent) endStateTrackers(ctx context.Context, call *call) {
256262
}
257263

258264
func (a *agent) submit(ctx context.Context, call *call) error {
265+
statsCalls(ctx)
266+
267+
if !a.shutWg.AddSession(1) {
268+
statsTooBusy(ctx)
269+
return models.ErrCallTimeoutServerBusy
270+
}
271+
defer a.shutWg.DoneSession()
272+
259273
statsEnqueue(ctx)
260274

261275
a.startStateTrackers(ctx, call)

api/server/gin_middlewares.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,15 @@ func optionalCorsWrap(r *gin.Engine) {
6666

6767
// we should use http grr
6868
func traceWrap(c *gin.Context) {
69-
appKey, err := tag.NewKey("fn_appname")
69+
appIDKey, err := tag.NewKey("fn.app_id")
7070
if err != nil {
7171
logrus.Fatal(err)
7272
}
73-
appIDKey, err := tag.NewKey("fn_app_id")
74-
if err != nil {
75-
logrus.Fatal(err)
76-
}
77-
fnKey, err := tag.NewKey("fn_fn_id")
73+
fnKey, err := tag.NewKey("fn.fn_id")
7874
if err != nil {
7975
logrus.Fatal(err)
8076
}
8177
ctx, err := tag.New(c.Request.Context(),
82-
tag.Insert(appKey, c.Param(api.AppName)),
8378
tag.Insert(appIDKey, c.Param(api.AppID)),
8479
tag.Insert(fnKey, c.Param(api.FnID)),
8580
)
@@ -90,8 +85,14 @@ func traceWrap(c *gin.Context) {
9085
// TODO inspect opencensus more and see if we need to define a header ourselves
9186
// to trigger per-request spans (we will want this), we can set sampler here per request.
9287

93-
ctx, serverSpan := trace.StartSpan(ctx, "serve_http")
94-
defer serverSpan.End()
88+
ctx, span := trace.StartSpan(ctx, "serve_http")
89+
defer span.End()
90+
91+
// spans like these, not tags
92+
span.AddAttributes(
93+
trace.StringAttribute("fn.app_id", c.Param(api.AppID)),
94+
trace.StringAttribute("fn.fn_id", c.Param(api.FnID)),
95+
)
9596

9697
c.Request = c.Request.WithContext(ctx)
9798
c.Next()

api/server/server.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,14 +664,15 @@ func WithoutFnInvokeEndpoints() Option {
664664
// WithJaeger maps EnvJaegerURL
665665
func WithJaeger(jaegerURL string) Option {
666666
return func(ctx context.Context, s *Server) error {
667-
// ex: "http://localhost:14268"
667+
// ex: "http://localhost:14268/api/traces?format=jaeger.thrift"
668668
if jaegerURL == "" {
669669
return nil
670670
}
671671

672672
exporter, err := jaeger.NewExporter(jaeger.Options{
673-
Endpoint: jaegerURL,
674-
ServiceName: "fn",
673+
CollectorEndpoint: jaegerURL,
674+
Process: jaeger.Process{ServiceName: "fnserver"},
675+
OnError: func(err error) { logrus.WithError(err).Error("Error when uploading spans to Jaeger") },
675676
})
676677
if err != nil {
677678
return fmt.Errorf("error connecting to jaeger: %v", err)

0 commit comments

Comments
 (0)