Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions CI-PLAN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# CI Failure Analysis Plan

## Failed Jobs Summary
- Job 1: common / test1 (multiple Java versions) (job IDs: 57490440498, 57490440505, 57490440450, 57490440447, 57490440473, etc.)
- Job 2: common / test2 (multiple Java versions) (job IDs: 57490440520, 57490440521, 57490440540, 57490440566, etc.)
- Job 3: test-latest-deps / testLatestDeps1 (job ID: 57490440183)
- Job 4: test-latest-deps / testLatestDeps2 (job ID: 57490440203)

Note: All jobs with parameters in parentheses (e.g., Java version, VM, indy settings) are variations of the same base jobs.

## Unique Failed Gradle Tasks
**Note**: Spotless tasks are excluded from this analysis as they are formatting-only checks.

- [x] Task: `:instrumentation:jdbc:javaagent:testStableSemconv`
- Seen in: test1 (all Java versions), testLatestDeps1
- Log files: /tmp/test1-java17-indy-false.log, /tmp/testLatestDeps1.log
- Error: `Expected span to have name <DB Query> but was <localhost>`
- Test: `JdbcInstrumentationTest > test getClientInfo exception`
- Location: AbstractJdbcInstrumentationTest.java:1223
- Fix: Updated DbClientSpanNameExtractor to not use server address alone as span name

- [x] Task: `:instrumentation:jdbc:library:testStableSemconv`
- Seen in: test2 (all Java versions)
- Log files: /tmp/test2-java25-indy-false.log
- Error: `Expected span to have name <DB Query> but was <localhost>`
- Test: `JdbcInstrumentationTest > test getClientInfo exception`
- Location: AbstractJdbcInstrumentationTest.java:1223
- Fix: Same as above

- [x] Task: `:instrumentation:cassandra:cassandra-3.0:javaagent:testStableSemconv`
- Seen in: test1 (all Java versions), testLatestDeps1
- Log files: /tmp/test1-java17-indy-false.log, /tmp/testLatestDeps1.log
- Fix: Same as above

## Notes
The failures were all related to the db.query.summary implementation. The span name was being set to "localhost" instead of "DB Query" when SQL could not be parsed.

**Root cause**: When SQL statement cannot be parsed (e.g., "testing 123" which is not valid SQL), the sanitizer returns null for operation, collection, and querySummary. The span name logic was incorrectly falling back to server.address as the span name.

**Solution**: According to OpenTelemetry semantic conventions for database spans, `server.address` should only be used as part of the `{target}` when combined with an operation (e.g., "SELECT localhost"). When there is no operation, the fallback should be `db.system.name` or the default "DB Query" span name.

**Fix applied**: Updated `DbClientSpanNameExtractor.computeSpanNameStable()` to only use server.address when an operation is available. When no operation exists, it now properly falls back to db.system.name or "DB Query".

**Commit**: 11e7b49ed1
136 changes: 136 additions & 0 deletions DB_QUERY_SUMMARY_PROGRESS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# db.query.summary Implementation Progress

## Overview
Implementing `db.query.summary` attribute from OpenTelemetry semantic conventions.
- Format: `{operation} {target}` (e.g., "SELECT users", "INSERT orders")
- Max length: 255 characters
- Span name in stable semconv should be `db.query.summary`

## Completed Work

### 1. SqlStatementInfo.java
**File:** `instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlStatementInfo.java`

Added:
- `querySummary` field to AutoValue class
- `getQuerySummary()` method
- `truncateQuerySummary()` helper (max 255 chars, truncates at word boundary)
- Updated `create()` factory method signature

### 2. SqlSanitizer.jflex
**File:** `instrumentation-api-incubator/src/jflex/SqlSanitizer.jflex`

Added:
- `querySummaryBuilder` StringBuilder field
- `appendOperationToSummary()` - appends operation (SELECT, INSERT, etc.)
- `appendTargetToSummary()` - appends table name after operation
- Integration in lexer rules to build query summary during parsing

**Note:** After editing, regenerate with: `./gradlew :instrumentation-api-incubator:generateJflex`

### 3. SqlClientAttributesExtractor.java
**File:** `instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractor.java`

Added:
- Import for `DB_QUERY_SUMMARY`
- Sets `db.query.summary` attribute from `SqlStatementInfo.getQuerySummary()`

### 4. MultiQuery.java
**File:** `instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/MultiQuery.java`

Added:
- `querySummary` tracking for multi-statement queries
- `getQuerySummary()` method

### 5. DbClientSpanNameExtractor.java
**File:** `instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientSpanNameExtractor.java`

Updated `SqlClientSpanNameExtractor.extract()`:
- In stable semconv mode: returns `querySummary` directly as span name
- In old semconv mode: uses existing `computeSpanName(namespace, operation, mainIdentifier)`

### 6. AbstractJdbcInstrumentationTest.java
**File:** `instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/testing/AbstractJdbcInstrumentationTest.java`

Added:
- Import: `import static io.opentelemetry.semconv.DbAttributes.DB_QUERY_SUMMARY;`
- Assertion for `DB_QUERY_SUMMARY` attribute in `testBasicStatement`
- Helper method: `querySummary(String table)` - returns `"SELECT"` or `"SELECT " + table`
- Updated span name assertion for stable semconv in `testBasicStatement`

## Test Status

### Passing
- ✅ `./gradlew :instrumentation:jdbc:javaagent:test` (old semconv) - BUILD SUCCESSFUL
- ✅ `./gradlew :instrumentation:jdbc:javaagent:testStableSemconv` (stable semconv) - BUILD SUCCESSFUL (107 tests)

All JDBC tests now pass for both old and stable semconv modes.

## Completed Test Fixes

Tests updated to use conditional span names and `DB_QUERY_SUMMARY` assertions:

1. `testBasicStatement` - Initial implementation
2. `testConnectionConstructorThrowing`
3. `testStatementUpdate`
4. `testPreparedStatementQuery`
5. `testProxyStatement`
6. `testProxyPreparedStatement`
7. `testCommitTransaction`
8. `testPreparedStatementWrapper`
9. `testProduceProperSpanName`
10. `testPreparedStatementExecute`

**Pattern applied:**
```java
// Span name conditional
span.hasName(emitStableDatabaseSemconv() ? querySummary(operation, table) : oldSpanName)

// DB_QUERY_SUMMARY attribute assertion
equalTo(DB_QUERY_SUMMARY, emitStableDatabaseSemconv() ? querySummary(operation, table) : null)
```

## Previous Issue (Resolved)

Tests were failing because span names in stable semconv mode should match `db.query.summary` format:
- Old format: `{operation} {namespace}.{table}` (e.g., "SELECT jdbcunittest")
- New format: `{operation} {table}` or just `{operation}` (e.g., "SELECT" or "SELECT users")

## Next Steps

1. **Run other instrumentation testStableSemconv tests** - Check if similar fixes are needed for:
- R2DBC instrumentation
- Other database instrumentations

## Key Files Reference

| File | Purpose |
|------|---------|
| `instrumentation-api-incubator/src/jflex/SqlSanitizer.jflex` | JFlex lexer source |
| `instrumentation-api-incubator/build/generated/sources/jflex/.../AutoSqlSanitizer.java` | Generated lexer |
| `instrumentation-api-incubator/.../db/SqlStatementInfo.java` | Parsed SQL data class |
| `instrumentation-api-incubator/.../db/SqlClientAttributesExtractor.java` | Sets DB attributes |
| `instrumentation-api-incubator/.../db/DbClientSpanNameExtractor.java` | Generates span names |
| `instrumentation/jdbc/testing/.../AbstractJdbcInstrumentationTest.java` | JDBC tests |

## Commands

```bash
# Regenerate JFlex lexer
./gradlew :instrumentation-api-incubator:generateJflex

# Run old semconv tests
./gradlew :instrumentation:jdbc:javaagent:test

# Run stable semconv tests
./gradlew :instrumentation:jdbc:javaagent:testStableSemconv

# Run specific test
./gradlew :instrumentation:jdbc:javaagent:testStableSemconv --tests "*.testBasicStatement"
```

## Semantic Convention Reference
- `db.query.summary`: A low-cardinality string describing the performed operation
- Format: `{operation}` or `{operation} {target}`
- Max length: 255 characters
- Used as span name in stable semconv mode
Loading
Loading