Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[processor/servicegraphprocessor] Add Configurable Database Name Attribute #30726

Merged
3 changes: 3 additions & 0 deletions processor/servicegraphprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ The following settings can be optionally configured:
- `virtual_node_peer_attributes`: the list of attributes need to match for building virtual server node, the higher the front, the higher the priority.
- Default: `[db.name, net.sock.peer.addr, net.peer.name, rpc.service, net.sock.peer.name, net.peer.name, http.url, http.target]`
- `metrics_flush_interval`: the interval at which metrics are flushed to the exporter. Metrics are flush on every received batch of traces by default.
- `database_name_attribute`: the attribute name used to identify the database name from span attributes.
- Default: `db.name`

## Example configuration

Expand All @@ -153,6 +155,7 @@ processors:
virtual_node_peer_attributes:
- db.name
- rpc.service
database_name_attribute: db.name
exporters:
prometheus/servicegraph:
endpoint: localhost:9090
Expand Down
4 changes: 4 additions & 0 deletions processor/servicegraphprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ type Config struct {
// MetricsFlushInterval is the interval at which metrics are flushed to the exporter.
// If set to 0, metrics are flushed on every received batch of traces.
MetricsFlushInterval time.Duration `mapstructure:"metrics_flush_interval"`

// DatabaseNameAttribute is the attribute name used to identify the database name from span attributes.
// The default value is db.name.
DatabaseNameAttribute string `mapstructure:"database_name_attribute"`
}

type StoreConfig struct {
Expand Down
6 changes: 4 additions & 2 deletions processor/servicegraphprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestLoadConfig(t *testing.T) {
CacheLoop: 2 * time.Minute,
StoreExpirationLoop: 10 * time.Second,
VirtualNodePeerAttributes: []string{"db.name", "rpc.service"},
DatabaseNameAttribute: "net.peer.name",
},
cfg.Processors[component.NewID(metadata.Type)],
)
Expand All @@ -59,8 +60,9 @@ func TestLoadConfig(t *testing.T) {
TTL: time.Second,
MaxItems: 10,
},
CacheLoop: time.Minute,
StoreExpirationLoop: 2 * time.Second,
CacheLoop: time.Minute,
StoreExpirationLoop: 2 * time.Second,
DatabaseNameAttribute: "db.name",
},
cfg.Connectors[component.NewID(metadata.Type)],
)
Expand Down
8 changes: 7 additions & 1 deletion processor/servicegraphprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ var (
defaultPeerAttributes = []string{
semconv.AttributeDBName, semconv.AttributeNetSockPeerAddr, semconv.AttributeNetPeerName, semconv.AttributeRPCService, semconv.AttributeNetSockPeerName, semconv.AttributeNetPeerName, semconv.AttributeHTTPURL, semconv.AttributeHTTPTarget,
}

defaultDatabaseNameAttribute = semconv.AttributeDBName
)

type metricSeries struct {
Expand Down Expand Up @@ -108,6 +110,10 @@ func newProcessor(set component.TelemetrySettings, config component.Config) *ser
pConfig.VirtualNodePeerAttributes = defaultPeerAttributes
}

if pConfig.DatabaseNameAttribute == "" {
pConfig.DatabaseNameAttribute = defaultDatabaseNameAttribute
}

meter := metadata.Meter(set)

droppedSpan, _ := meter.Int64Counter(
Expand Down Expand Up @@ -298,7 +304,7 @@ func (p *serviceGraphProcessor) aggregateMetrics(ctx context.Context, td ptrace.

// A database request will only have one span, we don't wait for the server
// span but just copy details from the client span
if dbName, ok := findAttributeValue(semconv.AttributeDBName, rAttributes, span.Attributes()); ok {
if dbName, ok := findAttributeValue(p.config.DatabaseNameAttribute, rAttributes, span.Attributes()); ok {
e.ConnectionType = store.Database
e.ServerService = dbName
e.ServerLatencySec = spanDuration(span)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ processors:
virtual_node_peer_attributes:
- db.name
- rpc.service
database_name_attribute: net.peer.name

service:
pipelines:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ connectors:
store:
ttl: 1s
max_items: 10
database_name_attribute: db.name

service:
pipelines:
Expand Down
Loading