Capture the Cassandra 4.4 logical server in server.address by trask · Pull Request #19877 · open-telemetry/opentelemetry-java-instrumentation · GitHub
Skip to content

Capture the Cassandra 4.4 logical server in server.address - #19877

Merged
trask merged 34 commits into
mainfrom
trask-cassandra-44-targets
Sep 9, 2026
Merged

trask merged 34 commits into
mainfrom
trask-cassandra-44-targets

Conversation

@trask

@trask trask commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

This PR is part of #19899 and applies the configured database target rules in open-telemetry/semantic-conventions#4058 to Cassandra 4.4. Stable spans report configured contact points in server.address rather than the selected coordinator; legacy coordinator and proxy telemetry are preserved, with operation peer information handled separately by #19883.

Library users supply the complete original contact-point list, including both builder and driver-configuration sources:

CqlSession tracedSession = cassandraTelemetry.wrap(session, contactPoints);

The existing wrap(session) still traces operations but omits stable server.address and server.port. This follows the MongoDB library pattern in #19839 rather than trying to reconstruct original configuration from resolved driver metadata.

The javaagent continues to combine captured builder contact points with basic.contact-points automatically. Targets are captured once when wrapping the session, so later topology and coordinator changes do not affect them.

Multi-endpoint handling

  • A single endpoint omits its port from server.address, and a non-default port is recorded in server.port.
  • Multiple endpoints omit ports when all use the default 9042 port.
  • When any of multiple endpoints uses a non-default port, every endpoint includes its port in server.address and server.port is omitted.
  • Endpoints are normalized and sorted, configured duplicates are preserved, and at most the first five resulting endpoints are recorded.

Omission rules

Unsafe or malformed values, implicit targets, and custom or SNI discovery endpoints omit the stable target instead of falling back to the coordinator.

Builds on #19872.

@trask
trask requested a balanced review from Copilot August 27, 2026 15:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Updates Cassandra 4.4 instrumentation to report stable server.address / server.port from configured (and captured programmatic) contact points, aligning with semantic-conventions#4041, while preserving legacy behavior and handling SNI/broadcast RPC cases.

Changes:

  • Capture and snapshot configured/programmatic contact points at session-wrap time and propagate into request/span attribute extraction.
  • Add CassandraServerTarget logic + tests for parsing/deduping/sorting contact points and session configuration fallbacks.
  • Extend server attribute extraction logic for stable semconv, including special handling for SNI endpoints.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
instrumentation/cassandra/cassandra-common-4.0/testing/src/main/java/io/opentelemetry/cassandra/common/v4_0/AbstractCassandraTest.java Adds an integration test verifying configured contact points become the stable server target.
instrumentation/cassandra/cassandra-4.4/library/src/test/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraServerTargetTest.java Adds unit tests for CassandraServerTarget parsing, grouping, and session configuration logic.
instrumentation/cassandra/cassandra-4.4/library/src/test/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraEndpointAttributesTest.java Adds tests for stable server.* extraction and SNI/broadcast-RPC behavior.
instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/TracingCqlSession.java Snapshots server target at wrap time and threads it through request creation.
instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraTelemetry.java Adds internal overload to wrap sessions with captured programmatic contact points.
instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraSqlAttributesGetter.java Implements stable server.address / server.port getters based on captured target, with SNI guarding.
instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraServerTarget.java Introduces server target parsing/combining and session contact-point source selection logic.
instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraRequest.java Carries CassandraServerTarget on the request to support stable semconv extraction.
instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraAttributesExtractor.java Updates server attribute extraction to preserve configured targets and handle SNI/broadcast-RPC for stable semconv.
instrumentation/cassandra/cassandra-4.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_4/SessionBuilderInstrumentation.java Captures programmatic contact points from the driver builder and passes them into wrapping logic.
instrumentation/cassandra/cassandra-4.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_4/CompletionStageFunction.java Removes old javaagent-local wrapping function.
instrumentation/cassandra/cassandra-4.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_4/CassandraSingletons.java Makes singleton telemetry accessor public for reuse from the new wrapper function.
instrumentation/cassandra/cassandra-4.4/javaagent/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CompletionStageFunction.java Adds new wrapping function carrying both telemetry and a snapshot of programmatic contact points.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-09-10 17:07 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@trask
trask requested a balanced review from Copilot August 27, 2026 22:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

@trask trask changed the title Use configured targets for Cassandra 4.4 Report Cassandra 4.4 configured targets in server attributes Aug 27, 2026
@trask
trask requested a balanced review from Copilot August 27, 2026 23:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

@trask trask changed the title Report Cassandra 4.4 configured targets in server attributes Capture the Cassandra 4.4 logical server in server.address Aug 29, 2026
@trask
trask force-pushed the trask-cassandra-44-targets branch 2 times, most recently from db0984d to 7f1f03b Compare August 30, 2026 23:08
@trask
trask force-pushed the trask-cassandra-44-targets branch from 7f1f03b to e66ddec Compare August 31, 2026 01:55
@trask
trask force-pushed the trask-cassandra-44-targets branch from e66ddec to dd7a20b Compare September 1, 2026 03:29
@trask
trask force-pushed the trask-cassandra-44-targets branch from dd7a20b to 291625c Compare September 1, 2026 18:53
trask and others added 10 commits September 8, 2026 22:41
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Failing check:

build / common / build: error: warnings found and -Werror specified

Cause: The Javadoc name addContactPoints resembled the contactPoints parameter, so Error Prone reported InvalidParam.

Fix: Describe the builder methods without identifier-style code text that Error Prone interprets as a parameter reference.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot comment:

`ofAddresses` does not guard against invalid entries (e.g., null elements) and does not wrap its loop/build in the same `try/catch` used by the session-based overloads. However, `CassandraServerTargetTest.unsafeExplicitContactPointAddressesHaveNoTarget` passes a null `InetSocketAddress` and expects `null` rather than an exception. To match the omission rules ('unsafe or malformed values omit the stable target'), handle null/invalid addresses by recording an invalid endpoint or catching `RuntimeException` and returning `null`.

Analysis: The explicit-address overload let invalid entries throw before the target builder could omit the target. Catching RuntimeException around endpoint collection and target construction applies the same omission behavior as the session overloads.

Upsides: Unsafe or malformed explicit addresses now omit server.address instead of escaping into session construction.

Downsides: The overload does not expose the specific malformed endpoint that caused omission.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot comment:

Parsing string contact points via `lastIndexOf(':')` makes unbracketed IPv6 literals **without** an explicit port ambiguous and can be misinterpreted as `host + port` (e.g., `\"::1\"` becomes host `\"::\"` port `1`, and `\"2001:db8::1\"` becomes host `\"2001:db8::\"` port `1`). This conflicts with `CassandraServerTargetTest.invalidContactPoints()` which expects those values to drop the target, and it can also yield incorrect stable targets in production. Consider changing the string-format contract to require bracketed IPv6 (`[addr]:port`) for any IPv6 host in configured contact points, or add stricter validation to reject cases that look like bare IPv6 literals rather than `host:port` entries. (Mandatory to make behavior deterministic and aligned with the test expectations/omission rules.)

Analysis: The last colon cannot distinguish an IPv6 address segment from a port. Requiring brackets whenever the parsed host contains a colon makes the configured contact point format unambiguous and keeps bare IPv6 literals from producing a false stable target.

Upsides: IPv6 contact points now produce a stable target only from the deterministic `[address]:port` form, and tests cover apparent-port edge cases.

Downsides: Previously accepted unbracketed IPv6 contact points with a port now omit the stable target.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Target ordering, malformed bracket handling, and the public overload contract need correction.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (2)

instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraServerTarget.java:96

  • [General] The mixed configured/programmatic path still preserves the configured prefix and sorts only the programmatic suffix. Since the Cassandra driver treats the merged contact points as an unordered set, equivalent builder/config combinations can produce different target strings. Enable sorting on the final DbServerTargetBuilder instead of preserving this split order.
      DbServerTargetBuilder target = DbServerTarget.builder(DEFAULT_PORT);

instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraServerTarget.java:177

  • [General] This strips brackets without checking that they enclosed IPv6, so malformed values such as [node.example.com]:9042 or [127.0.0.1]:9042 are accepted as ordinary hosts instead of dropping the target. Validate that a bracketed host is IPv6 before passing it to the target builder.
    if (host.startsWith("[")) {
      if (!host.endsWith("]")) {
        target.addEndpoint((String) null, -1);
        return null;
      }
  • Files reviewed: 14/14 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment on lines +201 to +205

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is to figure out whether 2 addresses are really the same, does it matter?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this was probably too much, simplified it, and require passing in the seeds into the library instrumentation similar to mongo (#19839)

trask and others added 3 commits September 9, 2026 07:36
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Bracketed non-IPv6 hosts are incorrectly accepted instead of triggering target omission.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 16/16 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Copilot comment:

[General] This strips brackets before `DbServerTargetBuilder` can validate their use, so a malformed value such as `[node.example.com]:9042` is accepted and emitted as `node.example.com` instead of dropping the complete target. Brackets are valid only for IPv6 literals; reject a bracketed host without a colon before removing the brackets so malformed configurations follow the PR's omission rule.

Analysis: CassandraServerTarget removes brackets before passing the host to DbServerTargetBuilder. The builder therefore cannot tell that a DNS hostname was bracketed. Rejecting a bracketed host without a colon preserves valid IPv6 literals and drops malformed bracketed hostnames.

Upsides: Malformed bracketed hostnames now omit the complete server target, and the parameterized parser test covers this case.

Downsides: No material downside identified

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The target capture, omission rules, semantic-convention behavior, and compatibility paths are consistently implemented and tested.

Review details
  • Files reviewed: 16/16 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@trask
trask disabled stacked auto-merge September 9, 2026 18:41
@trask
trask merged commit 9d61b8b into main Sep 9, 2026
100 checks passed
@trask
trask deleted the trask-cassandra-44-targets branch September 9, 2026 19:37
laurit pushed a commit to laurit/opentelemetry-java-instrumentation that referenced this pull request Sep 21, 2026
…metry#19877)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants