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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
fix: enable opamp for llmpricing/spanmmapper and remove unit from config (#11285)
Nityananda Gohain8040f222ad8b
diff --git a/ee/query-service/app/server.go b/ee/query-service/app/server.goindex a4f1d16046..028f309576 100644--- a/ee/query-service/app/server.go+++ b/ee/query-service/app/server.go@@ -90,8 +90,12 @@ func NewServer(config signoz.Config, signoz *signoz.SigNoz) (*Server, error) {// initiate agent config handleragentConfMgr, err := agentConf.Initiate(&agentConf.ManagerOptions{- Store: signoz.SQLStore,- AgentFeatures: []agentConf.AgentFeature{logParsingPipelineController},+ Store: signoz.SQLStore,+ AgentFeatures: []agentConf.AgentFeature{+ logParsingPipelineController,+ signoz.Modules.SpanMapper,+ signoz.Modules.LLMPricingRule,+ },})if err != nil {return nil, errdiff --git a/pkg/modules/llmpricingrule/impllmpricingrule/module.go b/pkg/modules/llmpricingrule/impllmpricingrule/module.goindex fce804cb56..83c00e59e7 100644--- a/pkg/modules/llmpricingrule/impllmpricingrule/module.go+++ b/pkg/modules/llmpricingrule/impllmpricingrule/module.go@@ -6,19 +6,22 @@ import ("time""github.com/SigNoz/signoz/pkg/errors"+ "github.com/SigNoz/signoz/pkg/flagger""github.com/SigNoz/signoz/pkg/modules/llmpricingrule""github.com/SigNoz/signoz/pkg/query-service/agentConf"+ "github.com/SigNoz/signoz/pkg/types/featuretypes""github.com/SigNoz/signoz/pkg/types/llmpricingruletypes""github.com/SigNoz/signoz/pkg/types/opamptypes""github.com/SigNoz/signoz/pkg/valuer")type module struct {- store llmpricingruletypes.Store+ store llmpricingruletypes.Store+ flagger flagger.Flagger}-func NewModule(store llmpricingruletypes.Store) llmpricingrule.Module {- return &module{store: store}+func NewModule(store llmpricingruletypes.Store, flagger flagger.Flagger) llmpricingrule.Module {+ return &module{store: store, flagger: flagger}}func (module *module) List(ctx context.Context, orgID valuer.UUID, offset, limit int, search string, isOverride *bool) ([]*llmpricingruletypes.LLMPricingRule, int, error) {@@ -89,6 +92,16 @@ func (module *module) AgentFeatureType() agentConf.AgentFeatureType {func (module *module) RecommendAgentConfig(orgID valuer.UUID, currentConfYaml []byte, configVersion *opamptypes.AgentConfigVersion) ([]byte, string, error) {ctx := context.Background()+ // Skip the llm pricing processor unless AI observability is enabled for the org.+ evalCtx := featuretypes.NewFlaggerEvaluationContext(orgID)+ enabled, err := module.flagger.Boolean(ctx, flagger.FeatureEnableAIObservability, evalCtx)+ if err != nil {+ return nil, "", err+ }+ if !enabled {+ return currentConfYaml, "", nil+ }+rules, err := module.getEnabledRules(ctx, orgID)if err != nil {return nil, "", errdiff --git a/pkg/modules/spanmapper/implspanmapper/module.go b/pkg/modules/spanmapper/implspanmapper/module.goindex 0ab4536991..16c5da5ff2 100644--- a/pkg/modules/spanmapper/implspanmapper/module.go+++ b/pkg/modules/spanmapper/implspanmapper/module.go@@ -4,19 +4,22 @@ import ("context""encoding/json"+ "github.com/SigNoz/signoz/pkg/flagger""github.com/SigNoz/signoz/pkg/modules/spanmapper""github.com/SigNoz/signoz/pkg/query-service/agentConf"+ "github.com/SigNoz/signoz/pkg/types/featuretypes""github.com/SigNoz/signoz/pkg/types/opamptypes""github.com/SigNoz/signoz/pkg/types/spantypes""github.com/SigNoz/signoz/pkg/valuer")type module struct {- store spantypes.SpanMapperStore+ store spantypes.SpanMapperStore+ flagger flagger.Flagger}-func NewModule(store spantypes.SpanMapperStore) spanmapper.Module {- return &module{store: store}+func NewModule(store spantypes.SpanMapperStore, flagger flagger.Flagger) spanmapper.Module {+ return &module{store: store, flagger: flagger}}func (module *module) ListGroups(ctx context.Context, orgID valuer.UUID, q *spantypes.ListSpanMapperGroupsQuery) ([]*spantypes.SpanMapperGroup, error) {@@ -109,12 +112,22 @@ func (module *module) AgentFeatureType() agentConf.AgentFeatureType {func (module *module) RecommendAgentConfig(orgID valuer.UUID, currentConfYaml []byte, configVersion *opamptypes.AgentConfigVersion) ([]byte, string, error) {ctx := context.Background()- enabled, err := module.listEnabledGroupsWithMappers(ctx, orgID)+ // Skip the llm pricing processor unless AI observability is enabled for the org.+ evalCtx := featuretypes.NewFlaggerEvaluationContext(orgID)+ enabled, err := module.flagger.Boolean(ctx, flagger.FeatureEnableAIObservability, evalCtx)+ if err != nil {+ return nil, "", err+ }+ if !enabled {+ return currentConfYaml, "", nil+ }++ enabledMappers, err := module.listEnabledGroupsWithMappers(ctx, orgID)if err != nil {return nil, "", err}- updatedConf, err := spantypes.GenerateCollectorConfigWithSpanMapperProcessor(currentConfYaml, enabled)+ updatedConf, err := spantypes.GenerateCollectorConfigWithSpanMapperProcessor(currentConfYaml, enabledMappers)if err != nil {return nil, "", err}diff --git a/pkg/query-service/app/server.go b/pkg/query-service/app/server.goindex 8ef4c59bb4..0a22827f43 100644--- a/pkg/query-service/app/server.go+++ b/pkg/query-service/app/server.go@@ -113,6 +113,8 @@ func NewServer(config signoz.Config, signoz *signoz.SigNoz) (*Server, error) {Store: signoz.SQLStore,AgentFeatures: []agentConf.AgentFeature{logParsingPipelineController,+ signoz.Modules.SpanMapper,+ signoz.Modules.LLMPricingRule,},},)diff --git a/pkg/signoz/module.go b/pkg/signoz/module.goindex 53f796084e..054c99b5af 100644--- a/pkg/signoz/module.go+++ b/pkg/signoz/module.go@@ -154,8 +154,8 @@ func NewModules(RuleStateHistory: implrulestatehistory.NewModule(implrulestatehistory.NewStore(telemetryStore, telemetryMetadataStore, providerSettings.Logger)),CloudIntegration: cloudIntegrationModule,TraceDetail: impltracedetail.NewModule(impltracedetail.NewTraceStore(telemetryStore), providerSettings, config.TraceDetail),- SpanMapper: implspanmapper.NewModule(implspanmapper.NewStore(sqlstore)),- LLMPricingRule: impllmpricingrule.NewModule(impllmpricingrule.NewStore(sqlstore)),+ SpanMapper: implspanmapper.NewModule(implspanmapper.NewStore(sqlstore), fl),+ LLMPricingRule: impllmpricingrule.NewModule(impllmpricingrule.NewStore(sqlstore), fl),Tag: tagModule,}}diff --git a/pkg/types/llmpricingruletypes/pricing.go b/pkg/types/llmpricingruletypes/pricing.goindex 141020e4a7..d3f8637995 100644--- a/pkg/types/llmpricingruletypes/pricing.go+++ b/pkg/types/llmpricingruletypes/pricing.go@@ -53,7 +53,8 @@ var (LLMPricingRuleCacheModeSubtract = LLMPricingRuleCacheMode{valuer.NewString("subtract")}// LLMPricingRuleCacheModeAdditive: cached tokens are reported separately (Anthropic-style).LLMPricingRuleCacheModeAdditive = LLMPricingRuleCacheMode{valuer.NewString("additive")}- // LLMPricingRuleCacheModeUnknown: provider behaviour is unknown; falls back to subtract.+ // LLMPricingRuleCacheModeUnknown: provider behaviour is unknown. buildProcessorConfig+ // normalizes this to an empty mode in the collector config.LLMPricingRuleCacheModeUnknown = LLMPricingRuleCacheMode{valuer.NewString("unknown")})diff --git a/pkg/types/llmpricingruletypes/processorconfig.go b/pkg/types/llmpricingruletypes/processorconfig.goindex 5b86509223..0278b537ed 100644--- a/pkg/types/llmpricingruletypes/processorconfig.go+++ b/pkg/types/llmpricingruletypes/processorconfig.go@@ -26,24 +26,23 @@ type LLMPricingRuleProcessorAttrs struct {CacheWrite string `yaml:"cache_write" json:"cache_write"`}-// LLMPricingRuleProcessorDefaultPricing holds the pricing unit and the list of model-specific rules.+// LLMPricingRuleProcessorDefaultPricing holds the list of model-specific rules.type LLMPricingRuleProcessorDefaultPricing struct {- Unit string `yaml:"unit" json:"unit"`Rules []LLMPricingRuleProcessor `yaml:"rules" json:"rules"`}// LLMPricingRuleProcessor is a single pricing rule inside the processor config.type LLMPricingRuleProcessor struct {- Name string `yaml:"name" json:"name"`- Pattern []string `yaml:"pattern" json:"pattern"`- Cache LLMPricingRuleProcessorCache `yaml:"cache" json:"cache"`- In float64 `yaml:"in" json:"in"`- Out float64 `yaml:"out" json:"out"`+ Name string `yaml:"name" json:"name"`+ Pattern []string `yaml:"pattern" json:"pattern"`+ Cache *LLMPricingRuleProcessorCache `yaml:"cache,omitempty" json:"cache,omitempty"`+ In float64 `yaml:"in" json:"in"`+ Out float64 `yaml:"out" json:"out"`}// LLMPricingRuleProcessorCache describes how cached tokens are accounted for.type LLMPricingRuleProcessorCache struct {- Mode string `yaml:"mode" json:"mode"`+ Mode string `yaml:"mode,omitempty" json:"mode,omitempty"`Read float64 `yaml:"read" json:"read"`Write float64 `yaml:"write" json:"write"`}@@ -61,10 +60,14 @@ type LLMPricingRuleProcessorOutputAttrs struct {func buildProcessorConfig(rules []*LLMPricingRule) *LLMPricingRuleProcessorConfig {pricingRules := make([]LLMPricingRuleProcessor, 0, len(rules))for _, r := range rules {- var cache LLMPricingRuleProcessorCache+ var cache *LLMPricingRuleProcessorCacheif r.Pricing.Cache != nil {- cache = LLMPricingRuleProcessorCache{- Mode: r.Pricing.Cache.Mode.StringValue(),+ mode := r.Pricing.Cache.Mode.StringValue()+ if mode != LLMPricingRuleCacheModeSubtract.StringValue() && mode != LLMPricingRuleCacheModeAdditive.StringValue() {+ mode = ""+ }+ cache = &LLMPricingRuleProcessorCache{+ Mode: mode,Read: r.Pricing.Cache.Read,Write: r.Pricing.Cache.Write,}@@ -87,7 +90,6 @@ func buildProcessorConfig(rules []*LLMPricingRule) *LLMPricingRuleProcessorConfiCacheWrite: GenAIUsageCacheCreationInputTokens,},DefaultPricing: LLMPricingRuleProcessorDefaultPricing{- Unit: UnitPerMillionTokens.StringValue(),Rules: pricingRules,},OutputAttrs: LLMPricingRuleProcessorOutputAttrs{diff --git a/pkg/types/llmpricingruletypes/processorconfig_test.go b/pkg/types/llmpricingruletypes/processorconfig_test.goindex d5e1fe6b35..04819b708d 100644--- a/pkg/types/llmpricingruletypes/processorconfig_test.go+++ b/pkg/types/llmpricingruletypes/processorconfig_test.go@@ -41,6 +41,16 @@ func makePricingRule(model string, patterns []string, cacheMode LLMPricingRuleCa}}+func makePricingRuleNoCache(model string, patterns []string, costIn, costOut float64) *LLMPricingRule {+ return &LLMPricingRule{+ Model: model,+ ModelPattern: StringSlice(patterns),+ Unit: UnitPerMillionTokens,+ Pricing: LLMRulePricing{Input: costIn, Output: costOut},+ Enabled: true,+ }+}+func TestGenerateCollectorConfigWithLLMPricingProcessor(t *testing.T) {tests := []struct {name string@@ -62,6 +72,24 @@ func TestGenerateCollectorConfigWithLLMPricingProcessor(t *testing.T) {rules: nil,expectedFile: "collector_no_rules.yaml",},+ // A rule without cache pricing omits the cache block entirely so the+ // collector does not apply any cache cost.+ {+ name: "rule_without_cache",+ rules: []*LLMPricingRule{+ makePricingRuleNoCache("gpt-4o", []string{"gpt-4o*"}, 5.0, 15.0),+ },+ expectedFile: "collector_rule_without_cache.yaml",+ },+ // An unknown cache mode still emits the cache block (with prices) but omits+ // the mode field; the collector handles a missing mode in its default branch.+ {+ name: "rule_cache_mode_unknown",+ rules: []*LLMPricingRule{+ makePricingRule("gpt-4o", []string{"gpt-4o*"}, LLMPricingRuleCacheModeUnknown, 5.0, 15.0, 2.5, 0),+ },+ expectedFile: "collector_rule_cache_mode_unknown.yaml",+ },}input, err := os.ReadFile(filepath.Join("testdata", "collector_baseline.yaml"))diff --git a/pkg/types/llmpricingruletypes/testdata/collector_baseline.yaml b/pkg/types/llmpricingruletypes/testdata/collector_baseline.yamlindex 342b0a84dc..578ef4d5f5 100644--- a/pkg/types/llmpricingruletypes/testdata/collector_baseline.yaml+++ b/pkg/types/llmpricingruletypes/testdata/collector_baseline.yaml@@ -11,7 +11,6 @@ processors:cache_read: gen_ai.usage.cache_read.input_tokenscache_write: gen_ai.usage.cache_creation.input_tokensdefault_pricing:- unit: per_million_tokensrules: []output_attrs:in: _signoz.gen_ai.cost_inputdiff --git a/pkg/types/llmpricingruletypes/testdata/collector_no_rules.yaml b/pkg/types/llmpricingruletypes/testdata/collector_no_rules.yamlindex 0c2c73bc96..f685c5ad79 100644--- a/pkg/types/llmpricingruletypes/testdata/collector_no_rules.yaml+++ b/pkg/types/llmpricingruletypes/testdata/collector_no_rules.yaml@@ -11,7 +11,6 @@ processors:cache_read: gen_ai.usage.cache_read.input_tokenscache_write: gen_ai.usage.cache_creation.input_tokensdefault_pricing:- unit: per_million_tokensrules: []output_attrs:in: _signoz.gen_ai.cost_inputdiff --git a/pkg/types/llmpricingruletypes/testdata/collector_rule_cache_mode_unknown.yaml b/pkg/types/llmpricingruletypes/testdata/collector_rule_cache_mode_unknown.yamlnew file mode 100644index 0000000000..4cca9f64d9--- /dev/null+++ b/pkg/types/llmpricingruletypes/testdata/collector_rule_cache_mode_unknown.yaml@@ -0,0 +1,42 @@+exporters:+ otlp:+ endpoint: localhost:4317+processors:+ batch: {}+ signozllmpricing:+ attrs:+ model: gen_ai.request.model+ in: gen_ai.usage.input_tokens+ out: gen_ai.usage.output_tokens+ cache_read: gen_ai.usage.cache_read.input_tokens+ cache_write: gen_ai.usage.cache_creation.input_tokens+ default_pricing:+ rules:+ - name: gpt-4o+ pattern:+ - gpt-4o*+ cache:+ read: 2.5+ write: 0+ in: 5+ out: 15+ output_attrs:+ in: _signoz.gen_ai.cost_input+ out: _signoz.gen_ai.cost_output+ cache_read: _signoz.gen_ai.cost_cache_read+ cache_write: _signoz.gen_ai.cost_cache_write+ total: _signoz.gen_ai.total_cost+receivers:+ otlp:+ protocols:+ grpc: null+service:+ pipelines:+ traces:+ exporters:+ - otlp+ processors:+ - batch+ - signozllmpricing+ receivers:+ - otlpdiff --git a/pkg/types/llmpricingruletypes/testdata/collector_rule_without_cache.yaml b/pkg/types/llmpricingruletypes/testdata/collector_rule_without_cache.yamlnew file mode 100644index 0000000000..e94afc36ff--- /dev/null+++ b/pkg/types/llmpricingruletypes/testdata/collector_rule_without_cache.yaml@@ -0,0 +1,39 @@+exporters:+ otlp:+ endpoint: localhost:4317+processors:+ batch: {}+ signozllmpricing:+ attrs:+ model: gen_ai.request.model+ in: gen_ai.usage.input_tokens+ out: gen_ai.usage.output_tokens+ cache_read: gen_ai.usage.cache_read.input_tokens+ cache_write: gen_ai.usage.cache_creation.input_tokens+ default_pricing:+ rules:+ - name: gpt-4o+ pattern:+ - gpt-4o*+ in: 5+ out: 15+ output_attrs:+ in: _signoz.gen_ai.cost_input+ out: _signoz.gen_ai.cost_output+ cache_read: _signoz.gen_ai.cost_cache_read+ cache_write: _signoz.gen_ai.cost_cache_write+ total: _signoz.gen_ai.total_cost+receivers:+ otlp:+ protocols:+ grpc: null+service:+ pipelines:+ traces:+ exporters:+ - otlp+ processors:+ - batch+ - signozllmpricing+ receivers:+ - otlpdiff --git a/pkg/types/llmpricingruletypes/testdata/collector_with_rule.yaml b/pkg/types/llmpricingruletypes/testdata/collector_with_rule.yamlindex 09ec9b8ebd..5c1aa87bfa 100644--- a/pkg/types/llmpricingruletypes/testdata/collector_with_rule.yaml+++ b/pkg/types/llmpricingruletypes/testdata/collector_with_rule.yaml@@ -11,7 +11,6 @@ processors:cache_read: gen_ai.usage.cache_read.input_tokenscache_write: gen_ai.usage.cache_creation.input_tokensdefault_pricing:- unit: per_million_tokensrules:- name: gpt-4opattern: