MCPcopy
hub / github.com/grafana/tempo / withInstance

Function withInstance

modules/livestore/live_store.go:921–940  ·  view source on GitHub ↗

withInstance extracts the tenant ID from the context, gets the instance, and calls the provided function if the instance exists. If the instance doesn't exist, it returns the zero value.

(ctx context.Context, s *LiveStore, fn func(*instance) (*T, error))

Source from the content-addressed store, hash-verified

919// and calls the provided function if the instance exists. If the instance
920// doesn't exist, it returns the zero value.
921func withInstance[T any](ctx context.Context, s *LiveStore, fn func(*instance) (*T, error)) (*T, error) {
922 var defaultValue T
923
924 // Check readiness before processing query
925 if err := s.CheckReady(ctx); err != nil {
926 return &defaultValue, err
927 }
928
929 instanceID, err := validation.ExtractValidTenantID(ctx)
930 if err != nil {
931 return &defaultValue, err
932 }
933
934 inst, found := s.getInstance(instanceID)
935 if inst == nil || !found {
936 return &defaultValue, nil
937 }
938
939 return fn(inst)
940}

Callers 7

FindTraceByIDMethod · 0.85
SearchRecentMethod · 0.85
SearchTagsMethod · 0.85
SearchTagsV2Method · 0.85
SearchTagValuesMethod · 0.85
SearchTagValuesV2Method · 0.85
QueryRangeMethod · 0.85

Calls 3

ExtractValidTenantIDFunction · 0.92
CheckReadyMethod · 0.45
getInstanceMethod · 0.45

Tested by

no test coverage detected