mirror of
https://gitee.com/johng/gf
synced 2026-07-04 21:03:13 +08:00
Apply gci import order changes
This commit is contained in:
@ -70,7 +70,7 @@ type ConfigNode struct {
|
||||
// Otel specifies the OpenTelemetry tracing configuration
|
||||
// Optional field
|
||||
Otel otel.Config `json:"otel"`
|
||||
|
||||
|
||||
// OtelTraceSQLEnabled enables OpenTelemetry tracing for SQL operations
|
||||
// Deprecated: Use Otel.TraceSQLEnabled instead. This field is kept for backward compatibility.
|
||||
// Optional field
|
||||
|
||||
@ -81,11 +81,11 @@ func (c *Core) traceSpanEnd(ctx context.Context, span trace.Span, sql *Sql) {
|
||||
}
|
||||
}
|
||||
events = append(events, attribute.String(traceEventDbExecutionType, string(sql.Type)))
|
||||
|
||||
|
||||
// Add SQL statement to tracing if enabled
|
||||
if c.db.GetConfig().IsOtelTraceSQLEnabled() {
|
||||
events = append(events, attribute.String(traceEventDbExecutionSQL, sql.Format))
|
||||
}
|
||||
|
||||
|
||||
span.AddEvent(traceEventDbExecution, trace.WithAttributes(events...))
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ func Test_OTEL_SQLTracing_Default(t *testing.T) {
|
||||
Type: "sqlite",
|
||||
Name: ":memory:",
|
||||
}
|
||||
|
||||
|
||||
// By default, SQL tracing should be disabled
|
||||
t.Assert(config.IsOtelTraceSQLEnabled(), false)
|
||||
t.Assert(config.OtelTraceSQLEnabled, false)
|
||||
@ -31,11 +31,11 @@ func Test_OTEL_SQLTracing_Default(t *testing.T) {
|
||||
func Test_OTEL_SQLTracing_Configuration(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
config := gdb.ConfigNode{
|
||||
Type: "sqlite",
|
||||
Name: ":memory:",
|
||||
Type: "sqlite",
|
||||
Name: ":memory:",
|
||||
OtelTraceSQLEnabled: true,
|
||||
}
|
||||
|
||||
|
||||
// SQL tracing should be configurable using legacy field
|
||||
t.Assert(config.IsOtelTraceSQLEnabled(), true)
|
||||
t.Assert(config.OtelTraceSQLEnabled, true)
|
||||
@ -52,7 +52,7 @@ func Test_OTEL_SQLTracing_NewConfiguration(t *testing.T) {
|
||||
TraceSQLEnabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
// SQL tracing should be configurable using new configuration
|
||||
t.Assert(config.IsOtelTraceSQLEnabled(), true)
|
||||
t.Assert(config.OtelTraceSQLEnabled, false)
|
||||
@ -63,11 +63,11 @@ func Test_OTEL_SQLTracing_NewConfiguration(t *testing.T) {
|
||||
func Test_OTEL_SQLTracing_Enabled(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
config := gdb.ConfigNode{
|
||||
Type: "mysql",
|
||||
Name: "test_db",
|
||||
Type: "mysql",
|
||||
Name: "test_db",
|
||||
OtelTraceSQLEnabled: true,
|
||||
}
|
||||
|
||||
|
||||
// Test that the configuration field can be set and retrieved using legacy field
|
||||
t.Assert(config.IsOtelTraceSQLEnabled(), true)
|
||||
})
|
||||
@ -76,15 +76,15 @@ func Test_OTEL_SQLTracing_Enabled(t *testing.T) {
|
||||
func Test_OTEL_SQLTracing_BothFieldsEnabled(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
config := gdb.ConfigNode{
|
||||
Type: "mysql",
|
||||
Name: "test_db",
|
||||
Type: "mysql",
|
||||
Name: "test_db",
|
||||
OtelTraceSQLEnabled: false,
|
||||
Otel: otel.Config{
|
||||
TraceSQLEnabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
// New field should take precedence over legacy field
|
||||
t.Assert(config.IsOtelTraceSQLEnabled(), true)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user