From 14c3069a5a6543e092c953a7875737de77f3ad1d Mon Sep 17 00:00:00 2001 From: Jared Tan Date: Sun, 25 Aug 2024 18:47:31 +0800 Subject: [PATCH] update db sysystem filter Signed-off-by: Jared Tan --- connector/slowsqlconnector/config.go | 2 ++ connector/slowsqlconnector/connector_logs.go | 6 ++++-- connector/slowsqlconnector/factory.go | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/connector/slowsqlconnector/config.go b/connector/slowsqlconnector/config.go index c2ba5efedde8..f54d681a2048 100644 --- a/connector/slowsqlconnector/config.go +++ b/connector/slowsqlconnector/config.go @@ -23,6 +23,8 @@ type Exemplars struct { type Config struct { // Threshold of slow sql. unit is seconds, default 1s. Threshold float64 `mapstructure:"threshold"` + // Filter specific db systems, default "h2", "mongodb", "mssql", "mysql", "oracle", "progress", "postgresql", "mariadb", ref: https://opentelemetry.io/docs/specs/semconv/attributes-registry/db/ + DBSystem []string `mapstructure:"db_system"` // Dimensions defines the list of additional dimensions on top of the provided: // - service.name // - span.name diff --git a/connector/slowsqlconnector/connector_logs.go b/connector/slowsqlconnector/connector_logs.go index 8d37a87d1b05..baeae2df7a45 100644 --- a/connector/slowsqlconnector/connector_logs.go +++ b/connector/slowsqlconnector/connector_logs.go @@ -71,8 +71,10 @@ func (c *logsConnector) ConsumeTraces(ctx context.Context, traces ptrace.Traces) case ptrace.SpanKindClient: // through db.Statement exists represents db client if _, dbSystem := findAttributeValue(dbSystemKey, span.Attributes()); dbSystem { - if spanDuration(span) >= c.config.Threshold { - c.attrToLogRecord(sl, serviceName, span, resourceAttr) + for _, db := range c.config.DBSystem { + if db == getValue(span.Attributes(), dbSystemKey) && spanDuration(span) >= c.config.Threshold { + c.attrToLogRecord(sl, serviceName, span, resourceAttr) + } } } } diff --git a/connector/slowsqlconnector/factory.go b/connector/slowsqlconnector/factory.go index e8d46738eb57..4b748b04b03b 100644 --- a/connector/slowsqlconnector/factory.go +++ b/connector/slowsqlconnector/factory.go @@ -27,6 +27,7 @@ func NewFactory() connector.Factory { func createDefaultConfig() component.Config { return &Config{ Threshold: 1, + DBSystem: []string{"h2", "mongodb", "mssql", "mysql", "oracle", "progress", "postgresql", "mariadb"}, Dimensions: []Dimension{}, } }