Skip to content

Commit 682db01

Browse files
author
Ignacio Bonafonte
committed
DatadogExporter: Add us3 endpoint
1 parent 79a7ff7 commit 682db01

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

Examples/Datadog Sample/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Foundation
88
import OpenTelemetryApi
99
import OpenTelemetrySdk
1010

11-
let clientKey = ""
11+
let clientToken = ""
1212
let apikey = ""
1313

1414
let sampleKey = "sampleKey"
@@ -27,7 +27,7 @@ let exporterConfiguration = ExporterConfiguration(
2727
applicationName: "SwiftDatadogSample",
2828
applicationVersion: "1.0.0",
2929
environment: "test",
30-
clientToken: clientKey,
30+
clientToken: clientToken,
3131
apiKey: apikey,
3232
endpoint: Endpoint.us,
3333
uploadCondition: { true },

Sources/Exporters/DatadogExporter/Upload/DatadogEndpoints.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public enum Endpoint {
99
/// US based servers.
1010
/// Sends logs to [app.datadoghq.com](https://app.datadoghq.com/).
1111
case us
12+
/// US3 based servers.
13+
/// Sends logs to [us3.datadoghq.com](https://us3.datadoghq.com/).
14+
case us3
1215
/// Europe based servers.
1316
/// Sends logs to [app.datadoghq.eu](https://app.datadoghq.eu/).
1417
case eu
@@ -21,6 +24,7 @@ public enum Endpoint {
2124
internal var logsURL: URL {
2225
switch self {
2326
case .us: return URL(string: "https://mobile-http-intake.logs.datadoghq.com/v1/input/")!
27+
case .us3: return URL(string: "https://logs.browser-intake-us3-datadoghq.com/v1/input/")!
2428
case .eu: return URL(string: "https://mobile-http-intake.logs.datadoghq.eu/v1/input/")!
2529
case .gov: return URL(string: "https://logs.browser-intake-ddog-gov.com/v1/input/")!
2630
case let .custom(_, logsURL: logsUrl, _): return logsUrl
@@ -30,6 +34,7 @@ public enum Endpoint {
3034
internal var tracesURL: URL {
3135
switch self {
3236
case .us: return URL(string: "https://public-trace-http-intake.logs.datadoghq.com/v1/input/")!
37+
case .us3: return URL(string: "https://trace.browser-intake-us3-datadoghq.com/v1/input/")!
3338
case .eu: return URL(string: "https://public-trace-http-intake.logs.datadoghq.eu/v1/input/")!
3439
case .gov: return URL(string: "https://trace.browser-intake-ddog-gov.com/v1/input/")!
3540
case let .custom(tracesURL: tracesUrl, _, _): return tracesUrl
@@ -39,6 +44,7 @@ public enum Endpoint {
3944
internal var metricsURL: URL {
4045
switch self {
4146
case .us: return URL(string: "https://api.datadoghq.com/api/v1/series/")!
47+
case .us3: return URL(string: "https://api.us3.datadoghq.com/api/v1/series/")!
4248
case .eu: return URL(string: "https://api.datadoghq.eu/api/v1/series/")!
4349
case .gov: return URL(string: "https://api.ddog-gov.com/api/v1/series/")!
4450
case let .custom(_, _, metricsURL: metricsURL): return metricsURL

Tests/ExportersTests/DatadogExporter/Upload/DatadogEndpointsTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ class DatadogEndpointsTests: XCTestCase {
2525
XCTAssertEqual(logsURL.absoluteString, "https://mobile-http-intake.logs.datadoghq.com/v1/input/abcdef123456789")
2626
}
2727

28+
func testWhenAsksUS3LogEndpointsWithClientToken_returnsCorrectly() throws {
29+
let endpoint = Endpoint.us3
30+
let clientToken = "abcdef123456789"
31+
32+
let logsURL = try endpoint.logsUrlWithClientToken(clientToken: clientToken)
33+
34+
XCTAssertEqual(logsURL, endpoint.logsURL.appendingPathComponent(clientToken))
35+
XCTAssertEqual(logsURL.absoluteString, "https://logs.browser-intake-us3-datadoghq.com/v1/input/abcdef123456789")
36+
}
37+
38+
2839
func testWhenAsksEULogEndpointsWithClientToken_returnsCorrectly() throws {
2940
let endpoint = Endpoint.eu
3041
let clientToken = "abcdef123456789"
@@ -62,6 +73,16 @@ class DatadogEndpointsTests: XCTestCase {
6273
XCTAssertEqual(logsURL.absoluteString, "https://public-trace-http-intake.logs.datadoghq.com/v1/input/abcdef123456789")
6374
}
6475

76+
func testWhenAsksUS3TracesEndpointsWithClientToken_returnsCorrectly() throws {
77+
let endpoint = Endpoint.us3
78+
let clientToken = "abcdef123456789"
79+
80+
let logsURL = try endpoint.tracesUrlWithClientToken(clientToken: clientToken)
81+
82+
XCTAssertEqual(logsURL, endpoint.tracesURL.appendingPathComponent(clientToken))
83+
XCTAssertEqual(logsURL.absoluteString, "https://trace.browser-intake-us3-datadoghq.com/v1/input/abcdef123456789")
84+
}
85+
6586
func testWhenAsksEUTracesEndpointsWithClientToken_returnsCorrectly() throws {
6687
let endpoint = Endpoint.eu
6788
let clientToken = "abcdef123456789"

0 commit comments

Comments
 (0)