<commit_before>package tracer

import (
	"encoding/binary"
	"io"
	"strconv"
	"strings"

	"github.com/opentracing/opentracing-go"
)

// An Extracter extracts a SpanContext from carrier.
type Extracter func(carrier interface{}) (SpanContext, error)

// An Injecter injects a SpanContext into carrier.
type Injecter func(sm SpanContext, carrier interface{}) error

var extracters = map[interface{}]Extracter{
	opentracing.TextMap: textExtracter,
	opentracing.Binary:  binaryExtracter,
}

var injecters = map[interface{}]Injecter{
	opentracing.TextMap: textInjecter,
	opentracing.Binary:  binaryInjecter,
}

// RegisterExtracter registers an Extracter.
func RegisterExtracter(format interface{}, extracter Extracter) {
	extracters[format] = extracter
}

// RegisterInjecter registers an Injecter.
func RegisterInjecter(format interface{}, injecter Injecter) {
	injecters[format] = injecter
}

// SpanContext contains the parts of a span that will be sent to
// downstream services.
type SpanContext struct {
	TraceID  uint64            `json:"trace_id"`
	ParentID uint64            `json:"parent_id"`
	SpanID   uint64            `json:"span_id"`
	Flags    uint64            `json:"flags"`
	Baggage  map[string]string `json:"baggage"`
}

// ForeachBaggageItem implements the opentracing.Tracer interface.
func (c SpanContext) ForeachBaggageItem(handler func(k, v string) bool) {
	for k, v := range c.Baggage {
		if !handler(k, v) {
			return
		}
	}
}

func textInjecter(sm SpanContext, carrier interface{}) error {
	w, ok := carrier.(opentracing.TextMapWriter)
	if !ok {
		return opentracing.ErrInvalidCarrier
	}
	w.Set("Tracer-TraceId", idToHex(sm.TraceID))
	w.Set("Tracer-SpanId", idToHex(sm.SpanID))
	w.Set("Tracer-ParentSpanId", idToHex(sm.ParentID))
	w.Set("Tracer-Flags", strconv.FormatUint(sm.Flags, 10))
	for k, v := range sm.Baggage {
		w.Set("Tracer-Baggage-"+k, v)
	}
	return nil
}

func textExtracter(carrier interface{}) (SpanContext, error) {
	r, ok := carrier.(opentracing.TextMapReader)
	if !ok {<commit_msg>Use lowercase keys in TextMap<commit_after>package tracer

import (
	"encoding/binary"
	"io"
	"strconv"
	"strings"

	"github.com/opentracing/opentracing-go"
)

// An Extracter extracts a SpanContext from carrier.
type Extracter func(carrier interface{}) (SpanContext, error)

// An Injecter injects a SpanContext into carrier.
type Injecter func(sm SpanContext, carrier interface{}) error

var extracters = map[interface{}]Extracter{
	opentracing.TextMap: textExtracter,
	opentracing.Binary:  binaryExtracter,
}

var injecters = map[interface{}]Injecter{
	opentracing.TextMap: textInjecter,
	opentracing.Binary:  binaryInjecter,
}

// RegisterExtracter registers an Extracter.
func RegisterExtracter(format interface{}, extracter Extracter) {
	extracters[format] = extracter
}

// RegisterInjecter registers an Injecter.
func RegisterInjecter(format interface{}, injecter Injecter) {
	injecters[format] = injecter
}

// SpanContext contains the parts of a span that will be sent to
// downstream services.
type SpanContext struct {
	TraceID  uint64            `json:"trace_id"`
	ParentID uint64            `json:"parent_id"`
	SpanID   uint64            `json:"span_id"`
	Flags    uint64            `json:"flags"`
	Baggage  map[string]string `json:"baggage"`
}

// ForeachBaggageItem implements the opentracing.Tracer interface.
func (c SpanContext) ForeachBaggageItem(handler func(k, v string) bool) {
	for k, v := range c.Baggage {
		if !handler(k, v) {
			return
		}
	}
}

func textInjecter(sm SpanContext, carrier interface{}) error {
	w, ok := carrier.(opentracing.TextMapWriter)
	if !ok {
		return opentracing.ErrInvalidCarrier
	}
	w.Set("tracer-traceid", idToHex(sm.TraceID))
	w.Set("tracer-spanid", idToHex(sm.SpanID))
	w.Set("tracer-parentspanid", idToHex(sm.ParentID))
	w.Set("tracer-flags", strconv.FormatUint(sm.Flags, 10))
	for k, v := range sm.Baggage {
		w.Set("tracer-baggage-"+k, v)
	}
	return nil
}

func textExtracter(carrier interface{}) (SpanContext, error) {
	r, ok := carrier.(opentracing.TextMapReader)
	if !ok {
{'fraction_non_alphanumeric': 0.11889491859891466, 'fraction_numerical': 0.00493339911198816, 'mean_word_length': 4.54719562243502, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1623870', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1406, 'n_words': 336}