/
trace.go
38 lines (33 loc) · 1.04 KB
/
trace.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
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package trace adds support for telemetry tracing.
package trace
import (
"context"
"time"
"github.com/anz-bank/sysl/pkg/lspimpl/lspframework/telemetry"
"github.com/anz-bank/sysl/pkg/lspimpl/lspframework/telemetry/export"
)
func StartSpan(ctx context.Context, name string, tags ...telemetry.Tag) (context.Context, func()) {
ctx = export.ProcessEvent(ctx, telemetry.Event{
Type: telemetry.EventStartSpan,
Message: name,
At: time.Now(),
Tags: tags,
})
return ctx, func() {
export.ProcessEvent(ctx, telemetry.Event{
Type: telemetry.EventEndSpan,
At: time.Now(),
})
}
}
// Detach returns a context without an associated span.
// This allows the creation of spans that are not children of the current span.
func Detach(ctx context.Context) context.Context {
return export.ProcessEvent(ctx, telemetry.Event{
Type: telemetry.EventDetach,
At: time.Now(),
})
}