Skip to content

Commit 03018a7

Browse files
committed
Update README, use the example code as the default main.cpp
1 parent 03ed22c commit 03018a7

File tree

2 files changed

+83
-292
lines changed

2 files changed

+83
-292
lines changed

README.md

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ A C++ library for instrumenting constrained embedded devices with OpenTelemetry.
1212

1313
All examples assume use of the Arduino framework under PlatformIO, and that you have already implemented the network connection stack along with any code needed to set the clock on your embedded device to the correct time.
1414

15+
**WE STRONGLY RECOMMEND YOU USE NTP TO SET THE INTERNAL CLOCK, ALONG WITH AN RTC MODULE IF AVAILABLE**
16+
1517
The example code shows how to do this with the `time` library and NTP.
1618

1719
---
@@ -33,12 +35,12 @@ The example code shows how to do this with the `time` library and NTP.
3335
https://github.com/proffalken/otel-embedded-cpp.git#main
3436
```
3537

36-
2. **Configure your build flags** (either hard‑coded or via `${sysenv.*}`):
38+
2. **Configure your build flags in platformio.ini** (either hard‑coded or via `${sysenv.*}`):
3739

3840
```ini
3941
build_flags =
40-
-DOTEL_WIFI_SSID="${sysenv.OTEL_WIFI_SSID}"
41-
-DOTEL_WIFI_PASS="${sysenv.OTEL_WIFI_PASS}"
42+
-DWIFI_SSID="${sysenv.OTEL_WIFI_SSID}"
43+
-DWIFI_PASS="${sysenv.OTEL_WIFI_PASS}"
4244
-DOTEL_COLLECTOR_HOST="${sysenv.OTEL_COLLECTOR_HOST}"
4345
-DOTEL_COLLECTOR_PORT=${sysenv.OTEL_COLLECTOR_PORT}
4446
-DOTEL_SERVICE_NAME="${sysenv.OTEL_SERVICE_NAME}"
@@ -78,11 +80,14 @@ The example code shows how to do this with the `time` library and NTP.
7880
#include <WiFi.h>
7981
#include <time.h>
8082

83+
// ---------------------------------------------------------
84+
// Import Open Telemetry Libraries
85+
// ---------------------------------------------------------
8186
#include "OtelDefaults.h"
82-
#include "OtelSender.h"
83-
#include "OtelLogger.h"
8487
#include "OtelTracer.h"
88+
#include "OtelLogger.h"
8589
#include "OtelMetrics.h"
90+
#include "OtelDebug.h"
8691

8792
static constexpr uint32_t HEARTBEAT_INTERVAL = 5000;
8893

@@ -105,19 +110,26 @@ void setup() {
105110
while (time(nullptr) < 1609459200UL) { delay(500); }
106111

107112
// Initialise Logger & Tracer
108-
OTel::Logger::begin(
109-
OTEL_SERVICE_NAME,
110-
OTEL_SERVICE_NAMESPACE,
111-
WiFi.localIP().toString(), // optional collector info
112-
WiFi.macAddress(), // host identifier
113-
OTEL_SERVICE_VERSION
114-
);
115-
OTel::Tracer::begin(
116-
OTEL_SERVICE_NAME,
117-
OTEL_SERVICE_NAMESPACE,
118-
OTEL_SERVICE_INSTANCE,
119-
OTEL_SERVICE_VERSION
120-
);
113+
114+
// Set the defaults for the resources
115+
auto &res = OTel::defaultResource();
116+
res.set("service", OTEL_SERVICE_NAME);
117+
res.set("service.name", OTEL_SERVICE_NAME);
118+
res.set("service.namespace", OTEL_SERVICE_NAMESPACE);
119+
res.set("service.instance.id", OTEL_SERVICE_INSTANCE);
120+
res.set("host.name", "my-embedded device");
121+
122+
// Setup our tracing engine
123+
OTel::Tracer::begin("otel-embedded", "1.0.1");
124+
125+
// Make sure that we start with empty trace and span ID's
126+
OTel::currentTraceContext().traceId = "";
127+
OTel::currentTraceContext().spanId = "";
128+
129+
// Setup the metrics engine
130+
OTel::Metrics::begin("otel-embedded", "1.0.1");
131+
OTel::Metrics::setDefaultMetricLabel("device.role", "test-device");
132+
OTel::Metrics::setDefaultMetricLabel("device.id", "device-chip-id-or-mac");
121133
}
122134

123135
void loop() {
@@ -149,8 +161,8 @@ Override defaults in `OtelDefaults.h` or via `-D` flags:
149161

150162
| Macro | Default | Description |
151163
| ------------------------ | ------------------ | ----------------------------------------------- |
152-
| `OTEL_WIFI_SSID` | `"default"` | Wi‑Fi SSID |
153-
| `OTEL_WIFI_PASS` | `"default"` | Wi‑Fi password |
164+
| `WIFI_SSID` | `"default"` | Wi‑Fi SSID |
165+
| `WIFI_PASS` | `"default"` | Wi‑Fi password |
154166
| `OTEL_COLLECTOR_HOST` | `"http://…:4318"` | OTLP HTTP endpoint |
155167
| `OTEL_COLLECTOR_PORT` | `4318` | OTLP HTTP port |
156168
| `OTEL_SERVICE_NAME` | `"demo_service"` | Name of your service |
@@ -169,8 +181,7 @@ We welcome contributions of all kinds! To help us maintain a high standard:
169181
1. **Fork** the repository and create a feature branch.
170182
2. **Follow** the existing code style (header‑only, minimal macros, clear names).
171183
3. **Document** any new APIs or changes in this README.
172-
4. **Issue** a pull request against `refactor/headers` once your changes are ready.
173-
5. **Respond** to review comments promptly.
184+
4. **Issue** a pull request against the main repo once your changes are ready.
174185

175186
Please open an issue for:
176187

0 commit comments

Comments
 (0)