Skip to content

Add Unity server telemetry sample for PlayFab MPS#95

Draft
dgkanatsios wants to merge 3 commits intomainfrom
unity-server-telemetry-sample
Draft

Add Unity server telemetry sample for PlayFab MPS#95
dgkanatsios wants to merge 3 commits intomainfrom
unity-server-telemetry-sample

Conversation

@dgkanatsios
Copy link
Copy Markdown
Contributor

Summary

New UnityServerTelemetry/ sample with 3 drop-in C# scripts that collect game server metrics and send them to the PlayFab Telemetry API.

Scripts

  • ServerMetricsCollector.cs — Collects 17 metrics (simulation rate, memory, CPU, game state) via ProfilerRecorder, Profiler API, GC, and System.Diagnostics.Process
  • PlayFabTelemetrySender.cs — Sends batched events to WriteTelemetryEvents API with X-TelemetryKey auth
  • ServerTelemetryManager.cs — Orchestrator with configurable intervals; reads telemetry key from MPS managed secrets (PF_MPS_SECRET_TelemetryKey) or Inspector

Metrics Collected

Category Metrics
Simulation Update loop rate, avg/max frame time, fixed tick rate
Memory Total used, GC used/reserved, GC alloc/frame, Mono heap/used
CPU CPU % (best-effort), GC gen 0/1/2 counts, thread count
Game Connected players, max players, uptime, network objects

Design

  • No PlayFab SDK dependency — raw REST via UnityWebRequest
  • MPS secrets for telemetry key management (recommended) or hardcoded for local testing
  • ~1-3 ms overhead every 30s, <1 microsecond per frame
  • Networking-agnostic — works with any Unity networking solution

New sample that collects game server metrics (simulation rate, memory,
CPU, game state) and sends them to the PlayFab Telemetry API using a
telemetry key.

Files:
- ServerMetricsCollector: collects 17 metrics via ProfilerRecorder,
  Profiler API, GC, and System.Diagnostics.Process (best-effort)
- PlayFabTelemetrySender: sends events to WriteTelemetryEvents API
  with X-TelemetryKey auth, batching up to 200 events
- ServerTelemetryManager: orchestrates collection/sending with
  configurable intervals, supports MPS managed secrets for the
  telemetry key (PF_MPS_SECRET_TelemetryKey env var)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Unity sample (UnityServerTelemetry/) that collects dedicated server performance/game metrics and ships them to PlayFab’s Telemetry API using a telemetry key (no PlayFab SDK dependency), plus a top-level README entry linking to it.

Changes:

  • Introduces a ServerTelemetryManager orchestrator for periodic collection + batch sending.
  • Adds a ServerMetricsCollector using Unity profiling/GC/process APIs to snapshot metrics.
  • Adds a PlayFabTelemetrySender that posts batches to WriteTelemetryEvents, and documents setup/integration in a new sample README.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
UnityServerTelemetry/Scripts/ServerTelemetryManager.cs Adds orchestration for collection/sending, config resolution (env/Inspector), buffering, and lifecycle hooks.
UnityServerTelemetry/Scripts/ServerMetricsCollector.cs Implements metrics snapshot collection via ProfilerRecorder/Profiler/GC/Process APIs.
UnityServerTelemetry/Scripts/PlayFabTelemetrySender.cs Implements raw REST batching to WriteTelemetryEvents with X-TelemetryKey auth.
UnityServerTelemetry/README.md Documents setup, metrics, and optional GSDK lifecycle wiring for the new sample.
README.md Adds a repository-level section linking to the new Unity server telemetry sample.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Dimitris Ilias Gkanatsios and others added 2 commits April 8, 2026 17:46
Fixes applied from reviews by Claude Opus 4.6, Sonnet 4, GPT-5.2,
Haiku 4.5, and GPT-4.1:

- Fix locale-dependent float serialization (use InvariantCulture)
- Fix Entity field casing to lowercase (type/id per telemetry docs)
- Fix Process.GetCurrentProcess() handle leak (wrap in using)
- Fix WaitForSeconds → WaitForSecondsRealtime (timeScale immunity)
- Fix division by zero when processorCount is 0
- Fix ProfilerRecorder.StartNew() crash on unsupported platforms
- Fix README GSDK example: add Initialize() for deferred config
- Add UnityWebRequest timeout (30s)
- Add singleton guard to prevent duplicate managers
- Add timestamp JSON escaping
- Add entity ID truncation to 64 chars (API limit)
- Add bounded buffer (500 max, drop-oldest)
- Remove broken StopTelemetry flush (coroutine can't complete)
- Rename gcAllocatedPerFrameBytes → lastFrameGcAllocBytes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Use _titleId field instead of constructor parameter for URL
- Fix 'Not render FPS' grammar in README metrics table

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants