-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15068 from mbruin-NR/NR-167603
Added an article on a new mobile agents api for tracking http headers
- Loading branch information
Showing
3 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
206 changes: 206 additions & 0 deletions
206
...tent/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/add-tracked-headers.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters