Skip to content

Commit

Permalink
Merge pull request #107 from DataDog/ncreated/RUMM-409-merge-master-t…
Browse files Browse the repository at this point in the history
…o-tracing

RUMM-409 Update tracing with `service`, `env` and `version`
  • Loading branch information
ncreated authored May 14, 2020
2 parents c0c4b74 + e88f126 commit ba8b4c0
Show file tree
Hide file tree
Showing 54 changed files with 994 additions and 846 deletions.
20 changes: 12 additions & 8 deletions Datadog/Datadog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
61133C4C2423990D00786299 /* LogsMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C1A2423990D00786299 /* LogsMocks.swift */; };
61133C4D2423990D00786299 /* CoreTelephonyMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C1B2423990D00786299 /* CoreTelephonyMocks.swift */; };
61133C4E2423990D00786299 /* UIKitMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C1C2423990D00786299 /* UIKitMocks.swift */; };
61133C4F2423990D00786299 /* DatadogObjcMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C1D2423990D00786299 /* DatadogObjcMocks.swift */; };
61133C512423990D00786299 /* DatadogMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C1F2423990D00786299 /* DatadogMocks.swift */; };
61133C522423990D00786299 /* FoundationMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C202423990D00786299 /* FoundationMocks.swift */; };
61133C532423990D00786299 /* MobileDeviceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C232423990D00786299 /* MobileDeviceTests.swift */; };
Expand Down Expand Up @@ -117,11 +116,12 @@
61441C982461A649003D8BB8 /* DebugTracingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61441C932461A649003D8BB8 /* DebugTracingViewController.swift */; };
61441C992461A649003D8BB8 /* DebugLoggingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61441C942461A649003D8BB8 /* DebugLoggingViewController.swift */; };
61441C9D2461A796003D8BB8 /* AppConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61441C9C2461A796003D8BB8 /* AppConfig.swift */; };
614E9EB3244719FA007EE3E1 /* Environment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 614E9EB2244719FA007EE3E1 /* Environment.swift */; };
614E9EB3244719FA007EE3E1 /* BundleType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 614E9EB2244719FA007EE3E1 /* BundleType.swift */; };
617CEB392456BC3A00AD4669 /* TracingUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617CEB382456BC3A00AD4669 /* TracingUUID.swift */; };
61AD4E182451C7FF006E34EA /* TracingFeatureMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61AD4E172451C7FF006E34EA /* TracingFeatureMocks.swift */; };
61AD4E3824531500006E34EA /* DataFormat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61AD4E3724531500006E34EA /* DataFormat.swift */; };
61AD4E3A24534075006E34EA /* TracingFeatureTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61AD4E3924534075006E34EA /* TracingFeatureTests.swift */; };
61B558CF2469561C001460D3 /* LoggerBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61B558CE2469561C001460D3 /* LoggerBuilderTests.swift */; };
61B558D42469CDD8001460D3 /* TracingUUIDGeneratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61B558D32469CDD8001460D3 /* TracingUUIDGeneratorTests.swift */; };
61B9ED1C2461E12000C0DCFF /* SendLogsFixtureViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61B9ED1A2461E12000C0DCFF /* SendLogsFixtureViewController.swift */; };
61B9ED1D2461E12000C0DCFF /* SendTracesFixtureViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61B9ED1B2461E12000C0DCFF /* SendTracesFixtureViewController.swift */; };
Expand Down Expand Up @@ -163,6 +163,7 @@
61E917CF2464270500E6C631 /* EncodableValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E917CE2464270500E6C631 /* EncodableValueTests.swift */; };
61E917D12465423600E6C631 /* DDTracerConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E917D02465423600E6C631 /* DDTracerConfiguration.swift */; };
61E917D3246546BF00E6C631 /* DDTracerConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E917D2246546BF00E6C631 /* DDTracerConfigurationTests.swift */; };
61F8CC092469295500FE2908 /* DatadogConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61F8CC082469295500FE2908 /* DatadogConfigurationTests.swift */; };
61FB222D244A21ED00902D19 /* LoggingFeatureMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61FB222C244A21ED00902D19 /* LoggingFeatureMocks.swift */; };
61FB2230244E1BE900902D19 /* LoggingFeatureTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61FB222F244E1BE900902D19 /* LoggingFeatureTests.swift */; };
9E08587A242519FF001A3583 /* NetworkPathMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E085879242519FF001A3583 /* NetworkPathMonitor.swift */; };
Expand Down Expand Up @@ -337,7 +338,6 @@
61133C1A2423990D00786299 /* LogsMocks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogsMocks.swift; sourceTree = "<group>"; };
61133C1B2423990D00786299 /* CoreTelephonyMocks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreTelephonyMocks.swift; sourceTree = "<group>"; };
61133C1C2423990D00786299 /* UIKitMocks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIKitMocks.swift; sourceTree = "<group>"; };
61133C1D2423990D00786299 /* DatadogObjcMocks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatadogObjcMocks.swift; sourceTree = "<group>"; };
61133C1F2423990D00786299 /* DatadogMocks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatadogMocks.swift; sourceTree = "<group>"; };
61133C202423990D00786299 /* FoundationMocks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationMocks.swift; sourceTree = "<group>"; };
61133C232423990D00786299 /* MobileDeviceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MobileDeviceTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -388,13 +388,14 @@
61441C932461A649003D8BB8 /* DebugTracingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DebugTracingViewController.swift; sourceTree = "<group>"; };
61441C942461A649003D8BB8 /* DebugLoggingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DebugLoggingViewController.swift; sourceTree = "<group>"; };
61441C9C2461A796003D8BB8 /* AppConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppConfig.swift; sourceTree = "<group>"; };
614E9EB2244719FA007EE3E1 /* Environment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Environment.swift; sourceTree = "<group>"; };
614E9EB2244719FA007EE3E1 /* BundleType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundleType.swift; sourceTree = "<group>"; };
615519252461BCE7002A85CF /* Datadog.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Datadog.xcconfig; sourceTree = "<group>"; };
615519262461BCE7002A85CF /* Datadog.local.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Datadog.local.xcconfig; sourceTree = "<group>"; };
617CEB382456BC3A00AD4669 /* TracingUUID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TracingUUID.swift; sourceTree = "<group>"; };
61AD4E172451C7FF006E34EA /* TracingFeatureMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TracingFeatureMocks.swift; sourceTree = "<group>"; };
61AD4E3724531500006E34EA /* DataFormat.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataFormat.swift; sourceTree = "<group>"; };
61AD4E3924534075006E34EA /* TracingFeatureTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TracingFeatureTests.swift; sourceTree = "<group>"; };
61B558CE2469561C001460D3 /* LoggerBuilderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggerBuilderTests.swift; sourceTree = "<group>"; };
61B558D32469CDD8001460D3 /* TracingUUIDGeneratorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TracingUUIDGeneratorTests.swift; sourceTree = "<group>"; };
61B9ED1A2461E12000C0DCFF /* SendLogsFixtureViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendLogsFixtureViewController.swift; sourceTree = "<group>"; };
61B9ED1B2461E12000C0DCFF /* SendTracesFixtureViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendTracesFixtureViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -434,6 +435,7 @@
61E917CE2464270500E6C631 /* EncodableValueTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncodableValueTests.swift; sourceTree = "<group>"; };
61E917D02465423600E6C631 /* DDTracerConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DDTracerConfiguration.swift; sourceTree = "<group>"; };
61E917D2246546BF00E6C631 /* DDTracerConfigurationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DDTracerConfigurationTests.swift; sourceTree = "<group>"; };
61F8CC082469295500FE2908 /* DatadogConfigurationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatadogConfigurationTests.swift; sourceTree = "<group>"; };
61FB222C244A21ED00902D19 /* LoggingFeatureMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggingFeatureMocks.swift; sourceTree = "<group>"; };
61FB222F244E1BE900902D19 /* LoggingFeatureTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggingFeatureTests.swift; sourceTree = "<group>"; };
9E085879242519FF001A3583 /* NetworkPathMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkPathMonitor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -569,7 +571,7 @@
61133B9E2423979B00786299 /* Core */ = {
isa = PBXGroup;
children = (
614E9EB2244719FA007EE3E1 /* Environment.swift */,
614E9EB2244719FA007EE3E1 /* BundleType.swift */,
61BB2B1A244A185D009F3F56 /* PerformancePreset.swift */,
61133B9F2423979B00786299 /* Utils */,
61133BA12423979B00786299 /* System */,
Expand Down Expand Up @@ -759,9 +761,11 @@
children = (
61133C192423990D00786299 /* Mocks */,
61133C412423990D00786299 /* DatadogTests.swift */,
61F8CC082469295500FE2908 /* DatadogConfigurationTests.swift */,
61133C382423990D00786299 /* LoggerTests.swift */,
61C5A89524509BF600DA608C /* DDTracerTests.swift */,
61E917D2246546BF00E6C631 /* DDTracerConfigurationTests.swift */,
61B558CE2469561C001460D3 /* LoggerBuilderTests.swift */,
61133C212423990D00786299 /* Core */,
61133C392423990D00786299 /* Logs */,
61C5A89724509C1100DA608C /* Tracing */,
Expand All @@ -777,7 +781,6 @@
61C5A89124509BD700DA608C /* SpansMocks.swift */,
61133C1B2423990D00786299 /* CoreTelephonyMocks.swift */,
61133C1C2423990D00786299 /* UIKitMocks.swift */,
61133C1D2423990D00786299 /* DatadogObjcMocks.swift */,
61133C1F2423990D00786299 /* DatadogMocks.swift */,
61C5A89224509BD700DA608C /* DatadogTracingMocks.swift */,
61C3638224361BE200C4D4E6 /* DatadogPrivateMocks.swift */,
Expand Down Expand Up @@ -1494,7 +1497,7 @@
61C5A88424509A0C00DA608C /* DDSpan.swift in Sources */,
61133BD82423979B00786299 /* HTTPClient.swift in Sources */,
61133BDB2423979B00786299 /* DatadogConfiguration.swift in Sources */,
614E9EB3244719FA007EE3E1 /* Environment.swift in Sources */,
614E9EB3244719FA007EE3E1 /* BundleType.swift in Sources */,
61133BCE2423979B00786299 /* BatteryStatusProvider.swift in Sources */,
61133BD52423979B00786299 /* DataUploadConditions.swift in Sources */,
612983CD2449E62E00D4424B /* LoggingFeature.swift in Sources */,
Expand Down Expand Up @@ -1533,6 +1536,7 @@
61E917CF2464270500E6C631 /* EncodableValueTests.swift in Sources */,
61133C4C2423990D00786299 /* LogsMocks.swift in Sources */,
61133C542423990D00786299 /* NetworkConnectionInfoProviderTests.swift in Sources */,
61B558CF2469561C001460D3 /* LoggerBuilderTests.swift in Sources */,
61133C4A2423990D00786299 /* DDConfigurationTests.swift in Sources */,
61C5A89F24509C1100DA608C /* UUID.swift in Sources */,
61C363802436164B00C4D4E6 /* ObjcExceptionHandlerTests.swift in Sources */,
Expand All @@ -1559,14 +1563,14 @@
61E45BD22450F65B00F2C652 /* SpanBuilderTests.swift in Sources */,
61E45BCF2450A6EC00F2C652 /* TracingUUIDTests.swift in Sources */,
61133C482423990D00786299 /* DDDatadogTests.swift in Sources */,
61133C4F2423990D00786299 /* DatadogObjcMocks.swift in Sources */,
61133C522423990D00786299 /* FoundationMocks.swift in Sources */,
61133C5B2423990D00786299 /* DirectoryTests.swift in Sources */,
61133C562423990D00786299 /* CarrierInfoProviderTests.swift in Sources */,
61C5A89E24509C1100DA608C /* WarningsTests.swift in Sources */,
9E36D92224373EA700BFBDB7 /* SwiftExtensionsTests.swift in Sources */,
61133C652423990D00786299 /* LogBuilderTests.swift in Sources */,
61C5A89424509BD700DA608C /* DatadogTracingMocks.swift in Sources */,
61F8CC092469295500FE2908 /* DatadogConfigurationTests.swift in Sources */,
61133C642423990D00786299 /* LoggerTests.swift in Sources */,
61E45BE5245196EA00F2C652 /* SpanFileOutputTests.swift in Sources */,
61133C4E2423990D00786299 /* UIKitMocks.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions Datadog/Example/AppConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct ExampleAppConfig: AppConfig {
}

self.datadogConfiguration = Datadog.Configuration
.builderUsing(clientToken: clientToken)
.builderUsing(clientToken: clientToken, environment: "tests")
.build()
}
}
Expand All @@ -44,7 +44,7 @@ struct UITestAppConfig: AppConfig {

init(mockServerURL: String) {
self.datadogConfiguration = Datadog.Configuration
.builderUsing(clientToken: "ui-tests-client-token")
.builderUsing(clientToken: "ui-tests-client-token", environment: "integration")
.set(logsEndpoint: .custom(url: mockServerURL))
.set(tracesEndpoint: .custom(url: mockServerURL))
.build()
Expand Down
7 changes: 5 additions & 2 deletions Shopist/Shopist/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import UIKit
@testable import Datadog // TODO: RUMM-332 Remove `@testable` import after `DDTracer` initializer is `public`
import Datadog
import OpenTracing

fileprivate(set) var logger: Logger!
Expand All @@ -20,7 +20,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
Datadog.initialize(
appContext: .init(),
configuration: Datadog.Configuration
.builderUsing(clientToken: appConfig.clientToken) // use your own client token obtained on Datadog website)
.builderUsing(
clientToken: appConfig.clientToken, // use your own client token obtained on Datadog website
environment: "tests"
)
.build()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import Foundation

/// An environment running the SDK.
internal enum Environment: Equatable {
/// A type of the bundle running the SDK.
internal enum BundleType: String {
case iOSApp
case iOSAppExtension
}
4 changes: 2 additions & 2 deletions Sources/Datadog/Core/PerformancePreset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ internal struct PerformancePreset: Equatable, StoragePerformancePreset, UploadPe
uploadDelayDecreaseFactor: 0.5 // reduce significantly for more uploads in short-lived app extensions
)

static func best(for environment: Environment) -> PerformancePreset {
switch environment {
static func best(for bundleType: BundleType) -> PerformancePreset {
switch bundleType {
case .iOSApp: return `default`
case .iOSAppExtension: return instantDataDelivery
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Datadog/Core/System/MobileDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal class MobileDevice {

/// Returns current mobile device if `UIDevice` is available on this platform.
/// On other platforms returns `nil`.
static var current: MobileDevice? {
static var current: MobileDevice {
#if !targetEnvironment(simulator)
// Real device
return MobileDevice(uiDevice: UIDevice.current, processInfo: ProcessInfo.processInfo)
Expand Down
24 changes: 7 additions & 17 deletions Sources/Datadog/Core/Upload/DataUploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Foundation

/// Creates URL and adds query items before providing them
internal class UploadURLProvider {
private let rawURL: URL
private let urlWithClientToken: URL
private let dateProvider: DateProvider

private var queryItems: [URLQueryItem] {
Expand All @@ -22,29 +22,19 @@ internal class UploadURLProvider {
}

var url: URL {
var urlComponents = URLComponents(url: rawURL, resolvingAgainstBaseURL: false)
var urlComponents = URLComponents(url: urlWithClientToken, resolvingAgainstBaseURL: false)
urlComponents?.percentEncodedQueryItems = queryItems

guard let url = urlComponents?.url else {
userLogger.error("🔥 Failed to create URL from \(rawURL) with \(queryItems)")
developerLogger?.error("🔥 Failed to create URL from \(rawURL) with \(queryItems)")
return rawURL
userLogger.error("🔥 Failed to create URL from \(urlWithClientToken) with \(queryItems)")
developerLogger?.error("🔥 Failed to create URL from \(urlWithClientToken) with \(queryItems)")
return urlWithClientToken
}
return url
}

init(endpointURL: String, clientToken: String, dateProvider: DateProvider) throws {
guard !endpointURL.isEmpty, let endpointURL = URL(string: endpointURL) else {
throw ProgrammerError(description: "`endpointURL` cannot be empty.")
}
guard !clientToken.isEmpty else {
throw ProgrammerError(description: "`clientToken` cannot be empty.")
}
let endpointURLWithClientToken = endpointURL.appendingPathComponent(clientToken)
guard let url = URL(string: endpointURLWithClientToken.absoluteString) else {
throw ProgrammerError(description: "Cannot build logs upload URL.")
}
self.rawURL = url
init(urlWithClientToken: URL, dateProvider: DateProvider) {
self.urlWithClientToken = urlWithClientToken
self.dateProvider = dateProvider
}
}
Expand Down
6 changes: 2 additions & 4 deletions Sources/Datadog/Core/Upload/HTTPHeaders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ internal struct HTTPHeaders {
return HTTPHeader(field: "Content-Type", value: contentType.rawValue)
}

static func userAgentHeader(for mobileDevice: MobileDevice, appName: String?, appVersion: String?) -> HTTPHeader {
let appName = appName ?? "Datadog"
let appVersion = appVersion ?? sdkVersion
static func userAgentHeader(appName: String, appVersion: String, device: MobileDevice) -> HTTPHeader {
return HTTPHeader(
field: "User-Agent",
value: "\(appName)/\(appVersion) CFNetwork (\(mobileDevice.model); \(mobileDevice.osName)/\(mobileDevice.osVersion))"
value: "\(appName)/\(appVersion) CFNetwork (\(device.model); \(device.osName)/\(device.osVersion))"
)
}

Expand Down
Loading

0 comments on commit ba8b4c0

Please sign in to comment.