tracing
API
tracing
packageAPI reference for the tracing
package.
Imports
(4)
S
testTracer
core/tracing/tracer_test.go:9-11
type testTracer struct
Methods
StartSpan
Method
Parameters
ctx
context.Context
name
string
Returns
func (*testTracer) StartSpan(ctx context.Context, name string) (context.Context, Span)
{
t.name = name
return context.WithValue(ctx, "span", name), &testSpan{}
}
Fields
| Name | Type | Description |
|---|---|---|
| name | string |
S
testSpan
core/tracing/tracer_test.go:18-21
type testSpan struct
Methods
End
Method
func (*testSpan) End()
{ s.ended = true }
Fields
| Name | Type | Description |
|---|---|---|
| ended | bool | |
| err | error |
F
function
TestStartSpanUsesNoopForNilTracer
Parameters
t
core/tracing/tracer_test.go:27-35
func TestStartSpanUsesNoopForNilTracer(t *testing.T)
{
ctx, span := StartSpan(context.Background(), nil, "op")
if ctx == nil || span == nil {
t.Fatal("StartSpan() returned nil values")
}
span.SetAttributes(Attribute{Key: "k", Value: "v"})
span.RecordError(errors.New("x"))
span.End()
}
F
function
TestStartSpanUsesTracer
Parameters
t
core/tracing/tracer_test.go:37-49
func TestStartSpanUsesTracer(t *testing.T)
{
tracer := &testTracer{}
ctx, span := StartSpan(context.Background(), tracer, "op")
if tracer.name != "op" {
t.Fatalf("name = %q, want op", tracer.name)
}
if ctx.Value("span") != "op" {
t.Fatalf("ctx value = %v, want op", ctx.Value("span"))
}
span.End()
}
I
interface
Span
Span represents a tracing span that can be ended and annotated.
core/tracing/tracer.go:8-12
type Span interface
Methods
End
Method
func End(...)
S
struct
Attribute
Attribute is a key-value pair for span metadata.
core/tracing/tracer.go:15-18
type Attribute struct
Fields
| Name | Type | Description |
|---|---|---|
| Key | string | |
| Value | any |
I
interface
Tracer
Tracer creates new spans.
core/tracing/tracer.go:21-23
type Tracer interface
Methods
S
noopSpan
core/tracing/tracer.go:25-25
type noopSpan struct
Methods
End
Method
func (noopSpan) End()
{}
S
noopTracer
core/tracing/tracer.go:31-31
type noopTracer struct
Methods
StartSpan
Method
Parameters
ctx
context.Context
name
string
Returns
func (noopTracer) StartSpan(ctx context.Context, name string) (context.Context, Span)
{
return ctx, noopSpan{}
}
F
function
StartSpan
StartSpan starts a span from the given tracer, falling back to Noop.
Parameters
Returns
core/tracing/tracer.go:41-46
func StartSpan(ctx context.Context, tracer Tracer, name string) (context.Context, Span)
{
if tracer == nil {
tracer = Noop
}
return tracer.StartSpan(ctx, name)
}