From 45a15cb5f152ec954b621e103b05728d2cf505c5 Mon Sep 17 00:00:00 2001 From: Corne de Bruin Date: Tue, 6 Dec 2022 09:37:16 +0100 Subject: [PATCH 1/7] Added requesttracker instance to enable custom request tracking and exposed a few more configuration flags --- packages/nativescript-appdynamics/common.ts | 89 ++++++++++++++++++- .../nativescript-appdynamics/index.android.ts | 42 ++++++++- packages/nativescript-appdynamics/index.d.ts | 4 +- .../nativescript-appdynamics/index.ios.ts | 36 +++++++- 4 files changed, 163 insertions(+), 8 deletions(-) diff --git a/packages/nativescript-appdynamics/common.ts b/packages/nativescript-appdynamics/common.ts index 92623cc..8e1260b 100644 --- a/packages/nativescript-appdynamics/common.ts +++ b/packages/nativescript-appdynamics/common.ts @@ -1,3 +1,5 @@ +import { HttpHeaders } from '@angular/common/http'; + interface SessionFrame { updateName(name: string): void; } @@ -16,10 +18,86 @@ export enum LoggingLevel { // the app key can be created from the AppDynamics control panel when adding a new app. // The app key should be of format "AD-AAA-BBB", AppDynamics will error if it's malformed. export interface AppdynamicsConfiguration { + /** + * Sets the application key used by the SDK. This is a required property. + */ + /** + * Sets the application key used by the SDK. This is a required property. + */ appKey: string; - collectorURL: string; // should be the 'EUM Cloud' / 'EUM Collector' address - screenshotURL: string; // should be the 'Screenshot Service' address + + /** + * Sets the name of this mobile application. If not set, the application name is the + * package name from the Android Manifest. Most users will not need this. + * + * The `applicationName` may contain uppercase or lowercase letters ('A' through 'Z'), numbers, + * and underscores ('_'). + * + * **NOTE:** If this property is set, all data reported from this application is associated with `applicationName`, + * and appears together in dashboards. + */ + applicationName?: string; + + /** + * Boolean value that indicates if automatic instrumentation is enabled. + * + * Setting this to `false` will disable all automatic instrumentation regardless of any code injection. + * The following features will also be effected: + * + * 1. {@link interactionCaptureMode} will be set to {@link InteractionCaptureMode.None} + * 2. Automatic Network requests from supported libraries will not be tracked. + * 3. Any UI transition events will not be tracked. + * 4. Screenshots (both automatic and manual) will be disabled. + * + * Set to `false` to disable automatic instrumentation, `true` to enable (default is enabled) + */ + autoInstrument?: boolean; + + /** + * Sets the URL of the collector to which the agent will report. + * + * This is NOT your controller URL. You likely do not need to call this method + * unless you have an on-premise EUM Processor. + */ + collectorURL?: string; // should be the 'EUM Cloud' / 'EUM Collector' address + /** + * Sets the URL of the screenshot service to which the agent will upload screenshots. + * + * This is NOT your controller URL. You likely do not need to call this method + * unless you have an AppDynamics managed private cloud (very rare). + * + * **NOTE:** If you have an on-premise EUM Processor + * and set the collector URL in {@link collectorURL}, + * then you do not need to call this method + * because the two URLs are the same, + * and the agent assumes that is the case. + */ + screenshotURL?: string; // should be the 'Screenshot Service' address + /** + * Sets the logging level of the agent. Default is {@link LoggingLevel.LOGGING_LEVEL_NONE}. + * + * **WARNING:** Not recommended for production use. + */ loggingLevel?: LoggingLevel; // defaults to 'Error' + + /** + * Enables or disables JavaScript agent AJAX call reporting. + * If enabled, JavaScript agent will capture AJAX calls in WebViews. + * + * Default is disabled. + * JS Agent injection needs to be enabled for this to have an effect + * See {@link jsAgentInjectionEnabled} + * @param enable true to enable JS AJAX reporting, false to disable + */ + jsAgentAjaxEnabled?: boolean; + + /** + * Enables or disables JavaScript agent injection into WebViews. + * If enabled, JavaScript agent will capture page loads in WebViews. + * + * Default is enabled. + */ + jsAgentInjectionEnabled?: boolean; } export interface IAppdynamics { @@ -31,3 +109,10 @@ export interface IAppdynamics { setUserData(key: string, value: string): void; requestTracker(value: string): void; } + +export interface IRequestTracker { + setError(error: any): void; + setStatusCode(statusCode: number); + setHeaders(headers: HttpHeaders); + reportDone(): void; +} diff --git a/packages/nativescript-appdynamics/index.android.ts b/packages/nativescript-appdynamics/index.android.ts index da3de9e..5737c2e 100644 --- a/packages/nativescript-appdynamics/index.android.ts +++ b/packages/nativescript-appdynamics/index.android.ts @@ -1,5 +1,6 @@ +import { HttpHeaders } from '@angular/common/http'; import { Utils } from '@nativescript/core'; -import { AppdynamicsConfiguration, IAppdynamics, LoggingLevel } from './common'; +import { AppdynamicsConfiguration, IAppdynamics, LoggingLevel, IRequestTracker } from './common'; import lazy from '@nativescript/core/utils/lazy'; const Instrumentation = lazy(() => com.appdynamics.eumagent.runtime.Instrumentation); @@ -14,6 +15,10 @@ export class Appdynamics implements IAppdynamics { .withCollectorURL(config.collectorURL) .withScreenshotURL(config.screenshotURL) .withLoggingLevel(config.loggingLevel || LoggingLevel.Error) + .withApplicationName(config.applicationName) + .withJSAgentAjaxEnabled(config.jsAgentAjaxEnabled) + .withJSAgentInjectionEnabled(config.jsAgentInjectionEnabled) + .withAutoInstrument(config.autoInstrument) .build(); Instrumentation().start(instrumentationConfig); @@ -40,6 +45,39 @@ export class Appdynamics implements IAppdynamics { } public requestTracker(url: string) { - return Instrumentation().beginHttpRequest(new java.net.URL(url)); + return new RequestTracker(url); + } +} + +export class RequestTracker implements IRequestTracker { + private _tracker; + + constructor(url) { + this._tracker = Instrumentation().beginHttpRequest(new java.net.URL(url)); + } + + setError(error) { + this._tracker.withError(error); + } + + reportDone(): void { + this._tracker.reportDone(); + } + + setHeaders(httpHeaders: HttpHeaders) { + const headerKeys = httpHeaders.keys(); + const values: java.util.HashMap> = new java.util.HashMap>(); + + headerKeys.forEach((key) => { + const stringList: java.util.ArrayList = new java.util.ArrayList(); + httpHeaders.getAll(key).forEach((headerValue) => stringList.add(headerValue)); + values.put(key, stringList); + }); + + this._tracker.withResponseHeaderFields(httpHeaders); + } + + setStatusCode(statusCode) { + this._tracker.withResponseCode(statusCode); } } diff --git a/packages/nativescript-appdynamics/index.d.ts b/packages/nativescript-appdynamics/index.d.ts index 42889a5..50d478d 100644 --- a/packages/nativescript-appdynamics/index.d.ts +++ b/packages/nativescript-appdynamics/index.d.ts @@ -1,4 +1,4 @@ -import { AppdynamicsConfiguration } from '@essent/nativescript-appdynamics/common'; +import { AppdynamicsConfiguration } from './common'; declare interface SessionFrame { updateName(name: string): void; @@ -12,5 +12,5 @@ export declare class Appdynamics { startTimer(name: string): void; stopTimer(name: string): void; setUserData(key: string, value: string): void; - requestTracker(value: string): void; + requestTracker(value: string): RequestTracker; } diff --git a/packages/nativescript-appdynamics/index.ios.ts b/packages/nativescript-appdynamics/index.ios.ts index e6623c6..529eeb5 100644 --- a/packages/nativescript-appdynamics/index.ios.ts +++ b/packages/nativescript-appdynamics/index.ios.ts @@ -1,4 +1,4 @@ -import { AppdynamicsConfiguration, IAppdynamics, LoggingLevel } from './common'; +import { AppdynamicsConfiguration, IAppdynamics, LoggingLevel, IRequestTracker } from './common'; // https://docs.appdynamics.com/appd/21.x/21.9/en/end-user-monitoring/mobile-real-user-monitoring/instrument-ios-applications/customize-the-ios-instrumentation @@ -8,6 +8,10 @@ export class Appdynamics implements IAppdynamics { adeumConfig.collectorURL = config.collectorURL; adeumConfig.screenshotURL = config.screenshotURL; adeumConfig.loggingLevel = (config.loggingLevel || LoggingLevel.Error) as unknown as ADEumLoggingLevel; + adeumConfig.applicationName = config.applicationName; + adeumConfig.jsAgentAjaxEnabled = config.jsAgentAjaxEnabled; + adeumConfig.jsAgentEnabled = config.jsAgentInjectionEnabled; + adeumConfig.enableAutoInstrument = config.autoInstrument; ADEumInstrumentation.initWithConfiguration(adeumConfig); } @@ -33,6 +37,34 @@ export class Appdynamics implements IAppdynamics { } public requestTracker(value: string) { - return ADEumHTTPRequestTracker.requestTrackerWithURL(NSURL.URLWithString(value)); + return new RequestTracker(value); + } +} + +export class RequestTracker implements IRequestTracker { + private _tracker; + + constructor(url) { + this._tracker = ADEumHTTPRequestTracker.requestTrackerWithURL(NSURL.URLWithString(url)); + } + + setError(error) { + this._tracker.error = error; + } + + reportDone(): void { + this._tracker.reportDone(); + } + + setHeaders(headers) { + const values: string[] = []; + const headerKeys = headers.keys(); + headerKeys.forEach((value, index) => (values[index] = value)); + + this._tracker.allHeaderFields = NSDictionary.dictionaryWithObjectsForKeys(values, headerKeys); + } + + setStatusCode(statusCode) { + this._tracker.statusCode = statusCode; } } From d613448be4e67254e7c255bbaf539d9902ea88ea Mon Sep 17 00:00:00 2001 From: Corne de Bruin Date: Tue, 6 Dec 2022 11:08:09 +0100 Subject: [PATCH 2/7] Fixed issue in Android setHeaders function and added missing typing for the RequestTracker --- .../nativescript-appdynamics/index.android.ts | 6 +++--- packages/nativescript-appdynamics/index.d.ts | 8 ++++++++ packages/nativescript-appdynamics/package.json | 16 +--------------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/packages/nativescript-appdynamics/index.android.ts b/packages/nativescript-appdynamics/index.android.ts index 5737c2e..74facc9 100644 --- a/packages/nativescript-appdynamics/index.android.ts +++ b/packages/nativescript-appdynamics/index.android.ts @@ -66,15 +66,15 @@ export class RequestTracker implements IRequestTracker { setHeaders(httpHeaders: HttpHeaders) { const headerKeys = httpHeaders.keys(); - const values: java.util.HashMap> = new java.util.HashMap>(); + const headerFieldsMap: java.util.HashMap> = new java.util.HashMap>(); headerKeys.forEach((key) => { const stringList: java.util.ArrayList = new java.util.ArrayList(); httpHeaders.getAll(key).forEach((headerValue) => stringList.add(headerValue)); - values.put(key, stringList); + headerFieldsMap.put(key, stringList); }); - this._tracker.withResponseHeaderFields(httpHeaders); + this._tracker.withResponseHeaderFields(headerFieldsMap); } setStatusCode(statusCode) { diff --git a/packages/nativescript-appdynamics/index.d.ts b/packages/nativescript-appdynamics/index.d.ts index 50d478d..891bd90 100644 --- a/packages/nativescript-appdynamics/index.d.ts +++ b/packages/nativescript-appdynamics/index.d.ts @@ -1,3 +1,4 @@ +import { HttpHeaders } from '@angular/common/http'; import { AppdynamicsConfiguration } from './common'; declare interface SessionFrame { @@ -14,3 +15,10 @@ export declare class Appdynamics { setUserData(key: string, value: string): void; requestTracker(value: string): RequestTracker; } + +export declare class RequestTracker { + setError(error: any): void; + setStatusCode(statusCode: number): void; + setHeaders(headers: HttpHeaders): void; + reportDone(): void; +} diff --git a/packages/nativescript-appdynamics/package.json b/packages/nativescript-appdynamics/package.json index 529ea4e..a59a645 100644 --- a/packages/nativescript-appdynamics/package.json +++ b/packages/nativescript-appdynamics/package.json @@ -8,21 +8,7 @@ "platforms": { "ios": "6.0.0", "android": "6.0.0" - }, - "hooks": [ - { - "name": "essent-nativescript-appdynamics", - "type": "before-checkForChanges", - "script": "hooks/before-checkForChanges.js", - "inject": true - }, - { - "name": "essent-nativescript-appdynamics", - "type": "before-watchPatterns", - "script": "hooks/before-watchPatterns.js", - "inject": true - } - ] + } }, "scripts": { "preuninstall": "node preuninstall", From f3a874d80ca61c5b0e89338f5af414649f997037 Mon Sep 17 00:00:00 2001 From: Corne de Bruin Date: Tue, 6 Dec 2022 11:09:57 +0100 Subject: [PATCH 3/7] Revert "Fixed issue in Android setHeaders function and added missing typing for the RequestTracker" This reverts commit d613448be4e67254e7c255bbaf539d9902ea88ea. --- .../nativescript-appdynamics/index.android.ts | 6 +++--- packages/nativescript-appdynamics/index.d.ts | 8 -------- packages/nativescript-appdynamics/package.json | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/nativescript-appdynamics/index.android.ts b/packages/nativescript-appdynamics/index.android.ts index 74facc9..5737c2e 100644 --- a/packages/nativescript-appdynamics/index.android.ts +++ b/packages/nativescript-appdynamics/index.android.ts @@ -66,15 +66,15 @@ export class RequestTracker implements IRequestTracker { setHeaders(httpHeaders: HttpHeaders) { const headerKeys = httpHeaders.keys(); - const headerFieldsMap: java.util.HashMap> = new java.util.HashMap>(); + const values: java.util.HashMap> = new java.util.HashMap>(); headerKeys.forEach((key) => { const stringList: java.util.ArrayList = new java.util.ArrayList(); httpHeaders.getAll(key).forEach((headerValue) => stringList.add(headerValue)); - headerFieldsMap.put(key, stringList); + values.put(key, stringList); }); - this._tracker.withResponseHeaderFields(headerFieldsMap); + this._tracker.withResponseHeaderFields(httpHeaders); } setStatusCode(statusCode) { diff --git a/packages/nativescript-appdynamics/index.d.ts b/packages/nativescript-appdynamics/index.d.ts index 891bd90..50d478d 100644 --- a/packages/nativescript-appdynamics/index.d.ts +++ b/packages/nativescript-appdynamics/index.d.ts @@ -1,4 +1,3 @@ -import { HttpHeaders } from '@angular/common/http'; import { AppdynamicsConfiguration } from './common'; declare interface SessionFrame { @@ -15,10 +14,3 @@ export declare class Appdynamics { setUserData(key: string, value: string): void; requestTracker(value: string): RequestTracker; } - -export declare class RequestTracker { - setError(error: any): void; - setStatusCode(statusCode: number): void; - setHeaders(headers: HttpHeaders): void; - reportDone(): void; -} diff --git a/packages/nativescript-appdynamics/package.json b/packages/nativescript-appdynamics/package.json index a59a645..529ea4e 100644 --- a/packages/nativescript-appdynamics/package.json +++ b/packages/nativescript-appdynamics/package.json @@ -8,7 +8,21 @@ "platforms": { "ios": "6.0.0", "android": "6.0.0" - } + }, + "hooks": [ + { + "name": "essent-nativescript-appdynamics", + "type": "before-checkForChanges", + "script": "hooks/before-checkForChanges.js", + "inject": true + }, + { + "name": "essent-nativescript-appdynamics", + "type": "before-watchPatterns", + "script": "hooks/before-watchPatterns.js", + "inject": true + } + ] }, "scripts": { "preuninstall": "node preuninstall", From a37e6a08d0860421c4ffdbc9fc71331779ada196 Mon Sep 17 00:00:00 2001 From: Corne de Bruin Date: Fri, 16 Dec 2022 15:22:08 +0100 Subject: [PATCH 4/7] Updated setting Error on the RequestTracker --- packages/nativescript-appdynamics/common.ts | 5 ++--- .../nativescript-appdynamics/index.android.ts | 19 +++---------------- packages/nativescript-appdynamics/index.d.ts | 6 ++++++ .../nativescript-appdynamics/index.ios.ts | 13 +++---------- 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/packages/nativescript-appdynamics/common.ts b/packages/nativescript-appdynamics/common.ts index 8e1260b..b68f991 100644 --- a/packages/nativescript-appdynamics/common.ts +++ b/packages/nativescript-appdynamics/common.ts @@ -1,4 +1,4 @@ -import { HttpHeaders } from '@angular/common/http'; +import { HttpErrorResponse } from '@angular/common/http'; interface SessionFrame { updateName(name: string): void; @@ -111,8 +111,7 @@ export interface IAppdynamics { } export interface IRequestTracker { - setError(error: any): void; + setError(error: HttpErrorResponse): void; setStatusCode(statusCode: number); - setHeaders(headers: HttpHeaders); reportDone(): void; } diff --git a/packages/nativescript-appdynamics/index.android.ts b/packages/nativescript-appdynamics/index.android.ts index 5737c2e..d130018 100644 --- a/packages/nativescript-appdynamics/index.android.ts +++ b/packages/nativescript-appdynamics/index.android.ts @@ -1,4 +1,4 @@ -import { HttpHeaders } from '@angular/common/http'; +import { HttpErrorResponse } from '@angular/common/http'; import { Utils } from '@nativescript/core'; import { AppdynamicsConfiguration, IAppdynamics, LoggingLevel, IRequestTracker } from './common'; import lazy from '@nativescript/core/utils/lazy'; @@ -56,27 +56,14 @@ export class RequestTracker implements IRequestTracker { this._tracker = Instrumentation().beginHttpRequest(new java.net.URL(url)); } - setError(error) { - this._tracker.withError(error); + setError(error: HttpErrorResponse) { + this._tracker.withError(error.message); } reportDone(): void { this._tracker.reportDone(); } - setHeaders(httpHeaders: HttpHeaders) { - const headerKeys = httpHeaders.keys(); - const values: java.util.HashMap> = new java.util.HashMap>(); - - headerKeys.forEach((key) => { - const stringList: java.util.ArrayList = new java.util.ArrayList(); - httpHeaders.getAll(key).forEach((headerValue) => stringList.add(headerValue)); - values.put(key, stringList); - }); - - this._tracker.withResponseHeaderFields(httpHeaders); - } - setStatusCode(statusCode) { this._tracker.withResponseCode(statusCode); } diff --git a/packages/nativescript-appdynamics/index.d.ts b/packages/nativescript-appdynamics/index.d.ts index 50d478d..2a0f39e 100644 --- a/packages/nativescript-appdynamics/index.d.ts +++ b/packages/nativescript-appdynamics/index.d.ts @@ -14,3 +14,9 @@ export declare class Appdynamics { setUserData(key: string, value: string): void; requestTracker(value: string): RequestTracker; } + +export interface RequestTracker { + setError(error: HttpErrorResponse): void; + setStatusCode(statusCode: number); + reportDone(): void; +} diff --git a/packages/nativescript-appdynamics/index.ios.ts b/packages/nativescript-appdynamics/index.ios.ts index 529eeb5..0be4557 100644 --- a/packages/nativescript-appdynamics/index.ios.ts +++ b/packages/nativescript-appdynamics/index.ios.ts @@ -1,3 +1,4 @@ +import { HttpErrorResponse } from '@angular/common/http'; import { AppdynamicsConfiguration, IAppdynamics, LoggingLevel, IRequestTracker } from './common'; // https://docs.appdynamics.com/appd/21.x/21.9/en/end-user-monitoring/mobile-real-user-monitoring/instrument-ios-applications/customize-the-ios-instrumentation @@ -48,22 +49,14 @@ export class RequestTracker implements IRequestTracker { this._tracker = ADEumHTTPRequestTracker.requestTrackerWithURL(NSURL.URLWithString(url)); } - setError(error) { - this._tracker.error = error; + setError(error: HttpErrorResponse) { + this._tracker.error = NSError.new().initWithDomainCodeUserInfo('nl.essent.verbruiksmanagerplus', error.status, NSDictionary.dictionaryWithObjectForKey('Error reason', error.message)); } reportDone(): void { this._tracker.reportDone(); } - setHeaders(headers) { - const values: string[] = []; - const headerKeys = headers.keys(); - headerKeys.forEach((value, index) => (values[index] = value)); - - this._tracker.allHeaderFields = NSDictionary.dictionaryWithObjectsForKeys(values, headerKeys); - } - setStatusCode(statusCode) { this._tracker.statusCode = statusCode; } From 263917bbb6f23f9239ffa5bed6cc4a54f11c7192 Mon Sep 17 00:00:00 2001 From: Corne de Bruin Date: Fri, 16 Dec 2022 16:00:53 +0100 Subject: [PATCH 5/7] Added setHeaders function on the RequestTracker --- packages/nativescript-appdynamics/common.ts | 1 + packages/nativescript-appdynamics/index.android.ts | 13 +++++++++++++ packages/nativescript-appdynamics/index.d.ts | 1 + packages/nativescript-appdynamics/index.ios.ts | 8 ++++++++ 4 files changed, 23 insertions(+) diff --git a/packages/nativescript-appdynamics/common.ts b/packages/nativescript-appdynamics/common.ts index b68f991..ee5517e 100644 --- a/packages/nativescript-appdynamics/common.ts +++ b/packages/nativescript-appdynamics/common.ts @@ -113,5 +113,6 @@ export interface IAppdynamics { export interface IRequestTracker { setError(error: HttpErrorResponse): void; setStatusCode(statusCode: number); + setHeaders(headers: { [key: string]: string[] | null }); reportDone(): void; } diff --git a/packages/nativescript-appdynamics/index.android.ts b/packages/nativescript-appdynamics/index.android.ts index d130018..4c36bca 100644 --- a/packages/nativescript-appdynamics/index.android.ts +++ b/packages/nativescript-appdynamics/index.android.ts @@ -64,6 +64,19 @@ export class RequestTracker implements IRequestTracker { this._tracker.reportDone(); } + setHeaders(httpHeaders: { [key: string]: string[] | null }) { + const headerKeys = Object.keys(httpHeaders); + const values: java.util.HashMap> = new java.util.HashMap>(); + + headerKeys.forEach((key) => { + const stringList: java.util.ArrayList = new java.util.ArrayList(); + httpHeaders[key].forEach((headerValue) => stringList.add(headerValue)); + values.put(key, stringList); + }); + + this._tracker.withResponseHeaderFields(httpHeaders); + } + setStatusCode(statusCode) { this._tracker.withResponseCode(statusCode); } diff --git a/packages/nativescript-appdynamics/index.d.ts b/packages/nativescript-appdynamics/index.d.ts index 2a0f39e..351b638 100644 --- a/packages/nativescript-appdynamics/index.d.ts +++ b/packages/nativescript-appdynamics/index.d.ts @@ -18,5 +18,6 @@ export declare class Appdynamics { export interface RequestTracker { setError(error: HttpErrorResponse): void; setStatusCode(statusCode: number); + setHeaders(headers: { [key: string]: string[] | null }); reportDone(): void; } diff --git a/packages/nativescript-appdynamics/index.ios.ts b/packages/nativescript-appdynamics/index.ios.ts index 0be4557..b431f50 100644 --- a/packages/nativescript-appdynamics/index.ios.ts +++ b/packages/nativescript-appdynamics/index.ios.ts @@ -57,6 +57,14 @@ export class RequestTracker implements IRequestTracker { this._tracker.reportDone(); } + setHeaders(headers: { [key: string]: string[] | null }) { + const values: string[][] = []; + const headerKeys = Object.keys(headers); + headerKeys.forEach((value, index) => (values[index] = headers[value])); + + this._tracker.allHeaderFields = NSDictionary.dictionaryWithObjectsForKeys(values, headerKeys); + } + setStatusCode(statusCode) { this._tracker.statusCode = statusCode; } From 17b2017a4f5aab5729b33c8f0408e59926996404 Mon Sep 17 00:00:00 2001 From: Corne de Bruin Date: Tue, 20 Dec 2022 10:53:33 +0100 Subject: [PATCH 6/7] Fixed android custom request tracker not updating the internal native tracker --- packages/nativescript-appdynamics/common.ts | 2 +- .../nativescript-appdynamics/index.android.ts | 16 ++++++++-------- packages/nativescript-appdynamics/index.d.ts | 4 ++-- packages/nativescript-appdynamics/index.ios.ts | 12 ++++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/nativescript-appdynamics/common.ts b/packages/nativescript-appdynamics/common.ts index ee5517e..3a9d3a2 100644 --- a/packages/nativescript-appdynamics/common.ts +++ b/packages/nativescript-appdynamics/common.ts @@ -111,7 +111,7 @@ export interface IAppdynamics { } export interface IRequestTracker { - setError(error: HttpErrorResponse): void; + setError(error: HttpErrorResponse, domain: string): void; setStatusCode(statusCode: number); setHeaders(headers: { [key: string]: string[] | null }); reportDone(): void; diff --git a/packages/nativescript-appdynamics/index.android.ts b/packages/nativescript-appdynamics/index.android.ts index 4c36bca..2d343f3 100644 --- a/packages/nativescript-appdynamics/index.android.ts +++ b/packages/nativescript-appdynamics/index.android.ts @@ -56,12 +56,8 @@ export class RequestTracker implements IRequestTracker { this._tracker = Instrumentation().beginHttpRequest(new java.net.URL(url)); } - setError(error: HttpErrorResponse) { - this._tracker.withError(error.message); - } - - reportDone(): void { - this._tracker.reportDone(); + setError(error: HttpErrorResponse, domain: string) { + this._tracker = this._tracker.withError(error.message); } setHeaders(httpHeaders: { [key: string]: string[] | null }) { @@ -74,10 +70,14 @@ export class RequestTracker implements IRequestTracker { values.put(key, stringList); }); - this._tracker.withResponseHeaderFields(httpHeaders); + this._tracker = this._tracker.withResponseHeaderFields(values); } setStatusCode(statusCode) { - this._tracker.withResponseCode(statusCode); + this._tracker = this._tracker.withResponseCode(statusCode); + } + + reportDone(): void { + this._tracker.reportDone(); } } diff --git a/packages/nativescript-appdynamics/index.d.ts b/packages/nativescript-appdynamics/index.d.ts index 351b638..a1b6253 100644 --- a/packages/nativescript-appdynamics/index.d.ts +++ b/packages/nativescript-appdynamics/index.d.ts @@ -15,8 +15,8 @@ export declare class Appdynamics { requestTracker(value: string): RequestTracker; } -export interface RequestTracker { - setError(error: HttpErrorResponse): void; +export declare class RequestTracker { + setError(error: HttpErrorResponse, domain: string): void; setStatusCode(statusCode: number); setHeaders(headers: { [key: string]: string[] | null }); reportDone(): void; diff --git a/packages/nativescript-appdynamics/index.ios.ts b/packages/nativescript-appdynamics/index.ios.ts index b431f50..4ee6759 100644 --- a/packages/nativescript-appdynamics/index.ios.ts +++ b/packages/nativescript-appdynamics/index.ios.ts @@ -49,12 +49,8 @@ export class RequestTracker implements IRequestTracker { this._tracker = ADEumHTTPRequestTracker.requestTrackerWithURL(NSURL.URLWithString(url)); } - setError(error: HttpErrorResponse) { - this._tracker.error = NSError.new().initWithDomainCodeUserInfo('nl.essent.verbruiksmanagerplus', error.status, NSDictionary.dictionaryWithObjectForKey('Error reason', error.message)); - } - - reportDone(): void { - this._tracker.reportDone(); + setError(error: HttpErrorResponse, domain: string) { + this._tracker.error = NSError.new().initWithDomainCodeUserInfo(domain, error.status, NSDictionary.dictionaryWithObjectForKey('Error reason', error.message)); } setHeaders(headers: { [key: string]: string[] | null }) { @@ -68,4 +64,8 @@ export class RequestTracker implements IRequestTracker { setStatusCode(statusCode) { this._tracker.statusCode = statusCode; } + + reportDone(): void { + this._tracker.reportDone(); + } } From 6a30a7839b856ea979572d981398eaada67ed7b0 Mon Sep 17 00:00:00 2001 From: Corne de Bruin Date: Tue, 20 Dec 2022 11:08:16 +0100 Subject: [PATCH 7/7] Removed duplicate comment Update defaulting loglevel to off Removed explicit typing --- packages/nativescript-appdynamics/common.ts | 7 ++----- packages/nativescript-appdynamics/index.android.ts | 6 +++--- packages/nativescript-appdynamics/index.ios.ts | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/nativescript-appdynamics/common.ts b/packages/nativescript-appdynamics/common.ts index 3a9d3a2..f611258 100644 --- a/packages/nativescript-appdynamics/common.ts +++ b/packages/nativescript-appdynamics/common.ts @@ -18,9 +18,6 @@ export enum LoggingLevel { // the app key can be created from the AppDynamics control panel when adding a new app. // The app key should be of format "AD-AAA-BBB", AppDynamics will error if it's malformed. export interface AppdynamicsConfiguration { - /** - * Sets the application key used by the SDK. This is a required property. - */ /** * Sets the application key used by the SDK. This is a required property. */ @@ -74,11 +71,11 @@ export interface AppdynamicsConfiguration { */ screenshotURL?: string; // should be the 'Screenshot Service' address /** - * Sets the logging level of the agent. Default is {@link LoggingLevel.LOGGING_LEVEL_NONE}. + * Sets the logging level of the agent. Default is {@link LoggingLevel.Off}. * * **WARNING:** Not recommended for production use. */ - loggingLevel?: LoggingLevel; // defaults to 'Error' + loggingLevel?: LoggingLevel; // defaults to 'Off' /** * Enables or disables JavaScript agent AJAX call reporting. diff --git a/packages/nativescript-appdynamics/index.android.ts b/packages/nativescript-appdynamics/index.android.ts index 2d343f3..1e872d5 100644 --- a/packages/nativescript-appdynamics/index.android.ts +++ b/packages/nativescript-appdynamics/index.android.ts @@ -14,7 +14,7 @@ export class Appdynamics implements IAppdynamics { .withContext(Utils.android.getApplicationContext()) .withCollectorURL(config.collectorURL) .withScreenshotURL(config.screenshotURL) - .withLoggingLevel(config.loggingLevel || LoggingLevel.Error) + .withLoggingLevel(config.loggingLevel || LoggingLevel.Off) .withApplicationName(config.applicationName) .withJSAgentAjaxEnabled(config.jsAgentAjaxEnabled) .withJSAgentInjectionEnabled(config.jsAgentInjectionEnabled) @@ -62,10 +62,10 @@ export class RequestTracker implements IRequestTracker { setHeaders(httpHeaders: { [key: string]: string[] | null }) { const headerKeys = Object.keys(httpHeaders); - const values: java.util.HashMap> = new java.util.HashMap>(); + const values = new java.util.HashMap>(); headerKeys.forEach((key) => { - const stringList: java.util.ArrayList = new java.util.ArrayList(); + const stringList = new java.util.ArrayList(); httpHeaders[key].forEach((headerValue) => stringList.add(headerValue)); values.put(key, stringList); }); diff --git a/packages/nativescript-appdynamics/index.ios.ts b/packages/nativescript-appdynamics/index.ios.ts index 4ee6759..7dee48c 100644 --- a/packages/nativescript-appdynamics/index.ios.ts +++ b/packages/nativescript-appdynamics/index.ios.ts @@ -8,7 +8,7 @@ export class Appdynamics implements IAppdynamics { const adeumConfig = ADEumAgentConfiguration.alloc().initWithAppKey(config.appKey); adeumConfig.collectorURL = config.collectorURL; adeumConfig.screenshotURL = config.screenshotURL; - adeumConfig.loggingLevel = (config.loggingLevel || LoggingLevel.Error) as unknown as ADEumLoggingLevel; + adeumConfig.loggingLevel = (config.loggingLevel || LoggingLevel.Off) as unknown as ADEumLoggingLevel; adeumConfig.applicationName = config.applicationName; adeumConfig.jsAgentAjaxEnabled = config.jsAgentAjaxEnabled; adeumConfig.jsAgentEnabled = config.jsAgentInjectionEnabled;