trace

package
v0.5.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2026 License: BSD-2-Clause Imports: 17 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SafeAttr

func SafeAttr(key string, val any) attribute.KeyValue
Example (Bool)
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/trace"
)

func main() {
	b := true
	attr := trace.SafeAttr("enabled", &b)
	fmt.Println(attr.Key)
	fmt.Println(attr.Value.AsBool())
}
Output:
enabled
true
Example (Float64)
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/trace"
)

func main() {
	f := 3.14
	attr := trace.SafeAttr("pi", &f)
	fmt.Println(attr.Key)
	fmt.Println(attr.Value.AsFloat64())
}
Output:
pi
3.14
Example (Int)
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/trace"
)

func main() {
	n := 42
	attr := trace.SafeAttr("count", &n)
	fmt.Println(attr.Key)
	fmt.Println(attr.Value.AsInt64())
}
Output:
count
42
Example (Nil)
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/trace"
)

func main() {
	attr := trace.SafeAttr("missing", nil)
	fmt.Println(attr.Key)
}
Output:
missing.unsupported
Example (String)
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/trace"
)

func main() {
	s := "hello"
	attr := trace.SafeAttr("greeting", &s)
	fmt.Println(attr.Key)
	fmt.Println(attr.Value.AsString())
}
Output:
greeting
hello
Example (StringSlice)
package main

import (
	"fmt"

	"github.com/SUNET/vc/pkg/trace"
)

func main() {
	vals := []string{"a", "b", "c"}
	attr := trace.SafeAttr("tags", &vals)
	fmt.Println(attr.Key)
	fmt.Println(attr.Value.AsStringSlice())
}
Output:
tags
[a b c]

Types

type Tracer

type Tracer struct {
	TP *sdktrace.TracerProvider
	trace.Tracer
	// contains filtered or unexported fields
}

Tracer is a wrapper for opentelemetry tracer

func New

func New(ctx context.Context, cfg *model.Cfg, serviceName string, log *logger.Log) (*Tracer, error)

New return a new tracer

func NewForTesting

func NewForTesting(ctx context.Context, projectName string, log *logger.Log) (*Tracer, error)

NewForTesting return a new tracer for testing purpose without exporting the trace

func (*Tracer) Shutdown

func (t *Tracer) Shutdown(ctx context.Context) error

Shutdown shuts down the tracer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL