package tracking

import (
	"context"
	"errors"
)

// Define our custom key type
type key int

// declare our key value
const tracerKey key = 0

type Tracer struct {
	ID int
}

func WithContext(ctx context.Context, t *Tracer) context.Context {
	return context.WithValue(ctx, tracerKey, t)
}

func FromContext(ctx context.Context) (*Tracer, error) {
	t, ok := ctx.Value(tracerKey).(*Tracer)
	if !ok {
		return nil, errors.New("tracer not found")
	}
	return t, nil
}
