Skip to content

Commit

Permalink
Merge pull request #15068 from mbruin-NR/NR-167603
Browse files Browse the repository at this point in the history
Added an article on a new mobile agents api for tracking http headers
  • Loading branch information
bradleycamacho committed Nov 15, 2023
2 parents 161c07b + f4420cb commit 22f5a63
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
---
title: Mobile SDK guide
tags:
- Mobile monitoring
- API guides
metaDescription: 'Customize your mobile agent instrumentation to capture specific HTTP header fields.'
---

<Tabs>
<TabsBar>
<TabsBarItem id="android">
Android
</TabsBarItem>
<TabsBarItem id="ios">
iOS
</TabsBarItem>
</TabsBar>

<TabsPages>
<TabsPageItem id="android">
## Syntax [#syntax]

### Java [#java]

```java
NewRelic.addHTTPHeadersTrackingFor(List<String> headers)
```

### Kotlin [#kotlin]

```kotlin
NewRelic.addHTTPHeadersTrackingFor(List<String> headers)
```

## Description [#description]

This API allows you to add any header field strings to a list that gets recorded as attributes with networking request events. After header fields have been added using this function, if the headers are in a network call they will be included in networking events in NR1.
The Android agent currently automatically captures the following header fields: X-APOLLO-OPERATION-NAME, X-APOLLO-OPERATION-TYPE, and X-APOLLO-OPERATION-ID.

## Parameters [#parameters]

<table>
<thead>
<tr>
<th width="30%">
Parameter
</th>

<th width="30%">
Type
</th>
<th>
Description
</th>
</tr>
</thead>

<tbody>
<tr>
<td>
`$headers`
</td>

<td>
`List<String>`
</td>

<td>
Required. The HTTP header fields to be added.
</td>
</tr>
</tbody>
</table>

## Return values [#return-values]

Returns `true` if added successfully, or `false` if not.

## Examples [#examples]

Here's an example of adding some HTTP header fields:

### Java [#java]

```java
List headers = new ArrayList();
headers.add("httpClient");
headers.add("CustomAttribute");
NewRelic.addHTTPHeadersTrackingFor(headers);`

// Okhttp3
Request request = new Request.Builder()
.url("https://speed.hetzner.de/1GB.bin")
.addHeader("httpClient","Okhttp3")
.addHeader("CustomAttribute","OutOfMemoryAPI")
.build();
```

### Kotlin [#kotlin]

```kotlin

val headers = mutableListOf()
headers.add("httpClient")
headers.add("CustomAttribute")
NewRelic.addHTTPHeadersTrackingFor(headers).
val client = OkHttpClient().newBuilder()
.addInterceptor(new MyInterceptor())
.cache(cache)
.build()


val request: Request = Builder()
.url("https://speed.hetzner.de/1GB.bin")
.addHeader("httpClient", "Okhttp3")
.addHeader("CustomAttribute", "OutOfMemoryAPI")
.build()
```

</TabsPageItem>
<TabsPageItem id="ios">

## Syntax [#syntax]

### Objective-c

```objectivec
(void)addHTTPHeaderTrackingFor:(NSArray<NSString*>*_Nonnull)headers;
```

### Swift [#swift]

```swift
func addHTTPHeaderTracking(for: [String])
```

## Description [#description]

This API allows you to add any header field strings to a list that gets recorded as attributes with networking request events. After header fields have been added using this function, if the headers are in a network call they will be included in networking events in NR1.
The iOS agent currently automatically captures the following header fields: X-APOLLO-OPERATION-NAME, X-APOLLO-OPERATION-TYPE, and X-APOLLO-OPERATION-ID.

## Parameters [#parameters]

<table>
<thead>
<tr>
<th width="30%">
Parameter
</th>

<th width={200}>
Type
</th>
<th>
Description
</th>
</tr>
</thead>

<tbody>
<tr>
<td>
`headers`
</td>

<td>
`NSArray<NSString*>*_Nonnull`
</td>

<td>
Required. The HTTP header fields to be added.
</td>
</tr>

</tbody>
</table>


## Examples [#examples]

Here's an example of adding some HTTP header fields:

```objectivec
[NewRelic addHTTPHeadersTrackingFor:@[@"Example", @"Example2"]];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.newrelic.com"]];
NSMutableURLRequest *mutableRequest = [request mutableCopy];
[mutableRequest addValue:@"Test" forHTTPHeaderField:@"Example"];
[mutableRequest addValue:@"Test2" forHTTPHeaderField:@"Example2"];
request = [mutableRequest copy];
[[NSURLSession sharedSession] dataTaskWithRequest:request];
```
```swift
NewRelic.addHTTPHeadersTracking(for:["Example", "Example2"])
var request = URLRequest(url: URL(string:"https://www.newrelic.com")!)
request.addValue("Test", forHTTPHeaderField: "Example")
request.addValue("Test2", forHTTPHeaderField: "Example2")
URLSession.shared.dataTask(with: request)
```

</TabsPageItem>
</TabsPages>
</Tabs>

58 changes: 58 additions & 0 deletions src/data/attribute-dictionary.json
Original file line number Diff line number Diff line change
Expand Up @@ -9120,6 +9120,35 @@
"name": "newRelicVersion",
"units": null
},
{
"definition": "<p>The X-APOLLO-OPERATION-ID value of an Apollo GraphQL network request.</p>\n",
"events": [
"MobileRequest",
"MobileRequestError"
],
"name": "operationId",
"units": {
"label": "ID"
}
},
{
"definition": "<p>The X-APOLLO-OPERATION-NAME value of an Apollo GraphQL network request.</p>\n",
"events": [
"MobileRequest",
"MobileRequestError"
],
"name": "operationName",
"units": null
},
{
"definition": "<p>The X-APOLLO-OPERATION-TYPE value of an Apollo GraphQL network request.</p>\n",
"events": [
"MobileRequest",
"MobileRequestError"
],
"name": "operationType",
"units": null
},
{
"definition": "<p>The simplified version number of the app&#39;s host operating system, such as iOS 11, as compared to iOS 11.0.4.</p>\n",
"events": [
Expand Down Expand Up @@ -9722,6 +9751,35 @@
"name": "osMajorVersion",
"units": null
},
{
"definition": "<p>The X-APOLLO-OPERATION-ID value of an Apollo GraphQL network request.</p>\n",
"events": [
"MobileRequest",
"MobileRequestError"
],
"name": "operationId",
"units": {
"label": "ID"
}
},
{
"definition": "<p>The X-APOLLO-OPERATION-NAME value of an Apollo GraphQL network request.</p>\n",
"events": [
"MobileRequest",
"MobileRequestError"
],
"name": "operationName",
"units": null
},
{
"definition": "<p>The X-APOLLO-OPERATION-TYPE value of an Apollo GraphQL network request.</p>\n",
"events": [
"MobileRequest",
"MobileRequestError"
],
"name": "operationType",
"units": null
},
{
"definition": "<p>The name of the app&#39;s host operating system, for example, iOS or Android.</p>\n",
"events": [
Expand Down
2 changes: 2 additions & 0 deletions src/nav/mobile-monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ pages:
path: /docs/mobile-monitoring/new-relic-mobile/mobile-sdk/network-request-success
- title: Track failing HTTP requests
path: /docs/mobile-monitoring/new-relic-mobile/mobile-sdk/network-request-failures
- title: Track HTTP requests headers
path: /docs/mobile-monitoring/new-relic-mobile/mobile-sdk/add-tracked-headers
- title: (Android only) Set app launch time target activity
path: /docs/mobile-monitoring/new-relic-mobile/mobile-sdk/name-android-activity
- title: Best practices
Expand Down

0 comments on commit 22f5a63

Please sign in to comment.