Skip to content
2 changes: 1 addition & 1 deletion devdocs/config/CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Attributes configures the decoration of some extra attributes that will be added
| `attributes.rename_unresolved_hosts` | `string` | `OTEL_EBPF_RENAME_UNRESOLVED_HOSTS` | `unresolved` | | | Will replace HostName and PeerName attributes when they are empty or contain unresolved IP addresses to reduce cardinality. Set this value to the empty string to disable this feature. |
| `attributes.rename_unresolved_hosts_incoming` | `string` | `OTEL_EBPF_RENAME_UNRESOLVED_HOSTS_INCOMING` | `incoming` | | | |
| `attributes.rename_unresolved_hosts_outgoing` | `string` | `OTEL_EBPF_RENAME_UNRESOLVED_HOSTS_OUTGOING` | `outgoing` | | | |
| `attributes.select` | `map[string]object` | | | | | Selection specifies which attributes are allowed for each metric. The key is the metric name (either in Prometheus or OpenTelemetry format) The value is the enumeration of included/excluded attribute globs |
| `attributes.select` | `map[string]object` | | | | | Selection specifies which attributes are allowed for each signal. The key is usually the metric name (either in Prometheus or OpenTelemetry format); the key "traces" selects optional attributes for exported OTLP traces. The value is the enumeration of included/excluded attribute globs |

### `attributes.host_id`

Expand Down
2 changes: 1 addition & 1 deletion devdocs/config/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2516,7 +2516,7 @@
"$ref": "#/$defs/InclusionLists"
},
"type": "object",
"description": "Selection specifies which attributes are allowed for each metric. The key is the metric name (either in Prometheus or OpenTelemetry format) The value is the enumeration of included/excluded attribute globs"
"description": "Selection specifies which attributes are allowed for each signal. The key is usually the metric name (either in Prometheus or OpenTelemetry format); the key \"traces\" selects optional attributes for exported OTLP traces. The value is the enumeration of included/excluded attribute globs"
},
"StatsConfig": {
"properties": {
Expand Down
6 changes: 3 additions & 3 deletions pkg/appolly/app/request/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func TestSpanStatusMessage_DBResponseErrorOptional(t *testing.T) {
Status: 1,
DBError: DBError{ErrorCode: "WRONGTYPE", Description: "WRONGTYPE Operation against a key holding the wrong kind of value"},
},
expectedDefault: attributes.DBErrorMessagePlaceholder,
expectedDefault: "",
expectedAllowed: "WRONGTYPE Operation against a key holding the wrong kind of value",
},
{
Expand All @@ -344,7 +344,7 @@ func TestSpanStatusMessage_DBResponseErrorOptional(t *testing.T) {
Status: 1,
SQLError: &SQLError{Code: 8, SQLState: "ABC", Message: "SQL error message"},
},
expectedDefault: attributes.DBErrorMessagePlaceholder,
expectedDefault: "",
expectedAllowed: "SQL Server errored: error_code=8 sql_state=ABC message=SQL error message",
},
{
Expand All @@ -355,7 +355,7 @@ func TestSpanStatusMessage_DBResponseErrorOptional(t *testing.T) {
Status: 1,
DBError: DBError{ErrorCode: "12003", Description: "Keyspace not found in CB datastore"},
},
expectedDefault: attributes.DBErrorMessagePlaceholder,
expectedDefault: "",
expectedAllowed: "Keyspace not found in CB datastore",
},
{
Expand Down
10 changes: 4 additions & 6 deletions pkg/export/attributes/attr_defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,17 +525,15 @@ func AllAttributeNames(
return names
}

const (
DBErrorMessagePlaceholder = "enable the db.response.error attribute for details"
)

// DBResponseErrorAttr returns a database response error attribute or a placeholder if the attribute is not selected
// DBResponseErrorAttr returns a database response error attribute if the attribute is selected, nil otherwise.
// When the attribute is not selected, it is simply omitted — consistent with how other optional
// attributes (e.g. db.query.text) behave.
func DBResponseErrorAttr(optionalAttrs map[attr.Name]struct{}, description string) []attribute.KeyValue {
if description == "" {
return nil
}
if _, ok := optionalAttrs[attr.DBResponseError]; !ok {
return []attribute.KeyValue{attribute.Key(attr.DBResponseError).String(DBErrorMessagePlaceholder)}
return nil
}
return []attribute.KeyValue{attribute.Key(attr.DBResponseError).String(description)}
}
5 changes: 3 additions & 2 deletions pkg/export/attributes/attr_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
attr "go.opentelemetry.io/obi/pkg/export/attributes/names"
)

// Selection specifies which attributes are allowed for each metric.
// The key is the metric name (either in Prometheus or OpenTelemetry format)
// Selection specifies which attributes are allowed for each signal.
// The key is usually the metric name (either in Prometheus or OpenTelemetry format);
// the key "traces" selects optional attributes for exported OTLP traces.
// The value is the enumeration of included/excluded attribute globs
type Selection map[Section]InclusionLists

Expand Down
10 changes: 5 additions & 5 deletions pkg/export/otel/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func TestGenerateTracesAttributes(t *testing.T) {
attrs := spans.At(0).Attributes()
status := spans.At(0).Status()
assert.Equal(t, ptrace.StatusCodeError, status.Code())
assert.Equal(t, attributes.DBErrorMessagePlaceholder, status.Message())
assert.Empty(t, status.Message())

assert.Equal(t, 9, attrs.Len())

Expand Down Expand Up @@ -533,7 +533,7 @@ func TestGenerateTracesAttributes(t *testing.T) {
ensureTraceAttrNotExists(t, attrs, attribute.Key(attr.DBQueryText))
ensureTraceAttrNotExists(t, attrs, attribute.Key(attr.DBResponseError))
assert.Equal(t, ptrace.StatusCodeError, spans.At(0).Status().Code())
assert.Equal(t, attributes.DBErrorMessagePlaceholder, spans.At(0).Status().Message())
assert.Empty(t, spans.At(0).Status().Message())
})
t.Run("test Couchbase trace generation", func(t *testing.T) {
span := request.Span{Type: request.EventTypeCouchbaseClient, Method: "GET", Path: "mycollection", DBNamespace: "mybucket.myscope", Status: 0}
Expand Down Expand Up @@ -582,7 +582,7 @@ func TestGenerateTracesAttributes(t *testing.T) {
ensureTraceAttrNotExists(t, attrs, attribute.Key(attr.DBQueryText))
ensureTraceAttrNotExists(t, attrs, attribute.Key(attr.DBResponseError))
assert.Equal(t, ptrace.StatusCodeError, spans.At(0).Status().Code())
assert.Equal(t, attributes.DBErrorMessagePlaceholder, spans.At(0).Status().Message())
assert.Empty(t, spans.At(0).Status().Message())
})
t.Run("test Couchbase trace generation with db.query.text", func(t *testing.T) {
span := request.Span{
Expand Down Expand Up @@ -679,7 +679,7 @@ func TestGenerateTracesAttributes(t *testing.T) {
ensureTraceAttrNotExists(t, attrs, semconv.PeerServiceKey)
ensureTraceAttrNotExists(t, attrs, attribute.Key(attr.DBResponseError))
assert.Equal(t, ptrace.StatusCodeError, spans.At(0).Status().Code())
assert.Equal(t, attributes.DBErrorMessagePlaceholder, spans.At(0).Status().Message())
assert.Empty(t, spans.At(0).Status().Message())
})
t.Run("test SQL++ trace generation", func(t *testing.T) {
span := request.Span{
Expand Down Expand Up @@ -789,7 +789,7 @@ func TestGenerateTracesAttributes(t *testing.T) {
ensureTraceStrAttr(t, attrs, attribute.Key(attr.DBResponseStatusCode), "12003")
ensureTraceAttrNotExists(t, attrs, attribute.Key(attr.DBResponseError))
assert.Equal(t, ptrace.StatusCodeError, spans.At(0).Status().Code())
assert.Equal(t, attributes.DBErrorMessagePlaceholder, spans.At(0).Status().Message())
assert.Empty(t, spans.At(0).Status().Message())
})
t.Run("test SQL++ trace generation with minimal attributes", func(t *testing.T) {
span := request.Span{
Expand Down