Skip to content

Commit

Permalink
Merge pull request #223 from open-telemetry/revert-datadog-payload-co…
Browse files Browse the repository at this point in the history
…mpression

Revert "Datadog Exporter: Set gzip compression for traces and logs up loads"
  • Loading branch information
Ignacio Bonafonte authored Aug 13, 2021
2 parents 62c9ced + e9a8684 commit 13ecada
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 36 deletions.
3 changes: 1 addition & 2 deletions Sources/Exporters/DatadogExporter/Logs/LogsExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ internal class LogsExporter {
appName: configuration.applicationName,
appVersion: configuration.version,
device: Device.current
),
.compressedContentEncodingHeader()
)
])

logsUpload = FeatureUpload(featureName: "logsUpload",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ internal class MetricsExporter {
appVersion: configuration.version,
device: Device.current
),
// metrics endpoint doesnt accept gzipped content
//.compressedContentEncodingHeader()
])

metricsUpload = FeatureUpload(featureName: "metricsUpload",
Expand Down
3 changes: 1 addition & 2 deletions Sources/Exporters/DatadogExporter/Spans/SpansExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ internal class SpansExporter {
appName: configuration.applicationName,
appVersion: configuration.version,
device: Device.current
),
.compressedContentEncodingHeader()
)
])

tracesUpload = FeatureUpload(featureName: "tracesUpload",
Expand Down
27 changes: 1 addition & 26 deletions Sources/Exporters/DatadogExporter/Upload/DataUploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import Compression
import Foundation

/// Creates URL and adds query items before providing them
Expand Down Expand Up @@ -108,33 +107,9 @@ internal final class DataUploader {
var request = URLRequest(url: urlProvider.url)
request.httpMethod = "POST"
request.allHTTPHeaderFields = httpHeaders.all
request.httpBody = httpHeaders.all["Content-Encoding"] != nil ? compressData(data: data) : data
request.httpBody = data
return request
}

private func compressData(data: Data) -> Data {
let destinationBuffer = UnsafeMutablePointer<UInt8>.allocate(capacity: data.count + 10)
var compressedSize: Int = 0
data.withUnsafeBytes { (source: UnsafeRawBufferPointer) in
// Set gzip header
destinationBuffer[0] = 31
destinationBuffer[1] = 139
destinationBuffer[2] = 8
destinationBuffer[3] = 0
destinationBuffer[4] = 0
destinationBuffer[5] = 0
destinationBuffer[6] = 0
destinationBuffer[7] = 0
destinationBuffer[8] = 0
destinationBuffer[9] = 0
// Actually compress the buffer
compressedSize = compression_encode_buffer(destinationBuffer.advanced(by: 10), data.count,
source.bindMemory(to: UInt8.self).baseAddress!, data.count,
nil,
COMPRESSION_ZLIB)
}
return Data(bytesNoCopy: destinationBuffer, count: compressedSize + 2, deallocator: .free)
}
}

internal enum DataUploadStatus: Equatable, Hashable {
Expand Down
4 changes: 0 additions & 4 deletions Sources/Exporters/DatadogExporter/Upload/HTTPHeaders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ internal struct HTTPHeaders {
return HTTPHeader(field: "Content-Type", value: contentType.rawValue)
}

static func compressedContentEncodingHeader() -> HTTPHeader {
return HTTPHeader( field: "Content-Encoding", value: "gzip")
}

static func userAgentHeader(appName: String, appVersion: String, device: Device) -> HTTPHeader {
return HTTPHeader(
field: "User-Agent",
Expand Down

0 comments on commit 13ecada

Please sign in to comment.