Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
89b19aa
docs: add comprehensive PR for all changes from 0.2.2 to 0.5.1
Oct 5, 2025
76bd6cb
style: fix Qodana findings (javadoc order, regex, redundant cast, com…
Oct 6, 2025
d69c0c5
refactor: address additional Qodana issues (duplicate expressions, re…
Oct 6, 2025
c22e564
style: suppress unchecked warnings and remove redundant casts across …
Oct 6, 2025
edac1fd
chore: restore workflow, qodana config, and docs removed inadvertently
Oct 6, 2025
cc1a5d3
refactor: use typed tag helpers across API and events; add code-aware…
Oct 6, 2025
520d866
Merge remote-tracking branch 'origin/develop' into develop
Oct 6, 2025
bed8994
Merge remote-tracking branch 'origin/develop' into chore/qodana-fixes
Oct 6, 2025
68114ed
chore(bom): bump to 1.1.1 and remove local JUnit overrides; test: qua…
Oct 6, 2025
e198b6e
chore(version): bump project version to 0.6.0 across poms and docs
Oct 6, 2025
6146268
Merge pull request #453 from tcheeric/chore/qodana-fixes
tcheeric Oct 6, 2025
98df86e
Merge remote-tracking branch 'origin/develop' into develop
Oct 6, 2025
6e1ee6a
fix(logging): improve error messages and log levels per Clean Code gu…
Oct 6, 2025
911ab87
refactor(logging): remove constructor logging from low-level key classes
Oct 6, 2025
33270a7
refactor(test): remove test method name logging per Clean Code guidel…
Oct 6, 2025
337bce4
refactor(logging): extract duplicated recovery logging in SpringWebSo…
Oct 6, 2025
90a4c8b
chore: bump version to 0.6.1
Oct 6, 2025
1feba9f
Merge pull request #454 from tcheeric/chore/bump-version-0.6.1
tcheeric Oct 6, 2025
a988d62
fix(logging): improve error messages and log levels per Clean Code gu…
Oct 6, 2025
5ffd3e7
refactor(logging): remove constructor logging from low-level key classes
Oct 6, 2025
37ea04b
refactor(test): remove test method name logging per Clean Code guidel…
Oct 6, 2025
6326f23
refactor(logging): extract duplicated recovery logging in SpringWebSo…
Oct 6, 2025
e813346
Merge remote-tracking branch 'origin/develop' into develop
Oct 6, 2025
c0e6509
docs(javadoc): fix plain-text NIP links to anchors; fully-qualify Jav…
Oct 6, 2025
7dc0019
docs(javadoc): address Qodana javadoc items (anchor NIP links, fully-…
Oct 6, 2025
f5ce0ad
chore: bump version to 0.6.2 and tighten fields per Qodana (FieldMayB…
Oct 6, 2025
93c5c2c
test: configure Mockito to use subclass mock-maker via SPI and surefi…
Oct 6, 2025
529b849
Merge pull request #455 from tcheeric/chore/qodana-final-and-bump-0.6.2
tcheeric Oct 6, 2025
7e9c139
fix: replace generic exception handling
tcheeric Oct 6, 2025
ec39a51
Merge pull request #456 from tcheeric/codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
9995e9f
fix: replace sneaky throws with explicit handling
tcheeric Oct 6, 2025
1a86ffb
Merge pull request #457 from tcheeric/codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
176020d
refactor: unify nostr exception hierarchy
tcheeric Oct 6, 2025
a555d0a
Merge branch 'develop' into codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
7816173
Merge pull request #458 from tcheeric/codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
981c57d
refactor: modularize nip helpers and client orchestration
tcheeric Oct 6, 2025
f11f80a
Merge branch 'develop' into codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
8ce884d
Merge pull request #459 from tcheeric/codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
241cbe2
refactor: streamline subscriptions and zap parameters
tcheeric Oct 6, 2025
5a52f53
Merge branch 'develop' into codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
e9a3248
Merge pull request #460 from tcheeric/codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
9397543
docs: clarify api documentation
tcheeric Oct 6, 2025
028d724
Merge branch 'develop' into codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
1c4ddf0
Merge pull request #461 from tcheeric/codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
b2abab2
refactor: normalize event cache naming and mapper access
tcheeric Oct 6, 2025
7ca269c
Merge branch 'develop' into codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
6c89350
Merge pull request #462 from tcheeric/codex/create-tasks-for-milestone-1
tcheeric Oct 6, 2025
67a565a
fix(api): allow optional sender when constructing websocket client
tcheeric Oct 6, 2025
398fc69
Merge pull request #463 from tcheeric/codex/fix-ci-error
tcheeric Oct 6, 2025
e2c80fc
refactor: abstract relay clients and codify nip ranges
tcheeric Oct 6, 2025
d3499a1
Merge branch 'develop' into codex/create-tasks-for-milestone-1-ylzf9j
tcheeric Oct 6, 2025
9ee96ee
Merge pull request #464 from tcheeric/codex/create-tasks-for-mileston…
tcheeric Oct 6, 2025
6b2a597
feat: finalize calendar decoding and generic event builder
tcheeric Oct 6, 2025
175b159
Merge branch 'develop' into codex/create-tasks-for-milestone-1-mt6702
tcheeric Oct 6, 2025
afdb80a
Merge pull request #465 from tcheeric/codex/create-tasks-for-mileston…
tcheeric Oct 6, 2025
69fefe1
build(pom): restore BOM version to 1.1.1 and re-add internal module o…
Oct 6, 2025
00c2ab5
chore(deps): bump org.sonatype.central:central-publishing-maven-plugin
dependabot[bot] Oct 6, 2025
7b71243
docs: complete Phase 2 documentation enhancement
Oct 6, 2025
223d911
Merge pull request #467 from tcheeric/docs/phase-2-documentation-enha…
tcheeric Oct 6, 2025
8216182
Merge pull request #466 from tcheeric/dependabot/maven/develop/org.so…
tcheeric Oct 6, 2025
0925bbd
docs: complete Phase 2 Task 5 - extended JavaDoc for NIPs and exceptions
Oct 6, 2025
2844e5e
chore: organize project management files into .project-management folder
Oct 6, 2025
6635cc4
chore: rename logging review and improvements markdown files
Oct 6, 2025
cfac008
Merge pull request #468 from tcheeric/docs/phase-2-extended-javadoc
tcheeric Oct 6, 2025
4ed2daf
docs: add MIGRATION.md for 1.0.0 upgrade path - Phase 2 Task 6 complete
Oct 8, 2025
89c05b0
test: add comprehensive tests for NIP-04, NIP-44, and NIP-57
Oct 8, 2025
afb5ffa
docs: add Phase 3 & 4 testing analysis and progress tracking
Oct 8, 2025
482fff9
chore: bump version to 0.6.4
Oct 8, 2025
e215449
docs: add PR document for critical tests and Phase 3 & 4
Oct 8, 2025
b963138
fix: remove unsupported eventId test from NIP57ImplTest
Oct 8, 2025
d191718
fix: adjust NIP-44 tests to respect NIP-44 plaintext constraints
Oct 8, 2025
cf5fc5b
Merge pull request #470 from tcheeric/test/critical-nip-tests-impleme…
tcheeric Oct 8, 2025
4bcc23b
chore(tests): strengthen client/handler tests and increase coverage; …
Oct 9, 2025
d5a3c60
Merge pull request #471 from tcheeric/chore/tests-coverage-enhancements
tcheeric Oct 9, 2025
a199549
build(api): add slf4j-test version (2.4.0) for test logging assertions
Oct 9, 2025
e98c4ce
chore: automate roadmap project setup
tcheeric Oct 11, 2025
6d653b0
Merge pull request #472 from tcheeric/codex/establish-remaining-tasks…
tcheeric Oct 11, 2025
e2f0382
Merge remote-tracking branch 'origin/develop' into develop
Oct 11, 2025
31ce804
fix(api): close WebSocket clients when subscription handles close; bu…
Oct 11, 2025
471c290
Merge pull request #473 from tcheeric/fix/websocket-handler-close-client
tcheeric Oct 11, 2025
fa6a8ba
chore: bump project version to 1.0.0-SNAPSHOT
Oct 11, 2025
5cd2a91
docs(migration): update migration steps for nostr-java BOM usage
Oct 11, 2025
85985de
docs(troubleshooting): update dependency version references for clarity
Oct 11, 2025
4243e5a
fix: parse BOLT11 separator correctly
tcheeric Oct 11, 2025
4d63f19
test: fix bolt11 whole btc fixture
tcheeric Oct 11, 2025
6fd28ca
Merge pull request #475 from tcheeric/codex/address-review-comment-in…
tcheeric Oct 11, 2025
7679bf2
fix(bolt11): correct HRP separator parsing in BOLT11 invoices
Oct 11, 2025
d4ddb67
fix(nip01): handle null uuid in identifier tag parsing
Oct 11, 2025
9861b76
feat: enhance task management in roadmap project script
Oct 11, 2025
de0f48a
Merge pull request #474 from tcheeric/chore/bump-version-1.0.0-SNAPSHOT
tcheeric Oct 11, 2025
199764f
chore(version): bump to 1.0.1-SNAPSHOT across all modules
Oct 12, 2025
4274095
fix: restore GenericTag fallback for DM decrypt
tcheeric Oct 12, 2025
b85dd49
Merge pull request #476 from tcheeric/chore/bump-version-1.0.1-SNAPSHOT
tcheeric Oct 12, 2025
8d04481
refactor(tags): reorganize imports for clarity
Oct 12, 2025
2d3cbd4
docs: rename relay references to 398ja
tcheeric Oct 12, 2025
8857498
Merge pull request #477 from tcheeric/codex/update-relay-name-from-da…
tcheeric Oct 12, 2025
41cdc37
fix: enforce string nip metadata
tcheeric Oct 12, 2025
4df2582
Merge pull request #478 from tcheeric/codex/update-event-kind-type-to…
tcheeric Oct 12, 2025
98d4df3
chore(deps): bump actions/checkout from 4 to 5
dependabot[bot] Oct 13, 2025
7c3458f
chore(deps): bump actions/setup-java from 4 to 5
dependabot[bot] Oct 13, 2025
ac61230
chore(deps): bump org.jacoco:jacoco-maven-plugin from 0.8.13 to 0.8.14
dependabot[bot] Oct 13, 2025
364452b
Merge pull request #481 from tcheeric/dependabot/maven/develop/org.ja…
tcheeric Oct 13, 2025
c8518be
Merge pull request #479 from tcheeric/dependabot/github_actions/devel…
tcheeric Oct 13, 2025
5834f52
Merge pull request #480 from tcheeric/dependabot/github_actions/devel…
tcheeric Oct 13, 2025
4a340ab
chore(version): bump to 1.0.2-SNAPSHOT across all modules
Oct 13, 2025
796773c
chore: release version 1.0.0
Oct 13, 2025
993b342
refactor(api): remove deprecated Identity parameter methods from NIP01
Oct 13, 2025
21c704a
Merge pull request #482 from tcheeric/chore/bump-version-1.0.2-SNAPSHOT
tcheeric Oct 13, 2025
d35c334
docs(readme): update troubleshooting section and remove outdated content
Oct 13, 2025
5af42bd
docs(readme): fix formatting of features list for consistency
Oct 13, 2025
0dcd0dc
chore: update changelog for version 1.0.0 release
Oct 13, 2025
8fbbb71
refactor(api)!: clean up and remove deprecated APIs in v1.0.0
Oct 13, 2025
9726c58
refactor(release): enhance Maven command options handling
Oct 13, 2025
baa075b
chore(settings): add Maven settings for repository configuration
Oct 13, 2025
7e273ec
chore(settings): update Maven repository URL for consistency
Oct 14, 2025
6cefd8f
fix(api): handle generic p-tags during DM decrypt
tcheeric Oct 14, 2025
54109ad
Merge pull request #484 from tcheeric/codex/add-unit-test-for-nip04.java
tcheeric Oct 14, 2025
c966937
fix: restore sender overrides in NIP-01 builder
tcheeric Oct 14, 2025
00870ac
style: use diamond operator in NIP01 builder
tcheeric Oct 14, 2025
b0b8d60
Merge pull request #485 from tcheeric/codex/address-code-comment-in-n…
tcheeric Oct 14, 2025
38b1639
Merge branch 'chore/bump-version-1.0.2-SNAPSHOT' into codex/address-c…
tcheeric Oct 14, 2025
042d019
Merge pull request #486 from tcheeric/codex/address-code-comment-in-n…
tcheeric Oct 14, 2025
c652345
Merge pull request #487 from tcheeric/chore/bump-version-1.0.2-SNAPSHOT
tcheeric Oct 14, 2025
58bceed
refactor(api)!: simplify event building methods by removing sender pa…
Oct 14, 2025
3a16764
refactor(api): update default sender handling in NIP01 event builder
Oct 14, 2025
7c90fec
ci: update Maven command to use custom settings file
Oct 14, 2025
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
Prev Previous commit
Next Next commit
chore(tests): strengthen client/handler tests and increase coverage; …
…bump version to 0.6.5-SNAPSHOT
  • Loading branch information
erict875 committed Oct 9, 2025
commit 4bcc23b712a943230b51eb4bf35595e02b9daf49
18 changes: 13 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: no-docker
mvn-args: "-Pno-docker"
- name: docker
mvn-args: ""
permissions:
contents: read
issues: write
Expand All @@ -25,8 +33,8 @@ jobs:
java-version: '21'
distribution: 'temurin'
cache: 'maven'
- name: Build with Maven
run: ./mvnw -q verify |& tee build.log
- name: Build with Maven (${{ matrix.name }})
run: ./mvnw -q ${{ matrix.mvn-args }} verify |& tee build.log
- name: Show build log
if: failure()
run: |
Expand Down Expand Up @@ -58,7 +66,7 @@ jobs:
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Create issue on failure
- name: Create issue on failure (${{ matrix.name }})
if: failure() && github.ref == 'refs/heads/develop'
uses: actions/github-script@v7
with:
Expand All @@ -72,7 +80,7 @@ jobs:
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `CI build failed for ${context.sha.slice(0,7)}`,
body: `Build failed for commit ${context.sha} in workflow run ${context.runId}.\\n\\nBuild error:\\n\\n\u0060\u0060\u0060\\n${errors}\\n\u0060\u0060\u0060\\n\\nLast lines of build log:\\n\\n\u0060\u0060\u0060\\n${log}\\n\u0060\u0060\u0060`,
title: `CI (${{ matrix.name }}) failed for ${context.sha.slice(0,7)}`,
body: `Build failed for commit ${context.sha} in workflow run ${context.runId} (matrix: ${{ matrix.name }}).\\n\\nBuild error:\\n\\n\u0060\u0060\u0060\\n${errors}\\n\u0060\u0060\u0060\\n\\nLast lines of build log:\\n\\n\u0060\u0060\u0060\\n${log}\\n\u0060\u0060\u0060`,
labels: ['ci']
});
30 changes: 30 additions & 0 deletions .project-management/ISSUES_OPERATIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Follow-up Issues: Operations Documentation

Create the following GitHub issues to track operations docs and examples.

1) Ops: Micrometer integration examples
- Show counters via `MeterRegistry` (simple counters, timers around send)
- Listener wiring (`onSendFailures`) increments counters
- Sample Prometheus scrape via micrometer-registry-prometheus

2) Ops: Prometheus exporter example
- Minimal HTTP endpoint exposing counters
- Translate `DefaultNoteService.FailureInfo` into metrics labels (relay)
- Include guidance on cardinality

3) Ops: Logging patterns and correlation IDs
- MDC usage to correlate sends with subscriptions
- Recommended logger categories & sample filters
- JSON logging example (Logback)

4) Ops: Configuration deep-dive
- Advanced timeouts and backoff strategies (pros/cons)
- When to adjust `await-timeout-ms` / `poll-interval-ms`
- Retry tuning beyond defaults and trade-offs

5) Ops: Diagnostics cookbook
- Common failure scenarios and how to interpret FailureInfo
- Mapping failures to remediation steps
- Cross-relay differences and best practices

Note: Opening issues requires repository permissions; add the above as individual issues with `docs` and `operations` labels.
15 changes: 14 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ See [docs/explanation/architecture.md](docs/explanation/architecture.md) for det
- **Test all edge cases:** null values, empty strings, invalid inputs
- **Use descriptive test names** or `@DisplayName`

### Client/Handler tests

- See `nostr-java-api/src/test/java/nostr/api/client/README.md` for structure and naming.
- Naming conventions:
- `NostrSpringWebSocketClient*` for high‑level client behavior
- `WebSocketHandler*` for internal handler semantics (send/close/request)
- `NostrRequestDispatcher*` and `NostrSubscriptionManager*` for dispatcher/manager lifecycles
- Use `nostr.api.TestHandlerFactory` to construct `WebSocketClientHandler` from tests outside `nostr.api`.

### Client module tests

- See `nostr-java-client/src/test/java/nostr/client/springwebsocket/README.md` for an overview of the Spring WebSocket client test suite (retry/subscribe/timeout behavior).

### Test Example

```java
Expand Down Expand Up @@ -186,4 +199,4 @@ void testValidateKindRejectsNegative() {
- Summaries in pull requests must cite file paths and include testing output.
- Open pull requests using the template at `.github/pull_request_template.md` and complete every section.

By following these conventions, contributors help keep the codebase maintainable and aligned with the Nostr specifications.
By following these conventions, contributors help keep the codebase maintainable and aligned with the Nostr specifications.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# nostr-java
[![CI](https://github.com/tcheeric/nostr-java/actions/workflows/ci.yml/badge.svg)](https://github.com/tcheeric/nostr-java/actions/workflows/ci.yml)
[![CI Matrix: docker + no-docker](https://img.shields.io/badge/CI%20Matrix-docker%20%2B%20no--docker-blue)](https://github.com/tcheeric/nostr-java/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/tcheeric/nostr-java/branch/main/graph/badge.svg)](https://codecov.io/gh/tcheeric/nostr-java)
[![GitHub release](https://img.shields.io/github/v/release/tcheeric/nostr-java)](https://github.com/tcheeric/nostr-java/releases)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
Expand All @@ -13,9 +14,64 @@

See [docs/GETTING_STARTED.md](docs/GETTING_STARTED.md) for installation and usage instructions.

## Running Tests

- Full test suite (requires Docker for Testcontainers ITs):

`mvn -q verify`

- Without Docker (skips Testcontainers-based integration tests via profile):

`mvn -q -Pno-docker verify`

The `no-docker` profile excludes tests under `**/nostr/api/integration/**` and sets `noDocker=true` for conditional test disabling.

### Troubleshooting failed relay sends

When broadcasting to multiple relays, failures on individual relays are tolerated and sending continues to other relays. To inspect which relays failed during the last send on the current thread:

```java
// Using the default client setup
NostrSpringWebSocketClient client = new NostrSpringWebSocketClient(sender);
client.setRelays(Map.of(
"relayA", "wss://relayA.example.com",
"relayB", "wss://relayB.example.com"
));

List<String> responses = client.sendEvent(event);
// Inspect failures (if using DefaultNoteService)
Map<String, Throwable> failures = client.getLastSendFailures();
failures.forEach((relay, error) ->
System.out.println("Relay " + relay + " failed: " + error.getMessage())
);
```

This returns an empty map if a custom `NoteService` is used that does not expose diagnostics.

To receive failure notifications immediately after each send attempt when using the default client:

```java
client.onSendFailures(map -> {
map.forEach((relay, t) -> System.err.println(
"Send failed on relay " + relay + ": " + t.getClass().getSimpleName() + ": " + t.getMessage()
));
});
```

For more detail (timestamp, class, message), use:

```java
Map<String, DefaultNoteService.FailureInfo> info = client.getLastSendFailureDetails();
info.forEach((relay, d) -> System.out.printf(
"[%d] %s failed: %s - %s%n",
d.timestampEpochMillis, relay, d.exceptionClass, d.message
));
```

## Documentation

- Docs index: [docs/README.md](docs/README.md) — quick entry point to all guides and references.
- Operations: [docs/operations/README.md](docs/operations/README.md) — logging, metrics, configuration, diagnostics.
- Getting started: [docs/GETTING_STARTED.md](docs/GETTING_STARTED.md) — install via Maven/Gradle and build from source.
- API how‑to: [docs/howto/use-nostr-java-api.md](docs/howto/use-nostr-java-api.md) — create, sign, and publish basic events.
- Streaming subscriptions: [docs/howto/streaming-subscriptions.md](docs/howto/streaming-subscriptions.md) — open and manage long‑lived, non‑blocking subscriptions.
Expand Down
10 changes: 10 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Quick links to the most relevant guides and references.
- [howto/streaming-subscriptions.md](howto/streaming-subscriptions.md) — Long-lived subscriptions
- [howto/custom-events.md](howto/custom-events.md) — Creating custom event types

## Operations

- [operations/README.md](operations/README.md) — Ops index (logging, metrics, config)
- [howto/diagnostics.md](howto/diagnostics.md) — Inspecting relay failures and troubleshooting

## Reference

- [reference/nostr-java-api.md](reference/nostr-java-api.md) — API classes, methods, and examples
Expand All @@ -26,3 +31,8 @@ Quick links to the most relevant guides and references.
## Project

- [CODEBASE_OVERVIEW.md](CODEBASE_OVERVIEW.md) — Codebase layout, testing, contributing

## Tests Overview

- API Client/Handler tests: `nostr-java-api/src/test/java/nostr/api/client/README.md` — logging, relays, handler send/close/request, dispatcher & subscription manager
- Client module (Spring WebSocket): `nostr-java-client/src/test/java/nostr/client/springwebsocket/README.md` — send/subscribe retries and timeout behavior
86 changes: 86 additions & 0 deletions docs/howto/diagnostics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Diagnostics: Relay Failures and Troubleshooting

This how‑to shows how to inspect, capture, and react to relay send failures when broadcasting events via the API client.

## Overview

- `DefaultNoteService` attempts to send an event to all configured relays.
- Failures on individual relays are tolerated; other relays are still attempted.
- After the send completes, you can inspect failures and structured details.
- You can also register a listener to receive failures in real time.

## Inspect last failures

```java
NostrSpringWebSocketClient client = new NostrSpringWebSocketClient(sender);
client.setRelays(Map.of(
"relayA", "wss://relayA.example.com",
"relayB", "wss://relayB.example.com"
));

List<String> responses = client.sendEvent(event);

// Map<String, Throwable>: relay name to exception
Map<String, Throwable> failures = client.getLastSendFailures();
failures.forEach((relay, error) -> System.err.printf(
"Relay %s failed: %s%n", relay, error.getMessage()
));

// Structured details (timestamp, relay URI, cause chain summary)
Map<String, DefaultNoteService.FailureInfo> details = client.getLastSendFailureDetails();
details.forEach((relay, info) -> System.err.printf(
"[%d] %s (%s) failed: %s | root: %s - %s%n",
info.timestampEpochMillis,
info.relayName,
info.relayUri,
info.message,
info.rootCauseClass,
info.rootCauseMessage
));
```

Note: If you use a custom `NoteService`, these accessors return empty maps unless the implementation exposes diagnostics.

## Receive failures with a listener

Register a callback to receive the failures map immediately after each send attempt:

```java
client.onSendFailures(failureMap -> {
failureMap.forEach((relay, t) -> System.err.printf(
"Failure on %s: %s: %s%n",
relay, t.getClass().getSimpleName(), t.getMessage()
));
});
```

## Tips

- Partial success is common on public relays; prefer aggregating successful responses.
- Use `getLastSendFailureDetails()` when you need to correlate failures with relay URIs or log timestamps.
- Combine diagnostics with your retry/backoff strategy at the application level if needed.

## MDC snippet (correlate logs per send)

Use SLF4J MDC to attach a correlation id for a send. Remember to clear the MDC in `finally`.

```java
import org.slf4j.MDC;
import java.util.UUID;

String correlationId = UUID.randomUUID().toString();
MDC.put("corrId", correlationId);
try {
var responses = client.sendEvent(event);
// Your logging here; include %X{corrId} in your log pattern
log.info("Sent event id={} corrId={} responses={}", event.getId(), correlationId, responses.size());
} finally {
MDC.remove("corrId");
}
```

Logback pattern example:

```properties
logging.pattern.console=%d{HH:mm:ss.SSS} %-5level [%X{corrId}] %logger{36} - %msg%n
```
16 changes: 16 additions & 0 deletions docs/operations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Operations

Operational guidance and runbook-style topics for nostr-java.

## Topics

- Diagnostics and Failures
- See how-to: [../howto/diagnostics.md](../howto/diagnostics.md)
- Logging
- Recommended logger setup, categories, and verbosity — see [logging.md](logging.md)
- Metrics
- Exporting client metrics and subscription activity — see [metrics.md](metrics.md)
- Configuration
- Tuning timeouts, retries, and backoff — see [configuration.md](configuration.md)

If you have specific operational topics you’d like documented first, open an issue and tag it with `docs` and `operations`.
40 changes: 40 additions & 0 deletions docs/operations/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Configuration

Tune WebSocket behavior and retries for your environment.

## Purpose

- Adjust timeouts and poll intervals for send operations.
- Understand retry behavior for transient I/O failures.

## WebSocket client settings

The Spring WebSocket client reads the following properties (with defaults):

- `nostr.websocket.await-timeout-ms` (default: `60000`) — Max time to await a response after send.
- `nostr.websocket.poll-interval-ms` (default: `500`) — Poll interval used during await.

Example (application.properties):

```
nostr.websocket.await-timeout-ms=30000
nostr.websocket.poll-interval-ms=250
```

## Retry behavior

WebSocket send and subscribe operations are annotated with a common retry policy:

- Included exception: `IOException`
- Max attempts: `3`
- Backoff: initial `500ms`, multiplier `2.0`

These values are defined in the `@NostrRetryable` annotation. To customize globally, consider:

- Creating a custom annotation or replacing `@NostrRetryable` with your configuration.
- Providing your own `NoteService` or client wrapper that applies your retry strategy.

## Notes

- Timeouts apply per send; long-running subscriptions are managed separately.
- Ensure your relay endpoints’ SLAs align with chosen timeouts and backoff.
Loading