Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ The configuration follows this JSON schema:
| appMonitorId | String | Yes | Unique identifier for the RUM App Monitor |
| overrideEndpoint | Object | No | Optional endpoint overrides for the RUM service |
| debug | Boolean | No | Flag to enable debug logging (defaults to false) |
| 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 |

#### ApplicationConfig

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,15 @@ public class AwsOpenTelemetryRumBuilder {
* @return A resource with AWS RUM attributes
*/
private static func buildResource(config: AwsOpenTelemetryConfig) -> Resource {
let rumResourceAttributes: [String: String] = [
var rumResourceAttributes: [String: String] = [
AwsRumConstants.AWS_REGION: config.rum.region,
AwsRumConstants.RUM_APP_MONITOR_ID: config.rum.appMonitorId
]

if config.rum.alias?.isEmpty == false {
rumResourceAttributes[AwsRumConstants.RUM_ALIAS] = config.rum.alias!
}

let resource = DefaultResources().get()
.merging(other: Resource(attributes: buildAttributeMap(rumResourceAttributes)))

Expand Down
3 changes: 3 additions & 0 deletions Sources/AwsOpenTelemetryCore/AwsRumConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ public enum AwsRumConstants {

/// Attribute key for the RUM App Monitor ID
public static let RUM_APP_MONITOR_ID = "awsRumAppMonitorId"

/// Attribute key for the RUM alias
public static let RUM_ALIAS = "awsRumAlias"
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ import Foundation
/// Flag to enable debug logging for SDK integration
public var debug: Bool?

/// Optional alias to add to all requests to compare against the rum:alias
/// in appmonitors with resource based policies
public var alias: String?

/**
* Initializes a new RUM configuration instance.
*
Expand All @@ -75,11 +79,12 @@ import Foundation
* @param overrideEndpoint Optional endpoint overrides for the RUM service
* @param debug Flag to enable debug logging (defaults to false)
*/
@objc public init(region: String, appMonitorId: String, overrideEndpoint: EndpointOverrides? = nil, debug: Bool = false) {
@objc public init(region: String, appMonitorId: String, overrideEndpoint: EndpointOverrides? = nil, debug: Bool = false, alias: String? = nil) {
self.region = region
self.appMonitorId = appMonitorId
self.overrideEndpoint = overrideEndpoint
self.debug = debug
self.alias = alias
super.init()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class AwsOpenTelemetryConfigTests: XCTestCase {
let tracesOnlyEndpoint = "https://traces-only.example.com"
let debug = true
let defaultVersion = "1.0.0"
let alias = "test-alias"

func testConfigInitialization() {
// Test basic initialization
Expand All @@ -25,6 +26,7 @@ final class AwsOpenTelemetryConfigTests: XCTestCase {
XCTAssertEqual(config.rum.region, region)
XCTAssertEqual(config.rum.appMonitorId, appMonitorId)
XCTAssertNil(config.rum.overrideEndpoint)
XCTAssertNil(config.rum.alias)
XCTAssertEqual(config.rum.debug, false)
XCTAssertEqual(config.application.applicationVersion, appVersion)
}
Expand All @@ -42,7 +44,8 @@ final class AwsOpenTelemetryConfigTests: XCTestCase {
region: region,
appMonitorId: appMonitorId,
overrideEndpoint: endpointOverrides,
debug: debug
debug: debug,
alias: alias
),
application: ApplicationConfig(applicationVersion: appVersion)
)
Expand All @@ -51,8 +54,10 @@ final class AwsOpenTelemetryConfigTests: XCTestCase {
XCTAssertEqual(config.rum.region, region)
XCTAssertEqual(config.rum.appMonitorId, appMonitorId)
XCTAssertNotNil(config.rum.overrideEndpoint)
XCTAssertNotNil(config.rum.alias)
XCTAssertEqual(config.rum.overrideEndpoint?.logs, logsEndpoint)
XCTAssertEqual(config.rum.overrideEndpoint?.traces, tracesEndpoint)
XCTAssertEqual(config.rum.alias, alias)
XCTAssertEqual(config.rum.debug, debug)
XCTAssertEqual(config.application.applicationVersion, appVersion)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ final class AwsRumConfigReaderTests: XCTestCase {
let appVersion = "1.2.3"
let logsEndpoint = "https://logs.example.com"
let tracesEndpoint = "https://traces.example.com"
let alias = "test-alias"

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

func testParseConfigWithAlias() throws {
// Create a valid JSON configuration
let jsonString = """
{
"version": "\(version)",
"rum": {
"region": "\(region)",
"appMonitorId": "\(appMonitorId)",
"alias": "\(alias)"
},
"application": {
"applicationVersion": "\(appVersion)"
}
}
"""

let data = jsonString.data(using: .utf8)!

// Parse the configuration
let config = try AwsRumConfigReader.parseConfig(from: data)

// Verify the alias
XCTAssertEqual(config.rum.alias, alias)
}

func testParseInvalidJson() {
// Define test value
let invalidJson = "{ this is not valid JSON }"
Expand Down
Loading