From 8f2177142663a644e83211b92ac7866196d3e193 Mon Sep 17 00:00:00 2001 From: Fiona Date: Wed, 12 Aug 2026 03:05:06 -0700 Subject: [PATCH 1/2] =?UTF-8?q?release(harmony):=20SDK=200.4.0=20=E2=80=94?= =?UTF-8?q?=20report=20resources=20from=20any=20network=20stack?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps the four SDK packages to 0.4.0 and records the changes shipped since 0.3.2. The minor rather than the patch position: this release removes `FlashcatHttp.hostOf()`. A patch number would hide a removal from anyone who upgrades without reading the changelog. Version numbers live in three places — the oh-package manifests with their inter-package pins, Version.ets, and the test fixtures carrying the version string — and all three move together here. --- flashcat-core/CHANGELOG.md | 4 ++++ flashcat-core/oh-package.json5 | 2 +- flashcat-core/src/main/ets/internal/Version.ets | 2 +- flashcat-crash/CHANGELOG.md | 4 ++++ flashcat-crash/oh-package.json5 | 4 ++-- flashcat-crash/src/test/CrashEventMapper.test.ets | 4 ++-- flashcat-crash/src/test/CrashIncident.test.ets | 6 +++--- flashcat-rum/CHANGELOG.md | 5 +++++ flashcat-rum/oh-package.json5 | 4 ++-- flashcat-rum/src/test/SessionLifecycle.test.ets | 2 +- flashcat-trace/CHANGELOG.md | 10 ++++++---- flashcat-trace/oh-package.json5 | 4 ++-- 12 files changed, 33 insertions(+), 18 deletions(-) diff --git a/flashcat-core/CHANGELOG.md b/flashcat-core/CHANGELOG.md index a1f4a65..5f6c09a 100644 --- a/flashcat-core/CHANGELOG.md +++ b/flashcat-core/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.4.0 + +- Version bump to keep the SDK packages in lockstep. + ## 0.3.2 - Added a durable snapshot of the last written ViewEvent, used by the RUM diff --git a/flashcat-core/oh-package.json5 b/flashcat-core/oh-package.json5 index 8e79ae0..6dbe9fd 100644 --- a/flashcat-core/oh-package.json5 +++ b/flashcat-core/oh-package.json5 @@ -1,6 +1,6 @@ { name: "@flashcatcloud/core", - version: "0.3.2", + version: "0.4.0", description: "FlashCat HarmonyOS SDK core: init, configuration, context, message bus, storage and batched upload.", main: "Index.ets", license: "Apache-2.0", diff --git a/flashcat-core/src/main/ets/internal/Version.ets b/flashcat-core/src/main/ets/internal/Version.ets index ebcbab6..c619785 100644 --- a/flashcat-core/src/main/ets/internal/Version.ets +++ b/flashcat-core/src/main/ets/internal/Version.ets @@ -5,4 +5,4 @@ * Keep this in sync with the `version` field of each module's * `oh-package.json5` on every release bump. */ -export const SDK_VERSION: string = '0.3.2'; +export const SDK_VERSION: string = '0.4.0'; diff --git a/flashcat-crash/CHANGELOG.md b/flashcat-crash/CHANGELOG.md index e1cd133..5ac1b0e 100644 --- a/flashcat-crash/CHANGELOG.md +++ b/flashcat-crash/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.4.0 + +- Version bump to keep the SDK packages in lockstep. + ## 0.3.2 - Version bump to keep the SDK packages in lockstep. Native crashes and freezes diff --git a/flashcat-crash/oh-package.json5 b/flashcat-crash/oh-package.json5 index c0b6515..30a89cb 100644 --- a/flashcat-crash/oh-package.json5 +++ b/flashcat-crash/oh-package.json5 @@ -1,12 +1,12 @@ { name: "@flashcatcloud/crash", - version: "0.3.2", + version: "0.4.0", description: "FlashCat HarmonyOS crash reporting: hiAppEvent APP_CRASH (native + ArkTS) + APP_FREEZE, reported as RUM is_crash errors.", main: "Index.ets", license: "Apache-2.0", author: "FlashCat (https://flashcat.cloud)", repository: "https://github.com/flashcatcloud/fc-sdk-harmony", dependencies: { - "@flashcatcloud/core": "0.3.2" + "@flashcatcloud/core": "0.4.0" } } diff --git a/flashcat-crash/src/test/CrashEventMapper.test.ets b/flashcat-crash/src/test/CrashEventMapper.test.ets index 0da4eb8..143e1e0 100644 --- a/flashcat-crash/src/test/CrashEventMapper.test.ets +++ b/flashcat-crash/src/test/CrashEventMapper.test.ets @@ -137,7 +137,7 @@ export default function crashEventMapperTests(): void { 'TypeError: boom\n at run (Index.ets:1:2)', 'fp-1', JsCrashPolicy.REPORT_THEN_EXIT, - '0.3.2', + '0.4.0', 'session-1', 'view-1', 'Home'); @@ -163,7 +163,7 @@ export default function crashEventMapperTests(): void { 'TypeError: boom\n at run (Index.ets:1:2)', 'fp-recovered', JsCrashPolicy.REPORT_AND_RECOVER, - '0.3.2', + '0.4.0', 'session-1', 'view-1', 'Home'); diff --git a/flashcat-crash/src/test/CrashIncident.test.ets b/flashcat-crash/src/test/CrashIncident.test.ets index 31b5b93..c23ca1e 100644 --- a/flashcat-crash/src/test/CrashIncident.test.ets +++ b/flashcat-crash/src/test/CrashIncident.test.ets @@ -45,7 +45,7 @@ export default function crashIncidentTests(): void { it('roundTripsViewUrlThroughSerialization', TestType.FUNCTION | Size.SMALLTEST | Level.LEVEL0, (): void => { const record: CrashIncidentRecord = new CrashIncidentRecord( 'inc-1', 1000, 'Error', 'boom', 'Error: boom\n at f (a.ets:1:1)', 'fp-1', - JsCrashPolicy.REPORT_THEN_EXIT, '0.3.2', 's-1', 'v-1', 'Home', 'pages/Home'); + JsCrashPolicy.REPORT_THEN_EXIT, '0.4.0', 's-1', 'v-1', 'Home', 'pages/Home'); const parsed: CrashIncidentRecord | null = CrashIncidentRecord.parse(record.serialize()); @@ -162,7 +162,7 @@ export default function crashIncidentTests(): void { 'TypeError: boom\n at run (Index.ets:1:2)', 'fp-1', JsCrashPolicy.REPORT_THEN_EXIT, - '0.3.2', + '0.4.0', 'session-1', 'view-1', 'Home'); @@ -178,7 +178,7 @@ export default function crashIncidentTests(): void { expect(parsed.stack.indexOf('Index.ets')).assertLarger(-1); expect(parsed.fingerprint).assertEqual('fp-1'); expect(parsed.policy).assertEqual(JsCrashPolicy.REPORT_THEN_EXIT); - expect(parsed.sdkVersion).assertEqual('0.3.2'); + expect(parsed.sdkVersion).assertEqual('0.4.0'); expect(parsed.sessionId).assertEqual('session-1'); expect(parsed.viewId).assertEqual('view-1'); expect(parsed.viewName).assertEqual('Home'); diff --git a/flashcat-rum/CHANGELOG.md b/flashcat-rum/CHANGELOG.md index 934c92c..104e77e 100644 --- a/flashcat-rum/CHANGELOG.md +++ b/flashcat-rum/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.4.0 + +- Version bump to keep the SDK packages in lockstep (see `@flashcatcloud/trace` + 0.4.0: resources can now be reported from any network stack). + ## 0.3.2 - Crash attribution now covers faults the SDK cannot observe in-process. Native diff --git a/flashcat-rum/oh-package.json5 b/flashcat-rum/oh-package.json5 index 73c38e9..3d8c766 100644 --- a/flashcat-rum/oh-package.json5 +++ b/flashcat-rum/oh-package.json5 @@ -1,12 +1,12 @@ { name: "@flashcatcloud/rum", - version: "0.3.2", + version: "0.4.0", description: "FlashCat HarmonyOS RUM: views, actions, resources, errors, sessions.", main: "Index.ets", license: "Apache-2.0", author: "FlashCat (https://flashcat.cloud)", repository: "https://github.com/flashcatcloud/fc-sdk-harmony", dependencies: { - "@flashcatcloud/core": "0.3.2" + "@flashcatcloud/core": "0.4.0" } } diff --git a/flashcat-rum/src/test/SessionLifecycle.test.ets b/flashcat-rum/src/test/SessionLifecycle.test.ets index 9bb4677..b26e7c4 100644 --- a/flashcat-rum/src/test/SessionLifecycle.test.ets +++ b/flashcat-rum/src/test/SessionLifecycle.test.ets @@ -17,7 +17,7 @@ function testContext(): FlashcatContext { version: '1.0.0', bundleId: 'com.example.demo', source: 'harmony', - sdkVersion: '0.3.2', + sdkVersion: '0.4.0', device: { brand: 'HUAWEI', model: 'Pura', osName: 'HarmonyOS', osVersion: 'NEXT', apiVersion: 18, deviceType: 'phone' diff --git a/flashcat-trace/CHANGELOG.md b/flashcat-trace/CHANGELOG.md index 0c0eeaf..da62134 100644 --- a/flashcat-trace/CHANGELOG.md +++ b/flashcat-trace/CHANGELOG.md @@ -1,7 +1,12 @@ # Changelog -## Unreleased +## 0.4.0 +- **Breaking**: `FlashcatHttp.hostOf()` removed. Host parsing moved behind the + first-party gate inside the SDK and the method had no callers left; it was a + URL helper on a public class rather than part of what this package does. + Applications that called it can extract the host themselves — it was a plain + string operation with no SDK state behind it. - `FlashcatTrace.startTracedResource(url, method, injectTrace?)` + `stopTracedResource` / `failTracedResource`: report a request as a RUM resource from any network stack the SDK cannot instrument itself — axios, a @@ -11,9 +16,6 @@ Requires `setTrackNetworkRequests(true)`, like every other network path. - `FlashcatHttp` now builds on the same entry point instead of duplicating the injection and resource-lifecycle logic. -- **Breaking**: `FlashcatHttp.hostOf()` removed. Host parsing moved behind the - first-party gate inside the SDK and the method had no callers left; it was a - URL helper rather than part of this package's purpose. ## 0.3.2 diff --git a/flashcat-trace/oh-package.json5 b/flashcat-trace/oh-package.json5 index 2b46db6..215fc23 100644 --- a/flashcat-trace/oh-package.json5 +++ b/flashcat-trace/oh-package.json5 @@ -1,12 +1,12 @@ { name: "@flashcatcloud/trace", - version: "0.3.2", + version: "0.4.0", description: "FlashCat HarmonyOS trace-context propagation: W3C traceparent generation + rcp interceptor + manual headers.", main: "Index.ets", license: "Apache-2.0", author: "FlashCat (https://flashcat.cloud)", repository: "https://github.com/flashcatcloud/fc-sdk-harmony", dependencies: { - "@flashcatcloud/core": "0.3.2" + "@flashcatcloud/core": "0.4.0" } } From 03ec2b35da711909f1aa2224a7450006e052a110 Mon Sep 17 00:00:00 2001 From: Fiona Date: Wed, 12 Aug 2026 06:01:43 -0700 Subject: [PATCH 2/2] Ship the axios integration as its own package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Applications using axios had to copy an interceptor file into their own repository and keep it there. `@flashcatcloud/axios` makes the integration one call — `trackAxios(instance)` — with nothing to vendor and nothing to re-sync when the SDK changes. Its own package rather than part of trace: axios is a third-party dependency, and folding it into `@flashcatcloud/trace` would make every user of that package install axios whether or not they use it. This mirrors the Android SDK, which ships an integration module per third-party library rather than pulling them into the core. The package is a thin layer over `startTracedResource` — resolving the url axios will actually request, copying the returned headers onto the config, and carrying the resource key between the request and response interceptors. Every rule that matters stays in the SDK. Also here, because both ship with this release: - `flashcat-rum/README.md` called `FlashcatRum.startView()`, which does not exist on that class. READMEs travel inside the published package, so anyone following the quickstart hit a compile error. Corrected to `GlobalRumMonitor.get().startView()`. - The headless test runner learned the new module and how to resolve `@flashcatcloud/trace`. --- .github/workflows/publish-ohpm.yml | 2 +- build-profile.json5 | 12 ++ entry/oh-package.json5 | 6 +- entry/src/main/ets/pages/Index.ets | 2 +- flashcat-axios/CHANGELOG.md | 8 + flashcat-axios/Index.ets | 3 + flashcat-axios/LICENSE | 202 ++++++++++++++++++ flashcat-axios/README.md | 45 ++++ flashcat-axios/build-profile.json5 | 18 ++ flashcat-axios/hvigorfile.ts | 6 + flashcat-axios/obfuscation-rules.txt | 3 + flashcat-axios/oh-package.json5 | 13 ++ .../src/main/ets}/AxiosTracking.ets | 73 ++++--- flashcat-axios/src/main/module.json5 | 7 + flashcat-axios/src/test/List.test.ets | 58 +++++ flashcat-rum/README.md | 4 +- oh-package.json5 | 3 +- scripts/unit-node/run.mjs | 5 +- 18 files changed, 431 insertions(+), 39 deletions(-) create mode 100644 flashcat-axios/CHANGELOG.md create mode 100644 flashcat-axios/Index.ets create mode 100644 flashcat-axios/LICENSE create mode 100644 flashcat-axios/README.md create mode 100644 flashcat-axios/build-profile.json5 create mode 100644 flashcat-axios/hvigorfile.ts create mode 100644 flashcat-axios/obfuscation-rules.txt create mode 100644 flashcat-axios/oh-package.json5 rename {entry/src/main/ets/common => flashcat-axios/src/main/ets}/AxiosTracking.ets (61%) create mode 100644 flashcat-axios/src/main/module.json5 create mode 100644 flashcat-axios/src/test/List.test.ets diff --git a/.github/workflows/publish-ohpm.yml b/.github/workflows/publish-ohpm.yml index 5ea14d2..1469ecb 100644 --- a/.github/workflows/publish-ohpm.yml +++ b/.github/workflows/publish-ohpm.yml @@ -30,7 +30,7 @@ jobs: env: OHPM_PUBLISH_REGISTRY: https://ohpm.openharmony.cn/ohpm/ - HARMONY_MODULES: "flashcat_core flashcat_rum flashcat_crash flashcat_trace" + HARMONY_MODULES: "flashcat_core flashcat_rum flashcat_crash flashcat_trace flashcat_axios" HARMONY_COMMAND_LINE_TOOLS_HOME: ${{ vars.HARMONY_COMMAND_LINE_TOOLS_HOME }} DEVECO_SDK_HOME: ${{ vars.DEVECO_SDK_HOME }} diff --git a/build-profile.json5 b/build-profile.json5 index a6bb816..df6362f 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -47,6 +47,18 @@ } ] }, + { + name: "flashcat_axios", + srcPath: "./flashcat-axios", + targets: [ + { + name: "default", + applyToProducts: [ + "default" + ] + } + ] + }, { name: "flashcat_trace", srcPath: "./flashcat-trace", diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 index c53f1a9..e9c8c96 100644 --- a/entry/oh-package.json5 +++ b/entry/oh-package.json5 @@ -10,9 +10,9 @@ "@flashcatcloud/rum": "file:../flashcat-rum", "@flashcatcloud/trace": "file:../flashcat-trace", "@flashcatcloud/crash": "file:../flashcat-crash", + "@flashcatcloud/axios": "file:../flashcat-axios", "libentry.so": "file:./src/main/cpp/types/libentry", - // Demo-only: exercises the manual axios instrumentation reference in - // common/AxiosTracking.ets. The SDK modules do NOT depend on axios. - "@ohos/axios": "^2.2.13" + // The demo calls axios directly; @flashcatcloud/axios brings its own. + "@ohos/axios": "^2.2.4" } } diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 028f4a3..a457984 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -11,7 +11,7 @@ import testNapi from 'libentry.so'; import { DemoSdk } from '../common/DemoSdk'; import { SpikeMode, SpikeModeStore } from '../common/SpikeMode'; import axios, { AxiosInstance, AxiosResponse } from '@ohos/axios'; -import { trackAxios } from '../common/AxiosTracking'; +import { trackAxios } from '@flashcatcloud/axios'; /** ArkTS requires every object literal to have a declared type. */ interface AxiosDemoPayload { diff --git a/flashcat-axios/CHANGELOG.md b/flashcat-axios/CHANGELOG.md new file mode 100644 index 0000000..2e77304 --- /dev/null +++ b/flashcat-axios/CHANGELOG.md @@ -0,0 +1,8 @@ +# Changelog + +## 0.4.0 + +- Initial release. `trackAxios(instance)` reports every request made through an + `@ohos/axios` instance as a RUM resource and attaches the distributed-trace + headers, replacing the interceptor code applications previously had to carry + themselves. diff --git a/flashcat-axios/Index.ets b/flashcat-axios/Index.ets new file mode 100644 index 0000000..639ef67 --- /dev/null +++ b/flashcat-axios/Index.ets @@ -0,0 +1,3 @@ +// Public API surface of @flashcatcloud/axios. + +export { trackAxios } from './src/main/ets/AxiosTracking'; diff --git a/flashcat-axios/LICENSE b/flashcat-axios/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/flashcat-axios/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/flashcat-axios/README.md b/flashcat-axios/README.md new file mode 100644 index 0000000..3e61571 --- /dev/null +++ b/flashcat-axios/README.md @@ -0,0 +1,45 @@ +# @flashcatcloud/axios + +FlashCat HarmonyOS integration for [`@ohos/axios`](https://ohpm.openharmony.cn/#/cn/detail/@ohos%2Faxios). + +`@ohos/axios` sends requests through its own `@ohos.net.http` adapter, which +neither the rcp interceptor nor `FlashcatHttp` can observe. This package +registers axios interceptors that report each request as a RUM resource and +attach the distributed-trace headers. + +## Install + +```sh +ohpm install @flashcatcloud/axios +``` + +## Usage + +```ts +import axios from '@ohos/axios'; +import { trackAxios } from '@flashcatcloud/axios'; + +const api = axios.create({ baseURL: 'https://api.example.com' }); +trackAxios(api); +``` + +That is the whole integration. Requests through `api` now appear as RUM +resources, carrying `traceparent` for correlation with the server-side trace. + +## Notes + +- Interceptors are registered **per instance**: the default `axios` export and + anything from `axios.create()` do not share them. Track each instance whose + requests should appear in RUM, and track it exactly once — registering twice + reports every request twice. +- Requires `FlashcatTrace.enable(...)`, and `FlashcatRum.enable(...)` with + `setTrackNetworkRequests(true)` for the resources to surface. +- `traceparent` is injected only when tracking consent is GRANTED and the host + matches `setFirstPartyHosts()`. A request that already carries a + `traceparent` keeps it — the existing trace is not overwritten. +- A response with an error status stays a resource carrying that status. Only a + request that never received a response is reported as a network error. + +## License + +Apache-2.0 diff --git a/flashcat-axios/build-profile.json5 b/flashcat-axios/build-profile.json5 new file mode 100644 index 0000000..72f05f7 --- /dev/null +++ b/flashcat-axios/build-profile.json5 @@ -0,0 +1,18 @@ +{ + apiType: "stageMode", + buildOption: {}, + buildOptionSet: [ + { + name: "release", + arkOptions: { + obfuscation: { + ruleOptions: { enable: true, files: ["./obfuscation-rules.txt"] }, + consumerFiles: ["./obfuscation-rules.txt"] + } + } + } + ], + targets: [ + { name: "default", runtimeOS: "HarmonyOS" } + ] +} diff --git a/flashcat-axios/hvigorfile.ts b/flashcat-axios/hvigorfile.ts new file mode 100644 index 0000000..35b07bf --- /dev/null +++ b/flashcat-axios/hvigorfile.ts @@ -0,0 +1,6 @@ +import { harTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: harTasks, + plugins: [] +}; diff --git a/flashcat-axios/obfuscation-rules.txt b/flashcat-axios/obfuscation-rules.txt new file mode 100644 index 0000000..27457d6 --- /dev/null +++ b/flashcat-axios/obfuscation-rules.txt @@ -0,0 +1,3 @@ +# Keep the axios integration entry point readable for integrators. +-keep-global-name + trackAxios diff --git a/flashcat-axios/oh-package.json5 b/flashcat-axios/oh-package.json5 new file mode 100644 index 0000000..669b0fd --- /dev/null +++ b/flashcat-axios/oh-package.json5 @@ -0,0 +1,13 @@ +{ + name: "@flashcatcloud/axios", + version: "0.4.0", + description: "FlashCat HarmonyOS axios integration: reports @ohos/axios requests as RUM resources with distributed-trace headers.", + main: "Index.ets", + license: "Apache-2.0", + author: "FlashCat (https://flashcat.cloud)", + repository: "https://github.com/flashcatcloud/fc-sdk-harmony", + dependencies: { + "@flashcatcloud/trace": "0.4.0", + "@ohos/axios": "^2.2.4" + } +} diff --git a/entry/src/main/ets/common/AxiosTracking.ets b/flashcat-axios/src/main/ets/AxiosTracking.ets similarity index 61% rename from entry/src/main/ets/common/AxiosTracking.ets rename to flashcat-axios/src/main/ets/AxiosTracking.ets index 176e7b4..1efa96a 100644 --- a/entry/src/main/ets/common/AxiosTracking.ets +++ b/flashcat-axios/src/main/ets/AxiosTracking.ets @@ -1,37 +1,40 @@ +import { AxiosInstance, InternalAxiosRequestConfig, AxiosResponse, AxiosError } from '@ohos/axios'; +import { FlashcatTrace, TracedResource } from '@flashcatcloud/trace'; + /** - * axios instrumentation built on `FlashcatTrace.startTracedResource` — the - * network-stack-agnostic entry point. - * - * `@ohos/axios` sends requests through its own `@ohos.net.http` adapter, which - * neither the rcp interceptor nor the `FlashcatHttp` wrapper observes. The - * primitive registers the resource and hands back the trace headers, leaving - * this file with only what is genuinely axios-shaped: resolving the url, - * copying headers onto the request, and carrying the key between the two + * Resource keys of in-flight requests, keyed by the axios request config. + * axios hands the very same config object back on `response.config` and + * `error.config`, which makes it a reliable join key across the two * interceptors. + */ +const pending: Map = new Map(); + +/** + * Reports every request made through `instance` as a RUM resource, with the + * distributed-trace headers attached. * * ```ets + * import axios from '@ohos/axios'; + * import { trackAxios } from '@flashcatcloud/axios'; + * * const api = axios.create({ baseURL: 'https://api.example.com' }); * trackAxios(api); * ``` * - * Requires `setTrackNetworkRequests(true)` on the RUM configuration — the - * resource travels the same path as the rcp interceptor and FlashcatHttp. - */ -import { AxiosInstance, InternalAxiosRequestConfig, AxiosResponse, AxiosError } from '@ohos/axios'; -import { FlashcatTrace, TracedResource } from '@flashcatcloud/trace'; - -/** - * Resource keys of in-flight requests, keyed by the axios request config — - * axios hands the same object back on `response.config` and `error.config`. + * Interceptors are registered per instance: the default `axios` export and + * anything from `axios.create()` do not share them. Track each instance whose + * requests should appear in RUM, and track it exactly once — registering twice + * reports every request twice. + * + * Requires `FlashcatTrace.enable(...)` and, for resources to surface, + * `FlashcatRum.enable(...)` with `setTrackNetworkRequests(true)`. */ -const pending: Map = new Map(); - -/** Report every request made through `instance` as a RUM resource. */ export function trackAxios(instance: AxiosInstance): void { instance.interceptors.request.use((config: InternalAxiosRequestConfig) => { - // A request interceptor sees the relative path; axios joins it with - // `baseURL` inside the adapter. Without the host the first-party check - // cannot match, and the resource would carry a path with no host. + // A request interceptor sees `config.url` as the relative path — axios + // joins it with `baseURL` further down, inside the adapter. Resolving it + // here is what lets the first-party host check match, and what puts a full + // url on the resource instead of a bare path. const url: string = fullUrlOf(config); // An inbound traceparent means this request already belongs to a trace. const traced: TracedResource = FlashcatTrace.startTracedResource( @@ -54,8 +57,10 @@ export function trackAxios(instance: AxiosInstance): void { }, (error: AxiosError) => { // axios rejects on HTTP status, so this branch is not only transport - // failures. A response means the request completed and stays a resource - // carrying that status; only a request that never got one is an error. + // failures. A response means the request completed, so it stays a + // resource carrying that status — matching how the rcp interceptor and + // FlashcatHttp report a 404. Only a request that never got a response + // becomes a network error. const key: string = takeKey(error.config); if (key.length > 0) { const response: AxiosResponse | undefined = error.response; @@ -70,8 +75,13 @@ export function trackAxios(instance: AxiosInstance): void { ); } -/** The url axios will actually request: `baseURL` joined with the path. */ -function fullUrlOf(config: InternalAxiosRequestConfig): string { +/** + * The url axios will actually request: `baseURL` joined with the per-request + * path, unless the path is already absolute. + * + * @internal — exported for tests. + */ +export function fullUrlOf(config: InternalAxiosRequestConfig): string { const url: string = config.url ?? ''; const base: string = config.baseURL ?? ''; if (url.startsWith('http://') || url.startsWith('https://')) { @@ -101,8 +111,13 @@ function takeKey(config: Object | undefined): string { return key; } -/** Best-effort response size; axios exposes the decoded body, not raw bytes. */ -function sizeOf(data: Object | undefined): number { +/** + * Best-effort response size — axios exposes the decoded body, not the bytes + * that came off the wire. + * + * @internal — exported for tests. + */ +export function sizeOf(data: Object | undefined): number { if (data instanceof ArrayBuffer) { return data.byteLength; } diff --git a/flashcat-axios/src/main/module.json5 b/flashcat-axios/src/main/module.json5 new file mode 100644 index 0000000..5944822 --- /dev/null +++ b/flashcat-axios/src/main/module.json5 @@ -0,0 +1,7 @@ +{ + module: { + name: "flashcat_axios", + type: "har", + deviceTypes: ["default", "phone", "tablet", "2in1", "tv", "wearable", "car"] + } +} diff --git a/flashcat-axios/src/test/List.test.ets b/flashcat-axios/src/test/List.test.ets new file mode 100644 index 0000000..7b02531 --- /dev/null +++ b/flashcat-axios/src/test/List.test.ets @@ -0,0 +1,58 @@ +import { describe, expect, it, Level, Size, TestType } from '@ohos/hypium'; +import { InternalAxiosRequestConfig } from '@ohos/axios'; +import { fullUrlOf, sizeOf } from '../main/ets/AxiosTracking'; + +/** Minimal stand-in: only the two fields fullUrlOf reads. */ +function configOf(url?: string, baseURL?: string): InternalAxiosRequestConfig { + const config: Record = {}; + if (url !== undefined) { + config['url'] = url; + } + if (baseURL !== undefined) { + config['baseURL'] = baseURL; + } + return config as Object as InternalAxiosRequestConfig; +} + +export default function axiosIntegrationTests(): void { + describe('flashcat-axios', (): void => { + // A request interceptor sees the relative path; axios joins it with + // baseURL inside the adapter. Forwarding the bare path leaves the + // first-party check with no host to match, so nothing gets injected and + // the resource is reported without a host. + it('joinsBaseUrlWithTheRequestPath', TestType.FUNCTION | Size.SMALLTEST | Level.LEVEL0, (): void => { + expect(fullUrlOf(configOf('/orders', 'https://api.example.com'))) + .assertEqual('https://api.example.com/orders'); + expect(fullUrlOf(configOf('orders', 'https://api.example.com'))) + .assertEqual('https://api.example.com/orders'); + }); + + it('collapsesDuplicateSlashesAtTheJoin', TestType.FUNCTION | Size.SMALLTEST | Level.LEVEL0, (): void => { + expect(fullUrlOf(configOf('/orders', 'https://api.example.com/'))) + .assertEqual('https://api.example.com/orders'); + }); + + it('keepsAnAbsoluteRequestUrlAsIs', TestType.FUNCTION | Size.SMALLTEST | Level.LEVEL0, (): void => { + expect(fullUrlOf(configOf('https://other.example.com/p', 'https://api.example.com'))) + .assertEqual('https://other.example.com/p'); + expect(fullUrlOf(configOf('http://other.example.com/p', 'https://api.example.com'))) + .assertEqual('http://other.example.com/p'); + }); + + it('handlesEitherHalfBeingAbsent', TestType.FUNCTION | Size.SMALLTEST | Level.LEVEL0, (): void => { + expect(fullUrlOf(configOf('https://api.example.com/p'))).assertEqual('https://api.example.com/p'); + expect(fullUrlOf(configOf(undefined, 'https://api.example.com'))).assertEqual('https://api.example.com'); + expect(fullUrlOf(configOf())).assertEqual(''); + }); + + it('measuresTheDecodedResponseBody', TestType.FUNCTION | Size.SMALLTEST | Level.LEVEL0, (): void => { + expect(sizeOf('hello')).assertEqual(5); + expect(sizeOf(new ArrayBuffer(64))).assertEqual(64); + expect(sizeOf(undefined)).assertEqual(0); + // Objects are measured by their serialized length — axios hands back the + // parsed body, so the bytes off the wire are no longer available. + const body: Record = { 'a': 1 }; + expect(sizeOf(body)).assertEqual('{"a":1}'.length); + }); + }); +} diff --git a/flashcat-rum/README.md b/flashcat-rum/README.md index 458c5f7..0323e16 100644 --- a/flashcat-rum/README.md +++ b/flashcat-rum/README.md @@ -14,7 +14,7 @@ ohpm install @flashcatcloud/rum ## Usage ```ts -import { FlashcatRum, RumConfigurationBuilder } from '@flashcatcloud/rum'; +import { FlashcatRum, GlobalRumMonitor, RumConfigurationBuilder } from '@flashcatcloud/rum'; const rumConfig = new RumConfigurationBuilder('') .setTrackUserInteractions(true) @@ -22,7 +22,7 @@ const rumConfig = new RumConfigurationBuilder('') .build(); FlashcatRum.enable(rumConfig); -FlashcatRum.startView('home', 'Home'); +GlobalRumMonitor.get().startView('home', 'Home'); ``` ## Instrumentation coverage (read before integrating) diff --git a/oh-package.json5 b/oh-package.json5 index 96e21ba..5781294 100644 --- a/oh-package.json5 +++ b/oh-package.json5 @@ -13,6 +13,7 @@ "@ohos/hamock": "1.0.0" }, overrides: { - "@flashcatcloud/core": "file:./flashcat-core" + "@flashcatcloud/core": "file:./flashcat-core", + "@flashcatcloud/trace": "file:./flashcat-trace" } } diff --git a/scripts/unit-node/run.mjs b/scripts/unit-node/run.mjs index 5793294..02c7f4d 100644 --- a/scripts/unit-node/run.mjs +++ b/scripts/unit-node/run.mjs @@ -43,7 +43,7 @@ if (ts === null) { process.exit(2); } -const MODULES = ['flashcat-core', 'flashcat-rum', 'flashcat-crash', 'flashcat-trace']; +const MODULES = ['flashcat-core', 'flashcat-rum', 'flashcat-crash', 'flashcat-trace', 'flashcat-axios']; // ---- transpile ---- fs.rmSync(outRoot, { recursive: true, force: true }); @@ -104,7 +104,8 @@ const SHIM_MAP = { '@kit.PerformanceAnalysisKit': path.join(shimDir, 'kit-performance.js'), '@kit.RemoteCommunicationKit': path.join(shimDir, 'kit-rcp.js'), '@ohos.app.ability.appRecovery': path.join(shimDir, 'app-recovery.js'), - '@flashcatcloud/core': path.join(outRoot, 'flashcat-core', 'Index.js') + '@flashcatcloud/core': path.join(outRoot, 'flashcat-core', 'Index.js'), + '@flashcatcloud/trace': path.join(outRoot, 'flashcat-trace', 'Index.js') }; Module._resolveFilename = function patched(request, ...rest) { if (SHIM_MAP[request] !== undefined) {