feat(telemetry): 0.3.0 service.version default, ResourceAttributes, logs follow AddZbTelemetry OTLP (#55)
- service.version: null ServiceVersion now defaults to the entry assembly's AssemblyInformationalVersion (the family apps stamp the git SHA there); "" omits it. - ResourceAttributes: extra Resource attributes on every signal; first-class keys (service.*, host.name, site.id, node.role) are reserved and rejected at startup. - Logs over OTLP: AddZbTelemetry publishes its options in DI and AddZbSerilog's OTLP log sink follows them when its own options do not select Otlp, so <App>:Telemetry:Exporter=Otlp now switches logs along with metrics and traces, with the same endpoint and Resource. ExportLogs=false opts out. - Ships the unpublished 0.2.1 review fixes, including the stricter OTLP endpoint check (scheme-less host:port rejected when Exporter=Otlp); no app config sets an endpoint. - Tests 42 -> 74, incl. a loopback OTLP/gRPC receiver proving logs arrive with the Resource, and an ExportLogs=false case with a metrics positive control. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
@@ -49,7 +49,7 @@ follow-on (tracked in `components/observability/GAPS.md`).
|
||||
|---|---|
|
||||
| **Metrics** | App Meters (via `options.Meters[]`) + standard: ASP.NET Core, HttpClient, .NET runtime, process. Exported via Prometheus (always on) with OTLP as an additive overlay. |
|
||||
| **Traces** | App ActivitySources (via `options.ActivitySources[]`) + standard: ASP.NET Core, HttpClient, gRPC client. Exported via OTLP when `Exporter = ZbExporter.Otlp`. |
|
||||
| **Logs** | Wired by `AddZbSerilog` (companion call). Serilog is used as the log sink; logs are bridged to OpenTelemetry via `Serilog.Sinks.OpenTelemetry` when configured. |
|
||||
| **Logs** | Wired by `AddZbSerilog` (companion call). Serilog is used as the log sink; logs are bridged to OpenTelemetry via `Serilog.Sinks.OpenTelemetry` when OTLP is selected. **0.3.0+:** the OTLP log sink follows the `AddZbTelemetry` registration in the same container, so `Exporter = Otlp` on `AddZbTelemetry` alone sends logs to the same endpoint with the same Resource (`ExportLogs = false` opts out). Options passed to `AddZbSerilog` that select OTLP themselves still win (for a logger built outside the host container, e.g. ScadaBridge). |
|
||||
|
||||
Trace↔log correlation is automatic: `TraceContextEnricher` reads `Activity.Current` for each
|
||||
log event and attaches `trace_id` and `span_id`, so log events produced inside a traced request
|
||||
@@ -71,6 +71,18 @@ intact (not reallocated). See the `ILogRedactor` XML doc for the full contract.
|
||||
|
||||
---
|
||||
|
||||
## Resource identity (0.3.0+)
|
||||
|
||||
| Attribute | Source |
|
||||
|---|---|
|
||||
| `service.name` / `service.namespace` | `ServiceName` (required) / `ServiceNamespace` (default `ZB.MOM.WW`) |
|
||||
| `service.version` | `ServiceVersion`; **`null` (default) = the entry assembly's `AssemblyInformationalVersion`** (the family apps stamp the git SHA there), `""` = omit, any other value = override |
|
||||
| `site.id` / `node.role` | `SiteId` / `NodeRole` (omitted when null/empty) |
|
||||
| `service.instance.id` / `host.name` | computed: `MachineName:ProcessId` / `MachineName` |
|
||||
| anything else | `ResourceAttributes` (e.g. `["otopcua.cluster.id"] = "c1"`); the keys above are reserved and rejected at startup |
|
||||
|
||||
The same attribute set goes to metrics, traces and the OTLP log sink.
|
||||
|
||||
## Exporter options
|
||||
|
||||
Prometheus is **always wired** for metrics regardless of the `Exporter` setting. OTLP is an
|
||||
@@ -144,9 +156,11 @@ backend):
|
||||
|
||||
| Assembly | Tests |
|
||||
|---|---|
|
||||
| `ZB.MOM.WW.Telemetry.Tests` | 12 |
|
||||
| `ZB.MOM.WW.Telemetry.Serilog.Tests` | 30 |
|
||||
| **Total** | **42** |
|
||||
| `ZB.MOM.WW.Telemetry.Tests` | 35 |
|
||||
| `ZB.MOM.WW.Telemetry.Serilog.Tests` | 39 |
|
||||
| **Total** | **74** |
|
||||
|
||||
The log-export tests start a loopback OTLP/gRPC receiver on Kestrel (no external collector).
|
||||
|
||||
---
|
||||
|
||||
@@ -159,8 +173,8 @@ dotnet pack ZB.MOM.WW.Telemetry.slnx -c Release -o ./artifacts
|
||||
Produces two `.nupkg` files in `artifacts/`:
|
||||
|
||||
```
|
||||
ZB.MOM.WW.Telemetry.0.2.0.nupkg
|
||||
ZB.MOM.WW.Telemetry.Serilog.0.2.0.nupkg
|
||||
ZB.MOM.WW.Telemetry.0.3.0.nupkg
|
||||
ZB.MOM.WW.Telemetry.Serilog.0.3.0.nupkg
|
||||
```
|
||||
|
||||
`GeneratePackageOnBuild` is off — pack explicitly as above. Both packages are versioned
|
||||
@@ -170,12 +184,11 @@ lockstep from `Directory.Build.props`.
|
||||
|
||||
## Status
|
||||
|
||||
**`0.1.0` is on the Gitea feed and adopted by all four apps** (OtOpcUa, MxAccessGateway, ScadaBridge,
|
||||
HistorianGateway): each pins `ZB.MOM.WW.Telemetry` + `ZB.MOM.WW.Telemetry.Serilog` `0.1.0` and calls
|
||||
`AddZbTelemetry`; all but ScadaBridge call `AddZbSerilog` (ScadaBridge keeps its own
|
||||
`LoggerConfigurationFactory` and adds only `TraceContextEnricher`). Verified against each repo's origin default
|
||||
branch 2026-11-09. **`0.2.0`** (the `AddZbSerilog` minimum-level governance hook, scadaproj#12) is built here but
|
||||
**not published**. Adoption history is in the component backlog:
|
||||
**`0.3.0`** (scadaproj#55) is the current release on the Gitea feed: `service.version` defaults from the
|
||||
entry assembly, `ResourceAttributes` for extra Resource attributes, logs follow `AddZbTelemetry`'s OTLP
|
||||
exporter, and the 0.2.1 review fixes (including the stricter OTLP endpoint check: a scheme-less
|
||||
`host:port` now fails at startup when `Exporter = Otlp`). Feed versions: `0.1.0`, `0.2.0`, `0.3.0`
|
||||
(`0.2.1` was never published). Consumer pins: see `CLAUDE.md`. Adoption history is in the component backlog:
|
||||
|
||||
- `~/Desktop/scadaproj/components/observability/GAPS.md`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user