From 8c22098d78fe57e2870f4d1de3be9287974ff168 Mon Sep 17 00:00:00 2001 From: Maciek Grzybowski Date: Thu, 17 Dec 2020 11:59:47 +0100 Subject: [PATCH] RUMM-833 Add `DatadogSDKAlamofireExtension.podspec` --- DatadogSDKAlamofireExtension.podspec | 24 +++++++++++++++ .../Alamofire/DatadogAlamofireExtension.swift | 29 +++++++++++++++++++ .../cocoapods/Podfile.src | 1 + 3 files changed, 54 insertions(+) create mode 100644 DatadogSDKAlamofireExtension.podspec create mode 100644 Sources/DatadogExtensions/Alamofire/DatadogAlamofireExtension.swift diff --git a/DatadogSDKAlamofireExtension.podspec b/DatadogSDKAlamofireExtension.podspec new file mode 100644 index 0000000000..c90680b385 --- /dev/null +++ b/DatadogSDKAlamofireExtension.podspec @@ -0,0 +1,24 @@ +Pod::Spec.new do |s| + s.name = "DatadogSDKAlamofireExtension" + s.module_name = "DatadogAlamofireExtension" + s.version = "1.0.0" + s.summary = "An Official Extensions of Datadog Swift SDK for Alamofire." + + s.homepage = "https://www.datadoghq.com" + s.social_media_url = "https://twitter.com/datadoghq" + + s.license = { :type => "Apache", :file => 'LICENSE' } + s.authors = { + "Maciek Grzybowski" => "maciek.grzybowski@datadoghq.com", + "Mert Buran" => "mert.buran@datadoghq.com" + } + + s.swift_version = '5.1' + s.ios.deployment_target = '11.0' + + s.source = { :git => "https://github.com/DataDog/dd-sdk-ios.git", :tag => s.version.to_s } + + s.source_files = ["Sources/DatadogExtensions/Alamofire/**/*.swift"] + s.dependency 'DatadogSDK', '~> 1.4' + s.dependency 'Alamofire', '~> 5.4' +end diff --git a/Sources/DatadogExtensions/Alamofire/DatadogAlamofireExtension.swift b/Sources/DatadogExtensions/Alamofire/DatadogAlamofireExtension.swift new file mode 100644 index 0000000000..9907599dd0 --- /dev/null +++ b/Sources/DatadogExtensions/Alamofire/DatadogAlamofireExtension.swift @@ -0,0 +1,29 @@ +/* + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2019-2020 Datadog, Inc. + */ + +import class Datadog.URLSessionInterceptor +import Alamofire + +public class DDEventMonitor: EventMonitor { + public func request(_ request: Request, didCreateTask task: URLSessionTask) { + URLSessionInterceptor.shared?.taskCreated(task: task) + } + + public func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) { + URLSessionInterceptor.shared?.taskMetricsCollected(task: task, metrics: metrics) + } + + public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) { + URLSessionInterceptor.shared?.taskCompleted(task: task, error: error) + } +} + +public class DDRequestInterceptor: RequestInterceptor { + public func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result) -> Void) { + let instrumentedRequest = URLSessionInterceptor.shared?.modify(request: urlRequest) + completion(.success(instrumentedRequest ?? urlRequest)) + } +} diff --git a/dependency-manager-tests/cocoapods/Podfile.src b/dependency-manager-tests/cocoapods/Podfile.src index 1d61c54c59..76e94103b6 100644 --- a/dependency-manager-tests/cocoapods/Podfile.src +++ b/dependency-manager-tests/cocoapods/Podfile.src @@ -3,4 +3,5 @@ platform :ios, '12.0' target 'CPProject' do use_frameworks! pod 'DatadogSDK', :git => 'https://github.com/DataDog/dd-sdk-ios.git', :branch => 'REMOTE_GIT_BRANCH' + pod 'DatadogSDKAlamofireExtension', :git => 'https://github.com/DataDog/dd-sdk-ios.git', :branch => 'REMOTE_GIT_BRANCH' end