Skip to content

Ton analytics send events#1

Open
tztopusr wants to merge 47 commits intotztopusr:masterfrom
ton-connect:ton-analytics-send-events
Open

Ton analytics send events#1
tztopusr wants to merge 47 commits intotztopusr:masterfrom
ton-connect:ton-analytics-send-events

Conversation

@tztopusr
Copy link
Owner

@tztopusr tztopusr commented Nov 25, 2025

Note

Adds a batched TON Analytics pipeline (ring buffer + collector + event builder) and integrates it into v1/v3 handlers and storages, with new config/env, Docker mock, tests, and updated tonmetrics schemas.

  • Analytics:
    • Add internal/analytics with RingCollector, periodic Collector, and EventBuilder for bridge events.
    • Implement TonMetricsSender and batch sending via tonmetrics client; support noop client forwarding to mock.
  • Handlers/Server:
    • Wire analytics collector/builder into v1/v3 handlers (cmd/bridge, cmd/bridge3); emit events on subscribe/unsubscribe, message sent/received/expired, validation/verify.
    • Update handler constructors to accept analytics deps.
  • Storage:
    • Extend v1 Postgres/memory and v3 memory storages to emit bridge-message-expired; adjust constructors to accept analytics deps.
  • Config:
    • Replace TF_* vars with TON_ANALYTICS_* (ENABLED, URL, BRIDGE_VERSION, BRIDGE_URL, NETWORK_ID).
  • Docker:
    • Add analytics-mock service and Dockerfile.analytics-mock; propagate analytics envs across compose files.
  • Tests:
    • Add go integration tests and in-memory mock server for analytics event capture.
  • Schemas/Client:
    • Update tonmetrics OpenAPI models (e.g., bridge-verify, bridge-verify-validation-failed) and batch /events endpoints.

Written by Cursor Bugbot for commit 72513d8. This will update automatically on new commits. Configure here.

@tztopusr
Copy link
Owner Author

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

"",
errorMsg,
))
}
Copy link

Choose a reason for hiding this comment

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

Bug: V1 handler passes error messages to wrong analytics field

The logEventRegistrationValidationFailure function in v1 handler passes errorMsg as the fourth parameter (messageHash) to NewBridgeMessageValidationFailedEvent, causing error messages like "Last-Event-ID should be int" to be stored in the EncryptedMessageHash field. Compare to the v3 handler which correctly uses requestType as the second parameter and passes it to the third position (requestType). This results in incorrect analytics data where error messages are recorded as message hashes rather than properly categorized request types.

Fix in Cursor Fix in Web

TON_ANALYTICS_URL: "http://analytics-mock:9090/events"
TON_ANALYTICS_NETWORK_ID: "-239"
TON_ANALYTICS_BRIDGE_VERSION: "test-1.0.0"
TON_ANALYTICS_BRIDGE_URL: "http://bridge-instance2:8080"
Copy link

Choose a reason for hiding this comment

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

Bug: Copy-paste error in bridge3 analytics URL configuration

The bridge3 service has TON_ANALYTICS_BRIDGE_URL set to "http://bridge-instance2:8080" which is copied from the bridge2 service configuration. This causes bridge3 to report itself as bridge-instance2 in analytics events, making it impossible to distinguish which bridge instance generated the events. The URL should reference bridge3's own endpoint.

Fix in Cursor Fix in Web

TON_ANALYTICS_URL: "http://analytics-mock:9090/events"
TON_ANALYTICS_NETWORK_ID: "-239"
TON_ANALYTICS_BRIDGE_VERSION: "test-1.0.0"
TON_ANALYTICS_BRIDGE_URL: "http://bridge-instance1:8080"
Copy link

Choose a reason for hiding this comment

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

Bug: Copy-paste error in memory docker-compose analytics URL

The TON_ANALYTICS_BRIDGE_URL is set to "http://bridge-instance1:8080" but the service is named "bridge" and runs on port 8081. There is no "bridge-instance1" service in this compose file. This is a copy-paste error that will cause analytics events to report an incorrect and nonexistent bridge URL.

Fix in Cursor Fix in Web

TON_ANALYTICS_URL: "http://analytics-mock:9090/events"
TON_ANALYTICS_NETWORK_ID: "-239"
TON_ANALYTICS_BRIDGE_VERSION: "test-1.0.0"
TON_ANALYTICS_BRIDGE_URL: "http://bridge-instance1:8080"
Copy link

Choose a reason for hiding this comment

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

Bug: Copy-paste error in postgres docker-compose analytics URL

The TON_ANALYTICS_BRIDGE_URL is set to "http://bridge-instance1:8080" but the service is named "bridge" and runs on port 8081. There is no "bridge-instance1" service in this compose file. This is a copy-paste error that will cause analytics events to report an incorrect and nonexistent bridge URL.

Fix in Cursor Fix in Web

@callmedenchick callmedenchick force-pushed the ton-analytics-send-events branch from 7cc85e1 to 3aa0f63 Compare November 26, 2025 12:02
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