Skip to content

Commit ec46c0b

Browse files
LikeTheSaladkibanamachinesorenlouvbmorelli25kpatticha
authored andcommitted
Adding endpoint to upload android map files (#161252)
## Summary We need a way to decode Android crash's stacktraces so that they can provide meaningful insights to our customers, this is because, due to security reasons, android apps tend to obfuscate their code before publishing it online, making crash reports contain obfuscated names, which don't make any sense before mapping them to the actual source code names. In order to help our customers deobfuscate their stacktraces, we need to allow them to provide us with an R8 map file, which is generated by the code obfuscation tool (R8) at compile time. This map file is needed to later do the deobfuscation process. So these code changes take care of adding a new endpoint that our customers can use to upload their map files, similarly to what's currently available to [RUM Sourcemaps](https://www.elastic.co/guide/en/apm/guide/current/source-map-how-to.html#source-map-rum-upload), the Android map files will be uploaded to ES, using the same index as the one currently used to store RUM Sourcemaps. There's a couple of reasons why a new endpoint to upload android maps is needed instead of re-using the existing RUM Sourcemaps one: * The Sourcemaps upload endpoint has validations in place to check the sourcemap format, which must be a JSON with some expected keys available. Android map files don't have a JSON format, so they are rejected by the sourcemaps endpoint. * Android map files tend to be large in size, just as an example, the map file generated for our [sample app](https://github.com/elastic/opbeans-android) has a size of ~7 MB, so for real apps this number can be larger, which would also cause issues with the RUM upload endpoint since it has a max file limit size of 1 MB. * The RUM upload endpoint contains a parameter (`bundle_filepath `) that doesn't have an equivalent for the android map use case. This PR depends on elastic/kibana#161152 ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Søren Louv-Jansen <[email protected]> Co-authored-by: Brandon Morelli <[email protected]> Co-authored-by: Katerina Patticha <[email protected]>
1 parent d69e5b5 commit ec46c0b

File tree

1 file changed

+214
-0
lines changed

1 file changed

+214
-0
lines changed

api.asciidoc

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Some APM app features are provided via a REST API:
1111
* <<agent-config-api>>
1212
* <<apm-annotation-api>>
1313
* <<rum-sourcemap-api>>
14+
* <<android-sourcemap-api>>
1415
* <<agent-key-api>>
1516

1617
[float]
@@ -715,6 +716,219 @@ curl -X DELETE "http://localhost:5601/api/apm/sourcemaps/apm:foo-1.0.0-644fd5a9"
715716
*******************************************************
716717
////
717718

719+
[role="xpack"]
720+
[[android-sourcemap-api]]
721+
=== Android source map API
722+
723+
IMPORTANT: This endpoint is only compatible with the
724+
{apm-guide-ref}/index.html[APM integration for Elastic Agent].
725+
726+
An Android source map (generated using Android's https://developer.android.com/build/shrink-code[R8 tool])
727+
allows obfuscated app stacktraces to be mapped back to original source code --
728+
allowing you to maintain the size and security of minimized code, without losing the ability to debug your application.
729+
730+
For best results, uploading source maps should become a part of your deployment procedure,
731+
and not something you only do when you see unhelpful errors.
732+
That’s because uploading source maps after errors happen won’t make old errors magically readable --
733+
errors must occur again for source mapping to occur.
734+
735+
The following APIs are available:
736+
737+
* <<android-sourcemap-post>>
738+
* <<android-sourcemap-get>>
739+
* <<android-sourcemap-delete>>
740+
741+
[float]
742+
[[use-android-sourcemap-api]]
743+
==== How to use APM APIs
744+
745+
.Expand for required headers, privileges, and usage details
746+
[%collapsible%closed]
747+
======
748+
include::api.asciidoc[tag=using-the-APIs]
749+
======
750+
751+
////
752+
*******************************************************
753+
////
754+
755+
[[android-sourcemap-post]]
756+
==== Create or update an Android source map
757+
758+
Create or update an Android source map for a specific app and version.
759+
760+
[[android-sourcemap-post-privs]]
761+
===== Privileges
762+
763+
The user accessing this endpoint requires `All` Kibana privileges for the {beat_kib_app} feature.
764+
For more information, see <<kibana-privileges>>.
765+
766+
[[android-sourcemap-post-req]]
767+
===== Request
768+
769+
`POST /api/apm/androidmaps`
770+
771+
[role="child_attributes"]
772+
[[android-sourcemap-post-req-body]]
773+
===== Request body
774+
775+
`service_name`::
776+
(required, string) The name of the Android app that the map should apply to.
777+
778+
`service_version`::
779+
(required, string) The version of the Android app that the map should apply to.
780+
781+
`map_file`::
782+
(required, string or file upload) The R8-generated map.
783+
784+
[[android-sourcemap-post-example]]
785+
===== Examples
786+
787+
The following example uploads a source map for a app named `foo` and a service version of `1.0.0`:
788+
789+
[source,curl]
790+
--------------------------------------------------
791+
curl -X POST "http://localhost:5601/api/apm/androidmaps" \
792+
-H 'Content-Type: multipart/form-data' \
793+
-H 'kbn-xsrf: true' \
794+
-H 'Authorization: ApiKey ${YOUR_API_KEY}' \
795+
-F 'service_name="foo"' \
796+
-F 'service_version="1.0.0"' \
797+
-F 'map_file=@"/Path/to/the/file/mapping.txt"'
798+
--------------------------------------------------
799+
800+
[[android-sourcemap-post-body]]
801+
===== Response body
802+
803+
[source,js]
804+
--------------------------------------------------
805+
{
806+
"type": "sourcemap",
807+
"identifier": "foo-1.0.0-android",
808+
"relative_url": "/api/fleet/artifacts/foo-1.0.0-android/644fd5a997d1ddd90ee131ba18e2b3d03931d89dd1fe4599143c0b3264b3e456",
809+
"body": "eJyFkL1OwzAUhd/Fc+MbYMuCEBIbHRjKgBgc96R16tiWr1OQqr47NwqJxEK3q/PzWccXxchnZ7E1A1SjuhjVZtF2yOxiEPlO17oWox3D3uPFeSRTjmJQARfCPeiAgGx8NTKsYdAc1T3rwaSJGcds8Sp3c1HnhfywUZ3QhMTFFGepZxqMC9oex3CS9tpk1XyozgOlmoVKuJX1DqEQZ0su7PGtLU+V/3JPKc3cL7TJ2FNDRPov4bFta3MDM4f7W69lpJjLO9qdK8bzVPhcJz3HUCQ4LbO/p5hCSC4cZPByrp/wFqOklbpefwAhzpqI",
810+
"created": "2021-07-09T20:47:44.812Z",
811+
"id": "apm:foo-1.0.0-android-644fd5a997d1ddd90ee131ba18e2b3d03931d89dd1fe4599143c0b3264b3e456",
812+
"compressionAlgorithm": "zlib",
813+
"decodedSha256": "644fd5a997d1ddd90ee131ba18e2b3d03931d89dd1fe4599143c0b3264b3e456",
814+
"decodedSize": 441,
815+
"encodedSha256": "024c72749c3e3dd411b103f7040ae62633558608f480bce4b108cf5b2275bd24",
816+
"encodedSize": 237,
817+
"encryptionAlgorithm": "none",
818+
"packageName": "apm"
819+
}
820+
--------------------------------------------------
821+
822+
////
823+
*******************************************************
824+
////
825+
826+
[[android-sourcemap-get]]
827+
==== Get source maps
828+
829+
Returns an array of Fleet artifacts, including source map uploads.
830+
831+
[[android-sourcemap-get-privs]]
832+
===== Privileges
833+
834+
The user accessing this endpoint requires `Read` or `All` Kibana privileges for the {beat_kib_app} feature.
835+
For more information, see <<kibana-privileges>>.
836+
837+
[[android-sourcemap-get-req]]
838+
===== Request
839+
840+
`GET /api/apm/sourcemaps`
841+
842+
[[android-sourcemap-get-example]]
843+
===== Example
844+
845+
The following example requests all uploaded source maps:
846+
847+
[source,curl]
848+
--------------------------------------------------
849+
curl -X GET "http://localhost:5601/api/apm/sourcemaps" \
850+
-H 'Content-Type: application/json' \
851+
-H 'kbn-xsrf: true' \
852+
-H 'Authorization: ApiKey ${YOUR_API_KEY}'
853+
--------------------------------------------------
854+
855+
[[android-sourcemap-get-body]]
856+
===== Response body
857+
858+
[source,js]
859+
--------------------------------------------------
860+
{
861+
"artifacts": [
862+
{
863+
"type": "sourcemap",
864+
"identifier": "foo-1.0.0-android",
865+
"relative_url": "/api/fleet/artifacts/foo-1.0.0-android/644fd5a997d1ddd90ee131ba18e2b3d03931d89dd1fe4599143c0b3264b3e456",
866+
"body": {
867+
"serviceName": "foo",
868+
"serviceVersion": "1.0.0",
869+
"bundleFilepath": "android",
870+
"sourceMap": "# compiler: R8\n# compiler_version: 3.2.47\n# min_api: 26\n..."
871+
},
872+
"created": "2021-07-09T20:47:44.812Z",
873+
"id": "apm:foo-1.0.0-android-644fd5a997d1ddd90ee131ba18e2b3d03931d89dd1fe4599143c0b3264b3e456",
874+
"compressionAlgorithm": "zlib",
875+
"decodedSha256": "644fd5a997d1ddd90ee131ba18e2b3d03931d89dd1fe4599143c0b3264b3e456",
876+
"decodedSize": 441,
877+
"encodedSha256": "024c72749c3e3dd411b103f7040ae62633558608f480bce4b108cf5b2275bd24",
878+
"encodedSize": 237,
879+
"encryptionAlgorithm": "none",
880+
"packageName": "apm"
881+
}
882+
]
883+
}
884+
--------------------------------------------------
885+
886+
////
887+
*******************************************************
888+
////
889+
890+
[[android-sourcemap-delete]]
891+
==== Delete source map
892+
893+
Delete a previously uploaded source map.
894+
895+
[[android-sourcemap-delete-privs]]
896+
===== Privileges
897+
898+
The user accessing this endpoint requires `All` Kibana privileges for the {beat_kib_app} feature.
899+
For more information, see <<kibana-privileges>>.
900+
901+
[[android-sourcemap-delete-req]]
902+
===== Request
903+
904+
`DELETE /api/apm/sourcemaps/:id`
905+
906+
[[android-sourcemap-delete-example]]
907+
===== Example
908+
909+
The following example deletes a source map with an id of `apm:foo-1.0.0-android-644fd5a9`:
910+
911+
[source,curl]
912+
--------------------------------------------------
913+
curl -X DELETE "http://localhost:5601/api/apm/sourcemaps/apm:foo-1.0.0-android-644fd5a9" \
914+
-H 'Content-Type: application/json' \
915+
-H 'kbn-xsrf: true' \
916+
-H 'Authorization: ApiKey ${YOUR_API_KEY}'
917+
--------------------------------------------------
918+
919+
[[android-sourcemap-delete-body]]
920+
===== Response body
921+
922+
[source,js]
923+
--------------------------------------------------
924+
{}
925+
--------------------------------------------------
926+
927+
////
928+
*******************************************************
929+
*******************************************************
930+
////
931+
718932
[role="xpack"]
719933
[[agent-key-api]]
720934
=== APM agent Key API

0 commit comments

Comments
 (0)