Instrumentation and telemetry
Maria GDK5 provides lightweight operation spans and checkpoints for investigating initialization, service connections, rendering setup and shutdown. Managed and selected native operations can be viewed together. This complements ordinary application logs; it is not continuous frame profiling or GPU execution timing.
The authoritative configuration, API and transport details are in README_TELEMETRY.md. This page is a practical overview.
Enable recording in MariaApplication
Merge the following into the active GeneralConfiguration.json; retain the other configuration sections:
{
"startupTiming": {
"enabled": true,
"telemetryFileRecording": {
"enabled": true,
"logFilePath": "%TEMP%\\MariaGDK5Log\\StartupTiming_[tag].jsonl",
"rollingFiles": 4
},
"openTelemetry": {
"enabled": false,
"endpoint": "http://localhost:4318/v1/traces",
"batchIntervalMs": 1000,
"queueCapacity": 4096,
"requestTimeoutMs": 2000,
"shutdownTimeoutMs": 2000
}
}
}
startupTiming.enabledis the master switch and defaults to false. File recording and standalone remote delivery are independent, opt-in outputs. With the master enabled, a host listener can collect GDK Activities even when both outputs are off.- The per-user configuration in
%LOCALAPPDATA%\TeleplanGlobe\MariaGDKtakes precedence over the application-directory file. Configuration is read once early in launch. - For local overrides, copy
GeneralConfiguration.local.sample.jsontoGeneralConfiguration.local.jsonbeside the selected base file; omitted settings retain their base values. - The filename must contain exactly one
[tag], replaced with UTCyyyyMMdd-HHmmssfff-PID. Environment variables are expanded; relative paths use the working directory.rollingFilesincludes the current report and defaults to 1. The resolved path is logged inMariaApplication.log. - For live delivery, set
openTelemetry.enabledto true. The endpoint must accept OTLP/HTTP JSON traces, normally port 4318 with/v1/traces; OTLP/gRPC port 4317 and a Grafana UI URL are not interchangeable. Use HTTPS for remote endpoints.
Invalid output settings or output failures are logged and disable the affected output without preventing application startup. Ordinary logging is unaffected by the telemetry master switch. These configuration keys belong to MariaApplication, not to every application embedding GDK.
Inspect and interpret a recording
Open Src\Hosts\MariaApplication\StartupTimelineViewer\index.html locally in a desktop browser and select the .jsonl file. No web server is required. The viewer provides nested duration bars, parent guides, checkpoints, search, duration filtering and an overview with selectable time ranges. Native spans normally appear purple.
Interpretation:
- Follow parent/child relationships, not file order or thread numbers. Async work may overlap or finish after its parent; do not add overlapping durations.
- An ordinary scope ending means it closed, not necessarily that the operation succeeded. Missing endings identify incomplete work; the recorder does not fabricate completion.
- Startup timing begins at the
Appconstructor, excluding earlier process/runtime initialization.ContentRenderedis a UI milestone, not proof that all services, imagery or GPU work are ready. - First-show/first-render instrumentation is bounded per instance, not repeated every frame. Native timings are elapsed CPU-call times, including existing driver waits; they add no GPU synchronization.
- Compare several Release runs without a debugger, with equivalent configuration and service availability. Separate cold and warm runs. Immediate journal flushing adds measurement overhead.
JSONL is an append-only diagnostic journal, not an OTLP payload. Each record is flushed, allowing inspection of stalled startup. The viewer can export closed spans as OTLP JSON or Zipkin v2 JSON, independently of display filters. It can also import OTLP/Zipkin JSON for viewing, but cannot re-export those imports. See JOURNAL_FORMAT.md for schema and mapping details.
Instrument managed code
Use TPG.GDK.CommonCore.Telemetry.OperationTrace, provided by the TPG.GDK.CommonCore.Common assembly. No recorder is passed to components. Scopes nest through the logical async context:
using System;
using System.Threading.Tasks;
using TPG.GDK.CommonCore.Telemetry;
static async Task InitializeWithTimingAsync(Func<Task> loadCatalog)
{
using var step = OperationTrace.StartStep("Initialize map data");
try
{
await OperationTrace.MeasureAsync("Read map catalog", loadCatalog);
OperationTrace.Checkpoint("Catalog ready");
}
catch (OperationCanceledException)
{
step?.MarkCancelled();
throw;
}
catch (Exception exception)
{
step?.MarkFailed(exception);
throw;
}
}
StartStep can return null when disabled or no listener requests an Activity. Dispose scopes normally and mark failures/cancellation inside their lifetime. Measure/MeasureAsync handle thrown failures and cancellation automatically; their Completed outcome means normal return, not that a returned boolean/result indicates success. Mark returned failures explicitly where appropriate.
Use stable, meaningful names and coarse phases. Attributes can be supplied to StartStep; checkpoints also accept details and attributes. A host-only listener receives checkpoints as Activity events on an active GDK operation; top-level checkpoints require a local recorder.
Instrument native code
Native instrumentation uses the native-only MCommon interface:
#include <MTelemetry.h>
void InitializeResources()
{
Maria::TelemetryScope operation("Initialize native resources");
{
Maria::TelemetryScope phase("Prepare native buffers");
// Existing synchronous resource preparation.
}
Maria::telemetryCheckpoint("Native resources ready");
}
Scopes are inert without a thread-local telemetry context. For selected synchronous P/Invokes, GDK's internal shared interop wrapper installs that context. Example fragment inside that assembly, preserving the surrounding locking and first-draw gate:
using var context = NativeTelemetry.EnterCurrentContext(); NativeGeoLayerManager_DrawFrame(_nativeGeoLayerManager);
NativeTelemetry is internal GDK infrastructure, not a public integrator API. Native scopes become children of the captured managed operation and use the same journal/export path. Rebuild and deploy matching native binaries to obtain newly added scopes.
Safety requirements: enter, native work and leave must remain synchronous, on the same thread, in LIFO order. All native scopes/callbacks must finish before registration disposal; never cross an await, transfer registrations between threads or retain callbacks. Workers do not inherit the context. Re-entry captures the managed parent, not automatically the enclosing native span. Keep delegates rooted through native leave; the existing bridge owns this lifetime. Managed locking does not make registration ownership cross-thread safe.
Keep scopes/context in MCommon and callback pointers/calling conventions in MNativeInterfaceBridge, not SilentToolkit. Instrumented native targets need the appropriate MCommon dependency. Prefer bounded first-use/shutdown phases over per-object, per-tile or worker-loop instrumentation.
System integrators using Maria GDK
The host owns enablement, listeners, sampling, resource identity and delivery. GDK uses .NET 8 System.Diagnostics.Activity APIs without requiring the OpenTelemetry SDK. Collection is opt-in through listeners/recorders; OperationTrace.Enabled defaults to true in integrating applications. Setting it to false suppresses new GDK operations/checkpoints, not unrelated host telemetry.
Integrate with an existing tracing provider
Register the source before starting GDK work. In the host's existing OpenTelemetry tracing configuration:
using OpenTelemetry.Trace; using TPG.GDK.CommonCore.Telemetry; // Inside the host's tracing configuration callback: tracing.AddSource(OperationTrace.ActivitySourceName);
The source name is TPG.GDK.CommonCore.Telemetry. An ordinary ActivityListener is also supported. Call the usual GDK initialization/connection APIs: no trace-session injection or component-constructor changes are needed. Instrumented operations join the current host Activity, or start a trace when there is no ambient parent. Coverage is explicit, not automatic instrumentation of every GDK method.
Configure host resource identity, sampling and exporters in the host provider. Use a service name/version and a unique running-instance identity; machine names are not automatically collected by GDK.
Optional local recording
Create a bounded, host-owned recorder before the work of interest:
using System;
using TPG.GDK.CommonCore.Telemetry;
using var recording = new OperationTraceSession(
new OperationTraceSessionOptions("Map setup", "MyGdkHost")
{
ServiceVersion = "1.0"
},
filePath: $@"C:\Logs\Gdk-{Guid.NewGuid():N}.jsonl");
// Call the ordinary GDK APIs while this recorder is alive.
Use a new writable path; existing files are not overwritten. The recorder observes GDK operations process-wide during its lifetime, not only lexical children of its using block. It creates a journal-only root without replacing Activity.Current. Earlier operations are not replayed; unfinished operations are not completed on disposal. Keep the recorder alive through the relevant shutdown work.
For standalone remote delivery, the optional TPG.GDK.CommonCore.Telemetry assembly supplies OtlpTraceExporter/OtlpTraceExporterOptions. Pass one exporter per session as its consumer; close the session before asynchronously disposing/draining the exporter. Export is bounded, asynchronous and best-effort, not durable. See the README for the complete example and limits.
Local recording may coexist with host Activity export. Avoid exporting the same work to the same backend through both the host provider and the standalone exporter unless duplicate representations are intentional: the journal has its own trace/root identity. Keep recordings bounded rather than using one indefinitely open session.
Trace names, attributes, details and service endpoints are diagnostic data. Exclude credentials, tokens and sensitive payloads; control file access, retention and remote destinations.
Further information
- README_TELEMETRY.md: full configuration, instrumentation, integration, exporter lifecycle and limitations.
- Repository README: environment/build entry points.
- Journal format: record schema and export mapping.
- Development profiling: separate renderer frame-rate/performance-graph facilities.