Skip to content

Commit 34a41e3

Browse files
authored
chore: Add alias field to rum config
2 parents 9f8a412 + 6ea093b commit 34a41e3

File tree

6 files changed

+47
-3
lines changed

6 files changed

+47
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ The configuration follows this JSON schema:
125125
| appMonitorId | String | Yes | Unique identifier for the RUM App Monitor |
126126
| overrideEndpoint | Object | No | Optional endpoint overrides for the RUM service |
127127
| debug | Boolean | No | Flag to enable debug logging (defaults to false) |
128+
| alias | String | No | Adds an alias to all requests. It will be compared to the rum:alias service context key in the resource based policy attached to a RUM app monitor |
128129

129130
#### ApplicationConfig
130131

Sources/AwsOpenTelemetryCore/AwsOpenTelemetryRumBuilder.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,15 @@ public class AwsOpenTelemetryRumBuilder {
212212
* @return A resource with AWS RUM attributes
213213
*/
214214
private static func buildResource(config: AwsOpenTelemetryConfig) -> Resource {
215-
let rumResourceAttributes: [String: String] = [
215+
var rumResourceAttributes: [String: String] = [
216216
AwsRumConstants.AWS_REGION: config.rum.region,
217217
AwsRumConstants.RUM_APP_MONITOR_ID: config.rum.appMonitorId
218218
]
219219

220+
if config.rum.alias?.isEmpty == false {
221+
rumResourceAttributes[AwsRumConstants.RUM_ALIAS] = config.rum.alias!
222+
}
223+
220224
let resource = DefaultResources().get()
221225
.merging(other: Resource(attributes: buildAttributeMap(rumResourceAttributes)))
222226

Sources/AwsOpenTelemetryCore/AwsRumConstants.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ public enum AwsRumConstants {
2727

2828
/// Attribute key for the RUM App Monitor ID
2929
public static let RUM_APP_MONITOR_ID = "awsRumAppMonitorId"
30+
31+
/// Attribute key for the RUM alias
32+
public static let RUM_ALIAS = "awsRumAlias"
3033
}

Sources/AwsOpenTelemetryCore/Configuration/AwsOpenTelemetryConfig.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ import Foundation
6767
/// Flag to enable debug logging for SDK integration
6868
public var debug: Bool?
6969

70+
/// Optional alias to add to all requests to compare against the rum:alias
71+
/// in appmonitors with resource based policies
72+
public var alias: String?
73+
7074
/**
7175
* Initializes a new RUM configuration instance.
7276
*
@@ -75,11 +79,12 @@ import Foundation
7579
* @param overrideEndpoint Optional endpoint overrides for the RUM service
7680
* @param debug Flag to enable debug logging (defaults to false)
7781
*/
78-
@objc public init(region: String, appMonitorId: String, overrideEndpoint: EndpointOverrides? = nil, debug: Bool = false) {
82+
@objc public init(region: String, appMonitorId: String, overrideEndpoint: EndpointOverrides? = nil, debug: Bool = false, alias: String? = nil) {
7983
self.region = region
8084
self.appMonitorId = appMonitorId
8185
self.overrideEndpoint = overrideEndpoint
8286
self.debug = debug
87+
self.alias = alias
8388
super.init()
8489
}
8590
}

Tests/AwsOpenTelemetryTests/Configuration/AwsOpenTelemetryConfigTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ final class AwsOpenTelemetryConfigTests: XCTestCase {
1212
let tracesOnlyEndpoint = "https://traces-only.example.com"
1313
let debug = true
1414
let defaultVersion = "1.0.0"
15+
let alias = "test-alias"
1516

1617
func testConfigInitialization() {
1718
// Test basic initialization
@@ -25,6 +26,7 @@ final class AwsOpenTelemetryConfigTests: XCTestCase {
2526
XCTAssertEqual(config.rum.region, region)
2627
XCTAssertEqual(config.rum.appMonitorId, appMonitorId)
2728
XCTAssertNil(config.rum.overrideEndpoint)
29+
XCTAssertNil(config.rum.alias)
2830
XCTAssertEqual(config.rum.debug, false)
2931
XCTAssertEqual(config.application.applicationVersion, appVersion)
3032
}
@@ -42,7 +44,8 @@ final class AwsOpenTelemetryConfigTests: XCTestCase {
4244
region: region,
4345
appMonitorId: appMonitorId,
4446
overrideEndpoint: endpointOverrides,
45-
debug: debug
47+
debug: debug,
48+
alias: alias
4649
),
4750
application: ApplicationConfig(applicationVersion: appVersion)
4851
)
@@ -51,8 +54,10 @@ final class AwsOpenTelemetryConfigTests: XCTestCase {
5154
XCTAssertEqual(config.rum.region, region)
5255
XCTAssertEqual(config.rum.appMonitorId, appMonitorId)
5356
XCTAssertNotNil(config.rum.overrideEndpoint)
57+
XCTAssertNotNil(config.rum.alias)
5458
XCTAssertEqual(config.rum.overrideEndpoint?.logs, logsEndpoint)
5559
XCTAssertEqual(config.rum.overrideEndpoint?.traces, tracesEndpoint)
60+
XCTAssertEqual(config.rum.alias, alias)
5661
XCTAssertEqual(config.rum.debug, debug)
5762
XCTAssertEqual(config.application.applicationVersion, appVersion)
5863
}

Tests/AwsOpenTelemetryTests/Configuration/AwsRumConfigReaderTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ final class AwsRumConfigReaderTests: XCTestCase {
99
let appVersion = "1.2.3"
1010
let logsEndpoint = "https://logs.example.com"
1111
let tracesEndpoint = "https://traces.example.com"
12+
let alias = "test-alias"
1213

1314
func testParseValidConfig() throws {
1415
// Create a valid JSON configuration
@@ -68,6 +69,31 @@ final class AwsRumConfigReaderTests: XCTestCase {
6869
XCTAssertEqual(config.rum.overrideEndpoint?.traces, tracesEndpoint)
6970
}
7071

72+
func testParseConfigWithAlias() throws {
73+
// Create a valid JSON configuration
74+
let jsonString = """
75+
{
76+
"version": "\(version)",
77+
"rum": {
78+
"region": "\(region)",
79+
"appMonitorId": "\(appMonitorId)",
80+
"alias": "\(alias)"
81+
},
82+
"application": {
83+
"applicationVersion": "\(appVersion)"
84+
}
85+
}
86+
"""
87+
88+
let data = jsonString.data(using: .utf8)!
89+
90+
// Parse the configuration
91+
let config = try AwsRumConfigReader.parseConfig(from: data)
92+
93+
// Verify the alias
94+
XCTAssertEqual(config.rum.alias, alias)
95+
}
96+
7197
func testParseInvalidJson() {
7298
// Define test value
7399
let invalidJson = "{ this is not valid JSON }"

0 commit comments

Comments
 (0)