通过 API 上传崩溃
重要
Visual Studio App Center 计划于 2025 年 3 月 31 日停用。 虽然可以继续使用 Visual Studio App Center,直到它完全停用,但你可以考虑迁移到几个建议的替代方法。
如果不想使用我们的 SDK 或针对自定义平台进行开发,可以上传故障报告。 将 崩溃、 错误或附件日志上传到 App Center,并在 App Center 诊断 UI 中查看详细信息。 以下部分将介绍如何上传 崩溃、 错误和 附件。
注意
App Center 仅接受每个唯一应用每分钟最多 60 次崩溃和处理的错误。 我们不会引入任何超过此限制的崩溃或错误。
若要上传报表,请在 中 https://in.appcenter.ms/logs?Api-Version=1.0.0
使用以下标头调用 App Center 引入终结点:
Content-Type
:描述正文的格式。 App Center 目前仅支持 JSON 格式。App-Secret
:表示每个应用的唯一标识符的字符串。 可以在应用的设置中找到应用机密。Install-ID
:可以是用于跟踪计数的任何 GUID 的字符串。
日志属性:
type
:日志类型为“appleError”的必需字符串:“appleError”表示 Apple 崩溃,“managedError”表示其他崩溃,“handledError”表示错误,“errorAttachment”表示错误附件。timestamp
:具有日志时间戳日期时间的可选字符串,例如“2017-03-13T18:05:42Z” - 如果已设置,则需要在引入时间的未来最多为 72 小时appLaunchTimestamp
:指定应用启动时的时间戳日期时间的必需字符串,例如“2017-03-13T18:05:42Z”。device
:具有设备特征的必需对象appVersion
:具有应用程序版本名称的必需字符串,例如“1.1.0”appBuild
:具有应用程序内部版本号的必需字符串,例如“42”sdkName
:具有 SDK 名称的必需字符串。 包含 SDK 和平台的名称,例如 Android 的“appcenter.android”和自定义平台的“appcenter.custom”sdkVersion
:具有语义版本控制格式的 SDK 版本的必需字符串,例如“1.2.0”或“0.12.3-alpha.1”osName
:具有 OS 名称的必需字符串,例如“android”osVersion
:OS 版本的必需字符串,例如“9.3.0”model
:具有设备型号的可选字符串,例如“iPad2”locale
:包含语言代码的必需字符串,例如“en-US”timeZoneOffset
:可选偏移量(以分钟为单位 (设备时区的协调世界时 (UTC) 之间的 -840 到 840) 之间)。 包括夏令时,例如 120。
userId
:用于将日志与用户关联的可选字符串exception
:具有异常详细信息的必需对象type
:具有异常类型的必需字符串frame
:具有堆栈帧的可选数组message
:具有异常原因的可选字符串stackTrace
:包含原始堆栈跟踪的可选字符串innerException
:具有内部异常的可选数组
可在下面找到有关如何上传故障报告、错误报告和附件的示例。 有关更多规范,可 在此处找到完整文件。
注意
由于保留策略的原因,报告 timestamp
在过去不超过 25 天或将来不超过 3 天。
上传故障报告
上传故障报告需要以下属性:
processId
:具有进程标识符的必需整数id
:具有异常标识符的必需字符串,必须是此报表的唯一 IDfatal
:必需布尔值,指示异常是否导致崩溃processName
:具有进程名称的必需字符串appNamespace
:对于 Android 应用是必需的,否则为具有捆绑标识符、包标识符或命名空间的可选字符串,具体取决于所使用的平台。
若要上传除 Apple 格式以外的故障报告,请确保日志类型设置为“managedError”。
curl -X POST \
'https://in.appcenter.ms/logs?Api-Version=1.0.0' \
-H 'Content-Type: application/json' \
-H 'app-secret: <app secret>' \
-H 'install-id: 00000000-0000-0000-0000-000000000001' \
-d '{
"logs": [
{
"type": "managedError",
"timestamp": "2019-10-08T04:22:23.516Z",
"appLaunchTimestamp": "2019-09-29T22:22:23.516Z",
"processId": "123",
"id": "bca65f46-46ee-451b-83bb-2e358c3f45bf",
"fatal": true,
"processName": "com.microsoft.appcenter.demo.project",
"device": {
"appVersion": "12.0",
"appBuild": "1",
"sdkName": "custom.android",
"sdkVersion": "1.0.0",
"osName": "android",
"osVersion": "9.3",
"model": "Pixel",
"locale": "en-US",
"appNamespace": "com.contoso.myapp"
},
"userId": "TestID",
"exception": {
"type": "java.lang.RuntimeException",
"frames": [
{
"className": "android.app.ActivityThread",
"fileName": "ActivityThread.java",
"lineNumber": 2575,
"methodName": "performResumeActivity"
},
{
"className": "android.app.ActivityThread",
"fileName": "ActivityThread.java",
"lineNumber": 2603,
"methodName": "handleResumeActivity"
},
{
"className": "android.app.ActivityThread",
"fileName": "ActivityThread.java",
"lineNumber": 2089,
"methodName": "handleLaunchActivity"
},
{
"className": "android.app.ActivityThread",
"fileName": "ActivityThread.java",
"lineNumber": 130,
"methodName": "access$600"
},
{
"className": "android.app.ActivityThread$H",
"fileName": "ActivityThread.java",
"lineNumber": 1195,
"methodName": "handleMessage"
},
{
"className": "android.os.Handler",
"fileName": "Handler.java",
"lineNumber": 99,
"methodName": "dispatchMessage"
},
{
"className": "android.os.Looper",
"fileName": "Looper.java",
"lineNumber": 137,
"methodName": "loop"
},
{
"className": "android.app.ActivityThread",
"fileName": "ActivityThread.java",
"lineNumber": 4745,
"methodName": "main"
}
],
"innerExceptions": [
{
"type": "java.lang.RuntimeException",
"frames": [
{
"className": "android.app.Activity",
"fileName": "Activity.java",
"lineNumber": 5084,
"methodName": "performResume"
},
{
"className": "android.app.ActivityThread",
"fileName": "ActivityThread.java",
"lineNumber": 2565,
"methodName": "performResumeActivity"
},
{
"className": "android.app.ActivityThread",
"fileName": "ActivityThread.java",
"lineNumber": 2603,
"methodName": "handleResumeActivity"
}
]
}
]
}
}
]
}'
上传 Apple 故障日志
若要上传 Apple 故障日志,请确保日志类型设置为“appleError”。 还需要以下属性:
primaryArchitectureId
:CPU 主体系结构的必需整数applicationPath
:包含应用程序路径的必需字符串osExceptionType
:OS 异常类型的必需字符串osExceptionCode
:包含 OS 异常代码的必需字符串osExceptionAddress
:包含 OS 异常地址的必需字符串binaries
:必需的数组,其中包含与错误关联的二进制文件
例如:
curl -X POST \
'https://in.appcenter.ms/logs?Api-Version=1.0.0' \
-H 'Content-Type: application/json' \
-H 'app-secret: <app secret>' \
-H 'install-id: 00000000-0000-0000-0000-000000000001' \
-d '{
"logs":
[
{
"type": "appleError",
"timestamp": "2019-10-08T02:44:55.000Z",
"appLaunchTimestamp": "2019-09-29T22:22:23.516Z",
"id": "70D280D4-2343-400D-BE4C-301BB2B39ECA",
"applicationPath": "iOS/salesforce",
"osExceptionType": "CustomerIssue (TestIssue)",
"osExceptionCode": "0",
"osExceptionAddress": "0x00",
"processName": "salesforce",
"fatal": true,
"isTestMessage": false,
"device": {
"appVersion": "10.0",
"appBuild": "1",
"sdkName": "custom.ios",
"sdkVersion": "1.0.0",
"osName": "iOS",
"osVersion": "9.3",
"model": "iPhone9,1",
"locale": "en-US"
},
"userId": "70D280D4-2343-400D-BE4C-301BB2B39ECA",
"fatal": true,
"threads": [
{
"id": 0,
"frames": [
{
"address": "0x000000018ada4d70",
"code": "0x18ad87000 + 122224"
},
{
"address": "0x0000000104463884",
"code": "0x10445c000 + 30852"
},
{
"address": "0x000000010438f640",
"code": "0x104388000 + 30272"
},
{
"address": "0x00000001b859fb64",
"code": "0x1b8229000 + 3631972"
}
]
},
{
"id": 1,
"frames": [
{
"address": "0x000000018bb4fce0",
"code": "0x18baa2000 + 711904"
},
{
"address": "0x000000018bbf7078",
"code": "0x18baa2000 + 1396856"
},
{
"address": "0x000000018baa8258",
"code": "0x18baa2000 + 25176"
},
{
"address": "0x000000018bb1c49c",
"code": "0x18baa2000 + 500892"
}
]
},
{
"id": 3,
"frames": [
{
"address": "0x000000018b755b9c",
"code": "0x18b732000 + 146332"
},
{
"address": "0x000000018b7dcd00",
"code": "0x18b7ce000 + 60672"
}
]
}
],
"binaries": [
{
"id": "d449e33d-7e74-379d-8b79-15ee104ed1df",
"startAddress": "0x0000000104388000",
"endAddress": "0x0000000104413fff",
"name": "CrashProbeiOS",
"path": "/var/containers/Bundle/Application/023013EA-0D58-4F6D-8B98-49E1372F4044/CrashProbeiOS.app/CrashProbeiOS",
"primaryArchitectureId": 16777228,
"architectureVariantId": 0
},
{
"id": "5da23653-d126-39f0-bdcf-994b3019f92c",
"startAddress": "0x000000010445c000",
"endAddress": "0x0000000104467fff",
"name": "CrashLibiOS",
"path": "/private/var/containers/Bundle/Application/023013EA-0D58-4F6D-8B98-49E1372F4044/CrashProbeiOS.app/Frameworks/CrashLibiOS.framework/CrashLibiOS",
"primaryArchitectureId": 16777228,
"architectureVariantId": 0
}
]
}
]
}'
上传自定义故障日志
若要上传自定义平台的崩溃,请确保日志类型设置为“managedError”,并将 sdkName 设置为“appcenter.custom”。 例如:
curl -X POST \
'https://in.appcenter.ms/logs?Api-Version=1.0.0' \
-H 'Content-Type: application/json' \
-H 'app-secret: <app secret>' \
-H 'install-id: 00000000-0000-0000-0000-000000000001' \
-d '{
"logs": [
{
"type": "managedError",
"id": "a7bea41b-1e4d-4e42-ae76-1025f4fdfc4f",
"userId": "TestID",
"timestamp": "2019-11-26T02:00:04Z",
"appLaunchTimestamp": "2019-11-26T02:00:04Z",
"architecture": "armeabi-v7a",
"fatal": true,
"processId": 4871,
"processName": "com.microsoft.appcenter.sasquatch.project",
"sid": "bca65f46-46ee-451b-83bb-2e358c3f45bf",
"errorThreadId": 1,
"errorThreadName": "main",
"device": {
"appBuild": "1337",
"appVersion": "7.1.0",
"appNamespace": "com.microsoft.appcenter.sasquatch.project",
"carrierCountry": "us",
"locale": "en_US",
"model": "Galaxy Nexus",
"oemName": "samsung",
"osApiLevel": 16,
"osBuild": "JRO03O",
"osName": "Android",
"osVersion": "5.0.0",
"screenSize": "720x1184",
"sdkName": "appcenter.custom",
"sdkVersion": "1.9.1",
"timeZoneOffset": -480
},
"exception": {
"frames": [
{
"className": "android.app.ActivityThread",
"fileName": "ActivityThread.java",
"lineNumber": 2575,
"methodName": "performResumeActivity"
},
{
"className": "android.app.ActivityThread",
"fileName": "ActivityThread.java",
"lineNumber": 2603,
"methodName": "handleResumeActivity"
},
{
"className": "android.app.ActivityThread",
"fileName": "ActivityThread.java",
"lineNumber": 2089,
"methodName": "handleLaunchActivity"
}
],
"innerExceptions": [
{
"frames": [
{
"className": "android.app.CustomActivity",
"fileName": "CustomActivity.java",
"lineNumber": 8673,
"methodName": "performCustomResume"
},
{
"className": "android.app.ActivityThread",
"fileName": "ActivityThread.java",
"lineNumber": 2565,
"methodName": "performResumeActivity"
}
],
"message": "Activity {com.microsoft.appcenter.sasquatch.project/com.microsoft.appcenter.sasquatch.activities.CrashSubActivity2} did not call through to super.onResume()",
"type": "android.app.CustomNotCalledException"
}
],
"message": "Unable to resume activity {com.microsoft.appcenter.sasquatch.project/com.microsoft.appcenter.sasquatch.activities.CrashSubActivity2}: android.app.SuperNotCalledException: Activity {com.microsoft.appcenter.sasquatch.project/com.microsoft.appcenter.sasquatch.activities.CrashSubActivity2} did not call through to super.onResume()",
"type": "java.lang.RuntimeException"
},
"threads": [
{
"frames": [
{
"className": "dalvik.system.NativeStart",
"fileName": "NativeStart.java",
"lineNumber": -2,
"methodName": "run"
}
],
"id": 369,
"name": "Binder_3"
},
{
"frames": [
{
"className": "dalvik.system.NativeStart",
"fileName": "NativeStart.java",
"lineNumber": -2,
"methodName": "run"
}
],
"id": 345,
"name": "Compiler"
}
]
}
]
}'
上传 Breakpad 故障日志和小型转储
可以上传适用于 Android 和 Windows 的自定义 Breakpad 崩溃。 例如:
curl -X POST \
'https://in.appcenter.ms/logs?Api-Version=1.0.0' \
-H 'Content-Type: application/json' \
-H 'app-secret: <app secret>' \
-H 'install-id: 00000000-0000-0000-0000-000000000001' \
-d '{
"logs":
[
{
"type": "managedError",
"id": "70D280D4-2343-400D-BE4C-301BB2B39ECA",
"userId": "TestID",
"processId": 9448,
"processName": "Contoso.UWP.Puppet.exe",
"fatal": true,
"timestamp": "2019-10-08T06:22:23.530Z",
"architecture": "X64",
"timestamp": "2019-10-08T06:22:23.516Z",
"sid": "d4608adf-83b9-4f69-90ad-8bb0234080a7",
"device": {
"sdkName": "appcenter.custom",
"sdkVersion": "2.4.1-SNAPSHOT",
"model": "Parallels Virtual Platform",
"oemName": "Parallels Software International Inc.",
"osName": "WINDOWS",
"osVersion": "10.0.18363",
"osBuild": "10.0.18363.418",
"locale": "en-US",
"timeZoneOffset": -300,
"screenSize": "4608x2470",
"appVersion": "1.0",
"appBuild": "1.0",
"appNamespace": "10805zumoTestUser.AppCenter-Contoso.UWP.Puppet",
"carrierCountry": "us",
"wrapperSdkName": "custom.ndk"
},
"exception": {
"type": "minidump",
"wrapperSdkName": "custom.ndk"
}
},
{
"contentType": "application/octet-stream",
"errorId": "70D280D4-2343-400D-BE4C-301BB2B39ECA",
"fileName": "minidump.dmp",
"id": "7b975468-5656-40a5-8242-c1907b26fc31",
"sid": "03693776-cdd4-46b8-bbda-12af457f1732",
"timestamp": "2019-10-08T06:22:23.516Z",
"type": "errorAttachment",
"device": {
"sdkName": "appcenter.custom",
"sdkVersion": "2.4.1-SNAPSHOT",
"model": "Parallels Virtual Platform",
"oemName": "Parallels Software International Inc.",
"osName": "WINDOWS",
"osVersion": "10.0.18363",
"osBuild": "10.0.18363.418",
"locale": "en-US",
"timeZoneOffset": -300,
"screenSize": "4608x2470",
"appVersion": "1.0",
"appBuild": "1.0",
"appNamespace": "10805zumoTestUser.AppCenter-Contoso.UWP.Puppet",
"carrierCountry": "us",
"wrapperSdkName": "custom.ndk"
},
"data": "<base64 encoded minidump>"
}
]
}'
注意事项
若要上传 Breakpad 故障,必须将 wrapperSdkName
字段设置为“custom.ndk”,并且必须将小型转储文件作为附件附加到故障报告。 了解如何在此页的附件 部分中发送附件 。
若要对故障进行符号化,必须根据我们的 API 文档,通过 CLI 或 API 上传符号。如果将 Breakpad 与 Android 配合使用,则支持 Android NDK 文档中 指定的两个选项;如果将 Breakpad 与 Windows 配合使用,则仅支持选项 2:“上传 Breakpad 符号”。
注意
如果要从 macOS 上传符号,则必须清理任何无关文件夹的符号,例如,生成__MACOS,若要删除此符号,可以使用 zip -d <symbols.zip> __MACOSX/\*
。
上传错误报告
目前,仅 Android、Xamarin、Unity、UWP、WPF 和 WinForms 应用支持已处理的错误。 若要上传错误报告,请确保日志类型设置为“handledError”。
curl -X POST \
'https://in.appcenter.ms/logs?Api-Version=1.0.0' \
-H 'Content-Type: application/json' \
-H 'app-secret: <app secret>' \
-H 'install-id: 00000000-0000-0000-0000-000000000001' \
-d '{
"logs":
[
{
"type": "handledError",
"timestamp": "2019-10-08T06:22:23.516Z",
"appLaunchTimestamp": "2019-09-29T22:22:23.516Z",
"id": "118dee14-9193-4ac3-9ef0-f6c11b43f2c4",
"device": {
"appVersion": "11.0",
"appBuild": "1",
"sdkName": "custom.android",
"sdkVersion": "1.0.0",
"osName": "android",
"osVersion": "9.3",
"model": "Pixel",
"locale": "en-US"
},
"userId": "TestID",
"exception": {
"type": "System.IO.IOException",
"message": "Server did not respond",
"stackTrace": " at Contoso.Forms.Puppet.FakeService+<>c.<DoStuffInBackground>b__0_0 () [0x00000] in <7ad93f134a5d4c00a8db8be9aa9c0f76>:0 \n at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <b38d4262627948c1b945a72f56ce6466>:0 \n at System.Threading.Tasks.Task.Execute () [0x00010] in <b38d4262627948c1b945a72f56ce6466>:0 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <b38d4262627948c1b945a72f56ce6466>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <b38d4262627948c1b945a72f56ce6466>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <b38d4262627948c1b945a72f56ce6466>:0",
"innerExceptions": [
{
"type": "System.IO.IOException",
"message": "Network down",
"stackTrace": " at Contoso.Forms.Demo.CrashesContentPage.SendHttp () [0x00002] in <4fd9174f6e18457b9721bfba2cd78098>:0 ",
"wrapperSdkName": "appcenter.xamarin"
},
{
"type": "System.ArgumentException",
"message": "Invalid parameter",
"innerExceptions": [
{
"type": "System.ArgumentOutOfRangeException",
"message": "It is over 9000!",
"stackTrace": " at Contoso.Forms.Demo.CrashesContentPage.ValidateLength () [0x00002] in <4fd9174f6e18457b9721bfba2cd78098>:0 ",
}
],
}
],
}
}
]
}'
上传附件
所有附件都必须与故障报告相关联。 可以在一次呼叫或两次单独调用中上传带有故障报告的附件。
特定于附件的属性:
contentType
:具有内容类型的必需字符串,例如,文本的“text/plain”。 可在此处找到受支持的类型的示例data
:数据编码为 base 64 的必需字符串errorId
:包含附件关联错误报告的唯一标识符的必需字符串fileName
:NDK 崩溃的必需字符串,设置为“minidump.dmp”
注意
附件的大小限制当前为 7 MB。 尝试发送更大的附件将触发错误。
下面是在一次调用中上传故障报告和附件的示例。
curl -X POST \
'https://in.appcenter.ms/logs?Api-Version=1.0.0' \
-H 'Content-Type: application/json' \
-H 'app-secret: <app secret>' \
-H 'install-id: 00000000-0000-0000-0000-000000000001' \
-d '{
"logs": [
{
"type": "managedError",
"timestamp": "2019-10-01T02:22:23.516Z",
"appLaunchTimestamp": "2019-09-29T22:22:23.516Z",
"id": "bca65f46-46ee-451b-83bb-2e358c3f45bf",
"fatal": true,
"processName": "com.microsoft.appcenter.sasquatch.project",
"device": {
"appVersion": "13.0",
"appBuild": "1",
"sdkName": "appcenter.android",
"sdkVersion": "1.0.0",
"osName": "android",
"osVersion": "9.3",
"model": "Pixel",
"locale": "en-US"
},
"userId": "118dee14",
"fatal": true,
"exception": {
"type": "CustomerIssue",
"frames": []
}
},
{
"type": "errorAttachment",
"contentType": "text/plain",
"timestamp": "2019-10-01T02:22:23.516Z",
"data": "aGVsbG8=",
"errorId": "bca65f46-46ee-451b-83bb-2e358c3f45bf",
"id": "7caaea8e-dab1-4588-993c-95de2d9a4fd1",
"device": {
"appVersion": "13.0",
"appBuild": "1",
"sdkName": "appcenter.android",
"sdkVersion": "1.0.0",
"osName": "android",
"osVersion": "9.3",
"model": "Pixel",
"locale": "en-US"
}
}
]
}'