Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

2.1 KB
Raw Blame
package telemetrymetadata

import (
	"strconv"
	"strings"

	"github.com/SigNoz/signoz/pkg/telemetryschema/tracestelemetryschema"
	"github.com/SigNoz/signoz/pkg/types/telemetrytypes"
)

// boolFieldValues is the suggestion set for a bool field, optionally narrowed
// by the search text.
func boolFieldValues(searchText string) *telemetrytypes.TelemetryFieldValues {
	values := &telemetrytypes.TelemetryFieldValues{}
	needle := strings.ToLower(searchText)
	for _, v := range []bool{true, false} {
		if needle == "" || strings.Contains(strconv.FormatBool(v), needle) {
			values.BoolValues = append(values.BoolValues, v)
		}
	}
	return values
}

// spanSearchScopeFieldValues is the suggestion set for a search-scope selector
// (isRoot, isEntryPoint), which only filters with true. ok is false for any
// other name.
func spanSearchScopeFieldValues(name, searchText string) (*telemetrytypes.TelemetryFieldValues, bool) {
	for scopeName := range tracestelemetryschema.SpanSearchScopeFields {
		if !strings.EqualFold(scopeName, name) {
			continue
		}
		values := &telemetrytypes.TelemetryFieldValues{}
		if needle := strings.ToLower(searchText); needle == "" || strings.Contains("true", needle) {
			values.BoolValues = []bool{true}
		}
		return values, true
	}
	return nil, false
}

// isKnownBoolField is true when the caller asked for the bool data type, or
// when the name is one of the signal's static bool fields and the requested
// context does not rule that static field out.
func isKnownBoolField(selector *telemetrytypes.FieldValueSelector, staticFields ...map[string]telemetrytypes.TelemetryFieldKey) bool {
	if selector.FieldDataType == telemetrytypes.FieldDataTypeBool {
		return true
	}
	if selector.FieldDataType != telemetrytypes.FieldDataTypeUnspecified {
		return false
	}
	for _, fields := range staticFields {
		field, ok := fields[selector.Name]
		if !ok || field.FieldDataType != telemetrytypes.FieldDataTypeBool {
			continue
		}
		if selector.FieldContext == telemetrytypes.FieldContextUnspecified || selector.FieldContext == field.FieldContext {
			return true
		}
	}
	return false
}