initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
|
||||
namespace Unity.Services.Core.Telemetry.Internal
|
||||
{
|
||||
static class CacheExtensions
|
||||
{
|
||||
public static bool IsEmpty<TPayload>(this CachedPayload<TPayload> self)
|
||||
where TPayload : ITelemetryPayload
|
||||
{
|
||||
return (self.Payload?.Count ?? 0) <= 0;
|
||||
}
|
||||
|
||||
public static void AddRangeFrom(
|
||||
this CachedPayload<DiagnosticsPayload> self, CachedPayload<DiagnosticsPayload> payload)
|
||||
{
|
||||
var hasDiagnosticsToAdd = payload.Payload.Diagnostics.Count > 0;
|
||||
if (hasDiagnosticsToAdd)
|
||||
{
|
||||
self.Payload.Diagnostics.AddRange(payload.Payload.Diagnostics);
|
||||
}
|
||||
|
||||
if (hasDiagnosticsToAdd
|
||||
&& self.TimeOfOccurenceTicks <= 0)
|
||||
{
|
||||
self.TimeOfOccurenceTicks = payload.TimeOfOccurenceTicks;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Add<TPayload>(this CachedPayload<TPayload> self, ITelemetryEvent telemetryEvent)
|
||||
where TPayload : ITelemetryPayload
|
||||
{
|
||||
if (self.TimeOfOccurenceTicks == 0)
|
||||
{
|
||||
self.TimeOfOccurenceTicks = DateTime.UtcNow.Ticks;
|
||||
}
|
||||
|
||||
self.Payload.Add(telemetryEvent);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 03bfba0c7dddf814d81dea93d3248e62
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,28 @@
|
|||
using System.Collections.Generic;
|
||||
using Unity.Services.Core.Configuration.Internal;
|
||||
using Unity.Services.Core.Internal;
|
||||
|
||||
namespace Unity.Services.Core.Telemetry.Internal
|
||||
{
|
||||
static class FactoryUtils
|
||||
{
|
||||
internal const string PackageVersionKeyFormat = "{0}.version";
|
||||
|
||||
public static IDictionary<string, string> CreatePackageTags(
|
||||
IProjectConfiguration projectConfig, string packageName)
|
||||
{
|
||||
var packageVersion = projectConfig.GetString(
|
||||
string.Format(PackageVersionKeyFormat, packageName), string.Empty);
|
||||
if (string.IsNullOrEmpty(packageVersion))
|
||||
{
|
||||
CoreLogger.LogTelemetry($"No package version found for the package \"{packageName}\"");
|
||||
}
|
||||
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
[TagKeys.PackageName] = packageName,
|
||||
[TagKeys.PackageVersion] = packageVersion,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 97fbf25a3dc582348a4d5fff07736c6e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,35 @@
|
|||
namespace Unity.Services.Core.Telemetry.Internal
|
||||
{
|
||||
static class TagKeys
|
||||
{
|
||||
public const string ApplicationInstallMode = "application_install_mode";
|
||||
|
||||
public const string OperatingSystem = "operating_system";
|
||||
|
||||
public const string Platform = "platform";
|
||||
|
||||
public const string Engine = "engine";
|
||||
|
||||
public const string UnityVersion = "unity_version";
|
||||
|
||||
public const string PackageName = "package_name";
|
||||
|
||||
public const string PackageVersion = "package_version";
|
||||
|
||||
public const string DiagnosticName = "name";
|
||||
|
||||
public const string DiagnosticMessage = "message";
|
||||
|
||||
public const string ApplicationVersion = "application_version";
|
||||
|
||||
public const string ProductName = "product_name";
|
||||
|
||||
public const string CloudProjectId = "cloud_project_id";
|
||||
|
||||
public const string EnvironmentName = "environment_name";
|
||||
|
||||
public const string ApplicationGenuine = "application_genuine";
|
||||
|
||||
public const string InternetReachability = "internet_reachability";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 65d7ef18358fe33498a7d554418dfbe7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,19 @@
|
|||
namespace Unity.Services.Core.Telemetry.Internal
|
||||
{
|
||||
static class TelemetryConfigKeys
|
||||
{
|
||||
const string k_BaseKey = "com.unity.services.core.telemetry-";
|
||||
|
||||
public const string TargetUrl = k_BaseKey + "target-url";
|
||||
|
||||
public const string ServicePath = k_BaseKey + "service-path";
|
||||
|
||||
public const string PayloadExpirationSeconds = k_BaseKey + "payload-expiration-seconds";
|
||||
|
||||
public const string PayloadSendingMaxIntervalSeconds = k_BaseKey + "payload-sending-max-interval-seconds";
|
||||
|
||||
public const string SafetyPersistenceIntervalSeconds = k_BaseKey + "safety-persistence-interval-seconds";
|
||||
|
||||
public const string MaxMetricCountPerPayload = k_BaseKey + "max-metric-count-per-payload";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1e808fd14ebfe6c4994ae957d6ca2b4d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,109 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Services.Core.Configuration.Internal;
|
||||
using Unity.Services.Core.Environments.Internal;
|
||||
using Unity.Services.Core.Scheduler.Internal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.Services.Core.Telemetry.Internal
|
||||
{
|
||||
static class TelemetryUtils
|
||||
{
|
||||
internal const string TelemetryDisabledKey = "com.unity.services.core.telemetry-disabled";
|
||||
|
||||
public static IMetricsFactory CreateMetricsFactory(
|
||||
IActionScheduler scheduler, IProjectConfiguration projectConfiguration, ICloudProjectId cloudProjectId,
|
||||
IEnvironments environments)
|
||||
{
|
||||
if (IsTelemetryDisabled(projectConfiguration))
|
||||
{
|
||||
return new DisabledMetricsFactory();
|
||||
}
|
||||
|
||||
var config = CreateTelemetryConfig(projectConfiguration);
|
||||
var cache = new CachedPayload<MetricsPayload>
|
||||
{
|
||||
Payload = new MetricsPayload
|
||||
{
|
||||
Metrics = new List<Metric>(),
|
||||
CommonTags = new Dictionary<string, string>(),
|
||||
MetricsCommonTags = new Dictionary<string, string>(),
|
||||
},
|
||||
};
|
||||
var cachePersister = CreateCachePersister<MetricsPayload>("UnityServicesCachedMetrics", Application.platform);
|
||||
var retryPolicy = new ExponentialBackOffRetryPolicy();
|
||||
var requestSender = new UnityWebRequestSender();
|
||||
var metricsSender = new TelemetrySender(
|
||||
config.TargetUrl, config.ServicePath, scheduler, retryPolicy, requestSender);
|
||||
var handler = new MetricsHandler(config, cache, scheduler, cachePersister, metricsSender);
|
||||
handler.Initialize(cloudProjectId, environments);
|
||||
|
||||
return new MetricsFactory(handler, projectConfiguration);
|
||||
}
|
||||
|
||||
//TODO: Reuse components from MetricsFactory (or vice versa)
|
||||
public static IDiagnosticsFactory CreateDiagnosticsFactory(
|
||||
IActionScheduler scheduler, IProjectConfiguration projectConfiguration, ICloudProjectId cloudProjectId,
|
||||
IEnvironments environments)
|
||||
{
|
||||
if (IsTelemetryDisabled(projectConfiguration))
|
||||
{
|
||||
return new DisabledDiagnosticsFactory();
|
||||
}
|
||||
|
||||
var config = CreateTelemetryConfig(projectConfiguration);
|
||||
var cache = new CachedPayload<DiagnosticsPayload>
|
||||
{
|
||||
Payload = new DiagnosticsPayload
|
||||
{
|
||||
Diagnostics = new List<Diagnostic>(),
|
||||
CommonTags = new Dictionary<string, string>(),
|
||||
DiagnosticsCommonTags = new Dictionary<string, string>(),
|
||||
},
|
||||
};
|
||||
var cachePersister = CreateCachePersister<DiagnosticsPayload>("UnityServicesCachedDiagnostics", Application.platform);
|
||||
var retryPolicy = new ExponentialBackOffRetryPolicy();
|
||||
var requestSender = new UnityWebRequestSender();
|
||||
var metricsSender = new TelemetrySender(
|
||||
config.TargetUrl, config.ServicePath, scheduler, retryPolicy, requestSender);
|
||||
var handler = new DiagnosticsHandler(
|
||||
config, cache, scheduler, cachePersister, metricsSender);
|
||||
handler.Initialize(cloudProjectId, environments);
|
||||
|
||||
return new DiagnosticsFactory(handler, projectConfiguration);
|
||||
}
|
||||
|
||||
static bool IsTelemetryDisabled(IProjectConfiguration projectConfiguration)
|
||||
=> projectConfiguration.GetBool(TelemetryDisabledKey);
|
||||
|
||||
internal static ICachePersister<TPayload> CreateCachePersister<TPayload>(
|
||||
string fileName, RuntimePlatform platform)
|
||||
where TPayload : ITelemetryPayload
|
||||
{
|
||||
if (platform == RuntimePlatform.Switch)
|
||||
return new DisabledCachePersister<TPayload>();
|
||||
|
||||
return new FileCachePersister<TPayload>(fileName);
|
||||
}
|
||||
|
||||
internal static TelemetryConfig CreateTelemetryConfig(IProjectConfiguration projectConfiguration)
|
||||
{
|
||||
const string defaultTargetUrl = "https://operate-sdk-telemetry.unity3d.com";
|
||||
const string defaultServicePath = "v1/record";
|
||||
const int defaultPayloadExpirationSeconds = 3600;
|
||||
const int defaultPayloadSendingMaxIntervalSeconds = 600;
|
||||
const int defaultSafetyPersistenceIntervalSeconds = 300;
|
||||
|
||||
var config = new TelemetryConfig
|
||||
{
|
||||
TargetUrl = projectConfiguration.GetString(TelemetryConfigKeys.TargetUrl, defaultTargetUrl),
|
||||
ServicePath = projectConfiguration.GetString(TelemetryConfigKeys.ServicePath, defaultServicePath),
|
||||
PayloadExpirationSeconds = projectConfiguration.GetInt(TelemetryConfigKeys.PayloadExpirationSeconds, defaultPayloadExpirationSeconds),
|
||||
PayloadSendingMaxIntervalSeconds = projectConfiguration.GetInt(TelemetryConfigKeys.PayloadSendingMaxIntervalSeconds, defaultPayloadSendingMaxIntervalSeconds),
|
||||
SafetyPersistenceIntervalSeconds = projectConfiguration.GetInt(TelemetryConfigKeys.SafetyPersistenceIntervalSeconds, defaultSafetyPersistenceIntervalSeconds),
|
||||
MaxMetricCountPerPayload = Math.Min(TelemetryConfig.MaxMetricCountPerPayloadLimit, projectConfiguration.GetInt(TelemetryConfigKeys.MaxMetricCountPerPayload, TelemetryConfig.MaxMetricCountPerPayloadLimit)),
|
||||
};
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a3d8d4bd36f9820498053c2dac2e959c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue