package tracing
import (
"context"
"net/http"
"github.com/mark3labs/mcp-go/mcp"
)
type SpanKind int
const (
SpanKindUnspecified SpanKind = iota
SpanKindServer
SpanKindClient
SpanKindInternal
)
type StatusCode int
const (
StatusUnset StatusCode = iota
StatusOK
StatusError
)
type Attribute struct {
Key, Value string
}
func String (key , value string ) Attribute {
return Attribute {Key : key , Value : value }
}
type Tracer interface {
Start (ctx context .Context , name string , kind SpanKind , attrs ...Attribute ) (context .Context , Span )
}
type Span interface {
SetAttributes (attrs ...Attribute )
RecordError (err error )
SetStatus (code StatusCode , description string )
End ()
}
type Propagator interface {
Inject (ctx context .Context , headers http .Header )
Extract (ctx context .Context , headers http .Header ) context .Context
}
type MetaPropagator interface {
InjectMeta (ctx context .Context , meta *mcp .Meta ) *mcp .Meta
ExtractMeta (ctx context .Context , meta *mcp .Meta ) context .Context
}
func NoopMetaPropagator () MetaPropagator { return noopMetaPropagator {} }
type spanContextKey struct {}
func ContextWithSpan (ctx context .Context , span Span ) context .Context {
return context .WithValue (ctx , spanContextKey {}, span )
}
func SpanFromContext (ctx context .Context ) Span {
if s , ok := ctx .Value (spanContextKey {}).(Span ); ok {
return s
}
return noopSpan {}
}
func NoopTracer () Tracer { return noopTracer {} }
func NoopPropagator () Propagator { return noopPropagator {} }
type noopTracer struct {}
func (noopTracer ) Start (ctx context .Context , _ string , _ SpanKind , _ ...Attribute ) (context .Context , Span ) {
return ctx , noopSpan {}
}
type noopSpan struct {}
func (noopSpan ) SetAttributes (...Attribute ) {}
func (noopSpan ) RecordError (error ) {}
func (noopSpan ) SetStatus (StatusCode , string ) {}
func (noopSpan ) End () {}
type noopPropagator struct {}
func (noopPropagator ) Inject (context .Context , http .Header ) {}
func (noopPropagator ) Extract (ctx context .Context , _ http .Header ) context .Context { return ctx }
type noopMetaPropagator struct {}
func (noopMetaPropagator ) InjectMeta (_ context .Context , meta *mcp .Meta ) *mcp .Meta { return meta }
func (noopMetaPropagator ) ExtractMeta (ctx context .Context , _ *mcp .Meta ) context .Context {
return ctx
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .