-
Notifications
You must be signed in to change notification settings - Fork 0
Bug/blocking calls #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7ce6387
Attempt to run as unblocking across multiple devices
proffalken 65bb4f4
Move sending of telemetry to second core if it exists
proffalken 70dd207
Update include/OtelSender.h
proffalken a3ce038
Update src/OtelSender.cpp
proffalken 92beb6d
Merge branch 'main' into bug/blocking_calls
proffalken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,77 @@ | ||
| #ifndef OTEL_SENDER_H | ||
| #define OTEL_SENDER_H | ||
|
|
||
| #pragma once | ||
| #include <Arduino.h> | ||
| #include <ArduinoJson.h> | ||
| #include <atomic> | ||
|
|
||
| // Optional compile-time on/off switch for all network sends. | ||
| // You can set -DOTEL_SEND_ENABLE=0 in platformio.ini for latency tests. | ||
| #ifndef OTEL_SEND_ENABLE | ||
| #define OTEL_SEND_ENABLE 1 | ||
| #endif | ||
|
|
||
| #ifndef OTEL_WORKER_BURST | ||
| #define OTEL_WORKER_BURST 8 | ||
| #endif | ||
|
|
||
| #ifndef OTEL_WORKER_SLEEP_MS | ||
| #define OTEL_WORKER_SLEEP_MS 0 | ||
| #endif | ||
|
|
||
| #ifndef OTEL_QUEUE_CAPACITY | ||
| #define OTEL_QUEUE_CAPACITY 128 | ||
| #endif | ||
| // Base URL of your OTLP/HTTP collector (no trailing slash), e.g. "http://192.168.8.50:4318" | ||
| // You can override this via build_flags: -DOTEL_COLLECTOR_BASE_URL="\"http://…:4318\"" | ||
| #ifndef OTEL_COLLECTOR_BASE_URL | ||
| #define OTEL_COLLECTOR_BASE_URL "http://192.168.8.50:4318" | ||
| #endif | ||
|
|
||
| #ifndef OTEL_COLLECTOR_HOST | ||
| #define OTEL_COLLECTOR_HOST "http://192.168.8.10:4318" | ||
| // Internal queue capacity for async sender on RP2040. | ||
| // Keep small to bound RAM; increase if you see drops. | ||
| #ifndef OTEL_QUEUE_CAPACITY | ||
| #define OTEL_QUEUE_CAPACITY 16 | ||
| #endif | ||
proffalken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| namespace OTel { | ||
| struct OTelQueuedItem { | ||
| const char* path; // "/v1/logs", "/v1/traces", "/v1/metrics" | ||
| String payload; // serialized JSON | ||
| }; | ||
|
|
||
| class OTelSender { | ||
| public: | ||
| // Main API: called by logger/tracer/metrics to send serialized JSON to OTLP/HTTP | ||
| static void sendJson(const char* path, JsonDocument& doc); | ||
| }; | ||
|
|
||
| } // namespace OTel | ||
| // Start the RP2040 core-1 worker (no-op on non-RP2040). Call once after Wi-Fi is ready. | ||
| static void beginAsyncWorker(); | ||
|
|
||
| // Diagnostics (published via your health metrics if you like) | ||
| static uint32_t droppedCount(); // number of items dropped due to full queue | ||
| static bool queueIsHealthy(); // worker started? | ||
|
|
||
| private: | ||
| // ---------- SPSC ring buffer (core0 producer -> core1 consumer) ---------- | ||
| static constexpr size_t QCAP = OTEL_QUEUE_CAPACITY; | ||
| static OTelQueuedItem q_[QCAP]; | ||
| static std::atomic<size_t> head_; // producer writes | ||
| static std::atomic<size_t> tail_; // consumer writes | ||
| static std::atomic<uint32_t> drops_; | ||
| static std::atomic<bool> worker_started_; | ||
|
|
||
| static bool enqueue_(const char* path, String&& payload); | ||
| static bool dequeue_(OTelQueuedItem& out); | ||
|
|
||
| // ---------- Worker ---------- | ||
| static void pumpOnce_(); // send one item if present | ||
| static void workerLoop_(); // runs on core 1 (RP2040) | ||
| static void launchWorkerOnce_(); | ||
|
|
||
| // ---------- Utilities ---------- | ||
| static String fullUrl_(const char* path); // build collector URL + path | ||
|
|
||
| // inside class OTelSender (near the bottom) | ||
proffalken marked this conversation as resolved.
Show resolved
Hide resolved
proffalken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #ifdef ARDUINO_ARCH_RP2040 | ||
| friend void otel_worker_entry(); | ||
| #endif | ||
| }; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.