Skip to content

Commit

Permalink
Publish version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzybinary committed Jul 22, 2024
1 parent 1b78183 commit dff0671
Show file tree
Hide file tree
Showing 23 changed files with 497 additions and 98 deletions.
Binary file modified .DS_Store
Binary file not shown.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Change Log

## 1.2.0

* Add and option to control when trace context headers are injected into web requests (Trace Context Injection).
* Add support for global log attributes, which adds attributes to logs sent from all loggers.
* Add the ability to customize your Service Name from the Datadog Options dialog.
* Update iOS SDK to 2.14.1
* Add support for Watchdog Terminations tracking in RUM
* Use #fileID over #filePath as default argument in errors.
* Fix compilation error in Xcode 16.
* Update IPHONEOS_DEPLOYMENT_TARGET to 12.0
* Add support for Fatal App Hangs tracking in RUM
* Update Android SDK to 2.11.0
* Optimise `BatchFileOrchestator` performance.
* Use custom naming for threads created inside SDK.
* Start sending batches immediately after feature is initialized.
* Add status code in user-facing message in case of UnknownError during batch upload.

## 1.1.3

* Fix `setVerbosity` on Android.
Expand Down
1 change: 1 addition & 0 deletions Editor/DatadogConfigurationOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static DatadogConfigurationOptions GetOrCreate(string settingsPath = null
options.ClientToken = string.Empty;
options.Enabled = true;
options.Env = string.Empty;
options.ServiceName = string.Empty;
options.OutputSymbols = false;
options.Site = DatadogSite.Us1;
options.CustomEndpoint = string.Empty;
Expand Down
5 changes: 4 additions & 1 deletion Editor/DatadogConfigurationWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public override void OnGUI(string searchContext)

_options.ClientToken = EditorGUILayout.TextField("Client Token", _options.ClientToken);
_options.Env = EditorGUILayout.TextField("Env", _options.Env);
_options.ServiceName = EditorGUILayout.TextField("Service Name", _options.ServiceName);
_options.Site = (DatadogSite)EditorGUILayout.EnumPopup("Datadog Site", _options.Site);
_options.CustomEndpoint = EditorGUILayout.TextField("Custom Endpoint", _options.CustomEndpoint);
_options.BatchSize = (BatchSize)EditorGUILayout.EnumPopup("Batch Size", _options.BatchSize);
_options.UploadFrequency = (UploadFrequency)EditorGUILayout.EnumPopup("Upload Frequency", _options.UploadFrequency);
_options.BatchProcessingLevel = (BatchProcessingLevel)EditorGUILayout.EnumPopup("Batch Processing Level", _options.BatchProcessingLevel);
Expand Down Expand Up @@ -80,6 +80,8 @@ public override void OnGUI(string searchContext)
_options.SessionSampleRate = Math.Clamp(_options.SessionSampleRate, 0.0f, 100.0f);
_options.TraceSampleRate =
EditorGUILayout.FloatField("Trace Sample Rate", _options.TraceSampleRate);
_options.TraceContextInjection =
(TraceContextInjection)EditorGUILayout.EnumPopup("Trace Context Injection", _options.TraceContextInjection);
_options.TraceSampleRate = Math.Clamp(_options.TraceSampleRate, 0.0f, 100.0f);

GUILayout.Space(12.0f);
Expand Down Expand Up @@ -116,6 +118,7 @@ public override void OnGUI(string searchContext)
_showAdvancedOptions = EditorGUILayout.BeginFoldoutHeaderGroup(_showAdvancedOptions, "Advanced RUM Options");
if (_showAdvancedOptions)
{
_options.CustomEndpoint = EditorGUILayout.TextField("Custom Endpoint", _options.CustomEndpoint);
_options.SdkVerbosity = (CoreLoggerLevel)EditorGUILayout.EnumPopup("SDK Verbosity", _options.SdkVerbosity);
_options.TelemetrySampleRate =
EditorGUILayout.FloatField("Telemetry Sample Rate", _options.TelemetrySampleRate);
Expand Down
14 changes: 7 additions & 7 deletions Editor/DatadogDependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
<repository>https://repo.maven.apache.org/maven2</repository>
<repository>https://oss.sonatype.org/content/repositories/snapshots</repository>
</repositories>
<androidPackage spec="com.datadoghq:dd-sdk-android-rum:2.10.1">
<androidPackage spec="com.datadoghq:dd-sdk-android-rum:2.11.0">
</androidPackage>
<androidPackage spec="com.datadoghq:dd-sdk-android-logs:2.10.1">
<androidPackage spec="com.datadoghq:dd-sdk-android-logs:2.11.0">
</androidPackage>
<androidPackage spec="com.datadoghq:dd-sdk-android-ndk:2.10.1">
<androidPackage spec="com.datadoghq:dd-sdk-android-ndk:2.11.0">
</androidPackage>
</androidPackages>
<iosPods>
<iosPod name="DatadogCore" bitcodeEnabled="false" minTargetSdk="12.0" version="2.9.0" />
<iosPod name="DatadogLogs" bitcodeEnabled="false" minTargetSdk="12.0" version="2.9.0" />
<iosPod name="DatadogRUM" bitcodeEnabled="false" minTargetSdk="12.0" version="2.9.0" />
<iosPod name="DatadogCrashReporting" bitcodeEnabled="false" minTargetSdk="12.0" version="2.9.0" />
<iosPod name="DatadogCore" bitcodeEnabled="false" minTargetSdk="12.0" version="2.14.1" />
<iosPod name="DatadogLogs" bitcodeEnabled="false" minTargetSdk="12.0" version="2.14.1" />
<iosPod name="DatadogRUM" bitcodeEnabled="false" minTargetSdk="12.0" version="2.14.1" />
<iosPod name="DatadogCrashReporting" bitcodeEnabled="false" minTargetSdk="12.0" version="2.14.1" />
</iosPods>
</dependencies>
74 changes: 58 additions & 16 deletions Editor/SymbolAssemblyBuildProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using UnityEditor;
using UnityEditor.Android;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
using UnityEngine.Device;
using Debug = UnityEngine.Debug;

namespace Datadog.Unity.Editor
{
public class SymbolAssemblyBuildProcess : IPostprocessBuildWithReport, IPostGenerateGradleAndroidProject
{
internal const string DatadogSymbolsDir = "datadogSymbols";
internal const string AndroidLineNumberMappingsOutputPath = "build/symbols";
internal const string IosDatadogSymbolsDir = "datadogSymbols";
internal const string AndroidSymbolsDir = "symbols";
internal const string AndroidLineNumberMappingsOutputPath = "symbols";

// Relative to the output directory
internal const string IosLineNumberMappingsLocation =
Expand Down Expand Up @@ -44,12 +47,21 @@ internal IBuildFileSystemProxy fileSystemProxy
public void OnPostprocessBuild(BuildReport report)
{
var options = DatadogConfigurationOptionsExtensions.GetOrCreate();
CopySymbols(options, report.summary.platformGroup, report.summary.guid.ToString(), report.summary.outputPath);
if (report.summary.platformGroup == BuildTargetGroup.iOS)
{
WriteBuildId(options, report.summary.platformGroup, report.summary.guid.ToString(), report.summary.outputPath);
}

CopySymbols(options, report.summary.platformGroup, report.summary.guid.ToString(),
report.summary.outputPath);
}

public void OnPostGenerateGradleAndroidProject(string path)
{
var options = DatadogConfigurationOptionsExtensions.GetOrCreate();
// Since Unity doesn't give us a copy of a buildGUID at this stage, generate our own.
var buildGuid = Guid.NewGuid().ToString();
WriteBuildId(options, BuildTargetGroup.Android, buildGuid, path);
AndroidCopyMappingFile(options, path);
}

Expand Down Expand Up @@ -95,25 +107,55 @@ internal void AndroidCopyMappingFile(DatadogConfigurationOptions options, string
}
}

internal void CopySymbols(DatadogConfigurationOptions options, BuildTargetGroup platformGroup, string buildGuid, string outputPath)
internal void WriteBuildId(DatadogConfigurationOptions options,
BuildTargetGroup platformGroup,
string buildGuid,
string outputPath)
{
if (platformGroup is not (BuildTargetGroup.Android or BuildTargetGroup.iOS))
{
// Only copy symbols for Android and iOS
return;
}

if (options.Enabled && options.OutputSymbols)
{
// Only iOS for now, but might change in the future
var shouldOutputBuildId = platformGroup == BuildTargetGroup.iOS;
var outputDir = platformGroup switch
{
BuildTargetGroup.Android => AndroidSymbolsDir,
BuildTargetGroup.iOS => IosDatadogSymbolsDir,
_ => ""
};

if (shouldOutputBuildId)
var symbolsDir = Path.Join(outputPath, outputDir);
if (!_fileSystemProxy.DirectoryExists(symbolsDir))
{
var symbolsDir = Path.Join(outputPath, DatadogSymbolsDir);
if (!_fileSystemProxy.DirectoryExists(symbolsDir))
{
_fileSystemProxy.CreateDirectory(symbolsDir);
}
_fileSystemProxy.CreateDirectory(symbolsDir);
}

var buildIdPath = Path.Join(symbolsDir, "build_id");
_fileSystemProxy.WriteAllText(buildIdPath, buildGuid);
var buildIdPath = Path.Join(symbolsDir, "build_id");
_fileSystemProxy.WriteAllText(buildIdPath, buildGuid);

if (platformGroup == BuildTargetGroup.Android)
{
// Write the build id to the Android assets directory
var androidAssetsDir = Path.Join(outputPath, "src/main/assets");
var androidBuildIdPath = Path.Join(androidAssetsDir, "datadog.buildId");
_fileSystemProxy.WriteAllText(androidBuildIdPath, buildGuid);
}
}
}

internal void CopySymbols(DatadogConfigurationOptions options, BuildTargetGroup platformGroup, string buildGuid, string outputPath)
{
if (platformGroup is not (BuildTargetGroup.Android or BuildTargetGroup.iOS))
{
// Only copy symbols for Android and iOS
return;
}

if (options.Enabled && options.OutputSymbols)
{
switch (platformGroup)
{
case BuildTargetGroup.iOS:
Expand All @@ -128,7 +170,7 @@ internal void CopySymbols(DatadogConfigurationOptions options, BuildTargetGroup
private void CopyIosSymbolFiles(string outputPath)
{
var mappingsSrcPath = Path.Join(outputPath, IosLineNumberMappingsLocation);
var mappingsDestPath = Path.Join(outputPath, DatadogSymbolsDir, "LineNumberMappings.json");
var mappingsDestPath = Path.Join(outputPath, IosDatadogSymbolsDir, "LineNumberMappings.json");
if (_fileSystemProxy.FileExists(mappingsSrcPath))
{
Debug.Log("Copying IL2CPP mappings file...");
Expand Down
19 changes: 14 additions & 5 deletions Editor/iOS/PostBuildProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void OnPostprocessBuild(BuildReport report)

if (datadogOptions.OutputSymbols)
{
AddSymbolGenAndCopyToProject(pbxProject, SymbolAssemblyBuildProcess.DatadogSymbolsDir);
AddSymbolGenAndCopyToProject(pbxProject, SymbolAssemblyBuildProcess.IosDatadogSymbolsDir);
}

// disable embed swift libs - prevents "UnityFramework.framework contains disallowed file 'Frameworks'."
Expand All @@ -88,6 +88,8 @@ internal static void GenerateInitializationFile(string path, DatadogConfiguratio
env = "prod";
}

var serviceName = options.ServiceName;

var sdkVersion = DatadogSdk.SdkVersion;
var sdkLogLevel = GetSwiftCoreLoggerLevel(options.SdkVerbosity);

Expand All @@ -106,7 +108,14 @@ func initializeDatadog() {{
clientToken: ""{options.ClientToken}"",
env: ""{env}"",
site: {GetSwiftSite(options.Site)},
batchSize: {GetSwiftBatchSize(options.BatchSize)},
");

if (!(serviceName is null or ""))
{
sb.AppendLine($" service: \"{serviceName}\",");
}

sb.Append($@" batchSize: {GetSwiftBatchSize(options.BatchSize)},
uploadFrequency: {GetSwiftUploadFrequency(options.UploadFrequency)},
batchProcessingLevel: {GetSwiftBatchProcessingLevel(options.BatchProcessingLevel)}
)
Expand Down Expand Up @@ -143,7 +152,7 @@ func initializeDatadog() {{
");
if (options.CustomEndpoint != string.Empty)
{
sb.AppendLine($@" logsConfig.customEndpoint = URL(string: ""{options.CustomEndpoint}/logs"")");
sb.AppendLine($@" logsConfig.customEndpoint = URL(string: ""{options.CustomEndpoint}/api/v2/logs"")");
}

sb.AppendLine(" Logs.enable(with: logsConfig)");
Expand All @@ -157,7 +166,7 @@ func initializeDatadog() {{
");
if (options.CustomEndpoint != string.Empty)
{
sb.AppendLine($@" rumConfig.customEndpoint = URL(string: ""{options.CustomEndpoint}/rum"")");
sb.AppendLine($@" rumConfig.customEndpoint = URL(string: ""{options.CustomEndpoint}/api/v2/rum"")");
}

if (options.VitalsUpdateFrequency != VitalsUpdateFrequency.None)
Expand Down Expand Up @@ -204,7 +213,7 @@ internal static void AddSymbolGenAndCopyToProject(PBXProject pbxProject, string

var copyDsymScript = new StringBuilder(@$"
cd ""$BUILT_PRODUCTS_DIR""
find . -type d -name '*.dSYM' -exec cp -r '{{}}' ""$PROJECT_DIR/{SymbolAssemblyBuildProcess.DatadogSymbolsDir}/"" ';'
find . -type d -name '*.dSYM' -exec cp -r '{{}}' ""$PROJECT_DIR/{SymbolAssemblyBuildProcess.IosDatadogSymbolsDir}/"" ';'
");

pbxProject.AddShellScriptBuildPhase(mainTarget, CopyPhaseName, "/bin/bash", copyDsymScript.ToString());
Expand Down
24 changes: 24 additions & 0 deletions Plugins/iOS/Datadog_Bridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import Foundation
import DatadogCore
import DatadogLogs
import DatadogInternal

@_cdecl("Datadog_SetSdkVerbosity")
Expand All @@ -27,6 +28,29 @@ func Datadog_SetTrackingConsent(trackingConsentInt: Int) {
}
}

@_cdecl("Datadog_AddLogsAttributes")
func Datadog_AddLogsAttributes(jsonAttributes: CString?) {
guard let jsonAttributes = jsonAttributes else {
return
}

let decodedAttributes = decodeJsonAttributes(fromCString: jsonAttributes);
for attr in decodedAttributes {
Logs.addAttribute(forKey: attr.key, value: attr.value)
}
}

@_cdecl("Datadog_RemoveLogsAttributes")
func Datadog_RemoveLogsAttributes(key: CString?) {
guard let key = key else {
return
}

if let swiftKey = String(cString: key, encoding: .utf8) {
Logs.removeAttribute(forKey: swiftKey)
}
}

@_cdecl("Datadog_SetUserInfo")
func Datadog_SetUserInfo(
id: CString?,
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The Datadog Unity SDK supports logging and crash reporting for Android and iOS a
> [!NOTE]
> Datadog plans on adding support for Open UPM after Closed Beta.
4.. Configure your project to use [Gradle templates](https://docs.unity3d.com/Manual/gradle-templates.html), and enable both `Custom Main Template` and `Custom Gradle Properties Template`.
4. Configure your project to use [Gradle templates](https://docs.unity3d.com/Manual/gradle-templates.html), and enable both `Custom Main Template` and `Custom Gradle Properties Template`.

5. If you build and recieve `Duplicate class` errors (common in Unity 2022.x) add the following block in the `dependencies` block in your `mainTemplate.gradle`:

Expand Down Expand Up @@ -105,7 +105,7 @@ logger.Debug("Hello with attributes", new()

### Manual Scene (View) Tracking

To manually track new Scenes (`Views` id Datadog), use the `StartVeiw` and `StopView` methods:
To manually track new Scenes (`Views` in Datadog), use the `StartView` and `StopView` methods:

```cs
public void Start()
Expand Down
24 changes: 21 additions & 3 deletions Runtime/Android/DatadogAndroidPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ public void Init(DatadogConfigurationOptions options)
environment = "prod";
}

var serviceName = options.ServiceName == string.Empty ? null : options.ServiceName;

using var configBuilder = new AndroidJavaObject(
"com.datadog.android.core.configuration.Configuration$Builder",
options.ClientToken,
environment,
string.Empty, // Variant Name
null // Service Name
serviceName // Service Name
);
configBuilder.Call<AndroidJavaObject>("useSite", DatadogConfigurationHelpers.GetSite(options.Site));
configBuilder.Call<AndroidJavaObject>("setBatchSize", DatadogConfigurationHelpers.GetBatchSize(options.BatchSize));
Expand Down Expand Up @@ -92,7 +94,7 @@ public void Init(DatadogConfigurationOptions options)
using var logsConfigBuilder = new AndroidJavaObject("com.datadog.android.log.LogsConfiguration$Builder");
if (options.CustomEndpoint != string.Empty)
{
logsConfigBuilder.Call<AndroidJavaObject>("useCustomEndpoint", options.CustomEndpoint + "/logs");
logsConfigBuilder.Call<AndroidJavaObject>("useCustomEndpoint", options.CustomEndpoint);
}

using var logsConfig = logsConfigBuilder.Call<AndroidJavaObject>("build");
Expand All @@ -105,7 +107,7 @@ public void Init(DatadogConfigurationOptions options)
rumConfigBuilder.Call<AndroidJavaObject>("disableUserInteractionTracking");
if (options.CustomEndpoint != string.Empty)
{
rumConfigBuilder.Call<AndroidJavaObject>("useCustomEndpoint", options.CustomEndpoint + "/rum");
rumConfigBuilder.Call<AndroidJavaObject>("useCustomEndpoint", options.CustomEndpoint);
}

rumConfigBuilder.Call<AndroidJavaObject>("useViewTrackingStrategy", new object[] { null });
Expand Down Expand Up @@ -192,6 +194,22 @@ public DdLogger CreateLogger(DatadogLoggingOptions options, DatadogWorker worker
return new DdWorkerProxyLogger(worker, innerLogger);
}

public void AddLogsAttributes(Dictionary<string, object> attributes)
{
using var logsClass = new AndroidJavaClass("com.datadog.android.log.Logs");
foreach (var attr in attributes)
{
AndroidJavaObject javaValue = DatadogAndroidHelpers.ObjectToJavaObject(attr.Value);
logsClass.CallStatic("addAttribute", attr.Key, javaValue);
}
}

public void RemoveLogsAttribute(string key)
{
using var logsClass = new AndroidJavaClass("com.datadog.android.log.Logs");
logsClass.CallStatic("removeAttribute", key);
}

public IDdRum InitRum(DatadogConfigurationOptions options)
{
using var globalRumMonitorClass = new AndroidJavaClass("com.datadog.android.rum.GlobalRumMonitor");
Expand Down
2 changes: 1 addition & 1 deletion Runtime/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyVersion("1.1.3")]
[assembly: AssemblyVersion("1.2.0")]
[assembly: InternalsVisibleTo("com.datadoghq.unity.tests")]
[assembly: InternalsVisibleTo("com.datadoghq.unity.android")]
[assembly: InternalsVisibleTo("com.datadoghq.unity.ios")]
Expand Down
Loading

0 comments on commit dff0671

Please sign in to comment.