Skip to content

Commit a85c8c9

Browse files
author
Ignacio Bonafonte
authored
Merge pull request #399 from Sherlouk/separate-http-grpc
Separate OTLP HTTP and GRPC Exporters
2 parents a7004d0 + d1155cc commit a85c8c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+97
-59
lines changed

Examples/OTLP Exporter/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import GRPC
1010
import NIO
1111
import NIOSSL
1212
import OpenTelemetryApi
13-
import OpenTelemetryProtocolExporter
13+
import OpenTelemetryProtocolExporterGrpc
1414
import OpenTelemetrySdk
1515
import ResourceExtension
1616
import SignPostIntegration

Examples/OTLP HTTP Exporter/main.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
#if os(macOS)
77

88
import Foundation
9-
import GRPC
10-
import NIO
11-
import NIOSSL
129
import OpenTelemetryApi
13-
import OpenTelemetryProtocolExporter
10+
import OpenTelemetryProtocolExporterHttp
1411
import OpenTelemetrySdk
1512
import ResourceExtension
1613
import SignPostIntegration

Package.swift

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ let package = Package(
2222
.library(name: "ZipkinExporter", type: .static, targets: ["ZipkinExporter"]),
2323
.library(name: "StdoutExporter", type: .static, targets: ["StdoutExporter"]),
2424
.library(name: "PrometheusExporter", type: .static, targets: ["PrometheusExporter"]),
25-
.library(name: "OpenTelemetryProtocolExporter", type: .static, targets: ["OpenTelemetryProtocolExporter"]),
25+
.library(name: "OpenTelemetryProtocolExporter", type: .static, targets: ["OpenTelemetryProtocolExporterGrpc"]),
26+
.library(name: "OpenTelemetryProtocolExporterHTTP", type: .static, targets: ["OpenTelemetryProtocolExporterHttp"]),
2627
.library(name: "PersistenceExporter", type: .static, targets: ["PersistenceExporter"]),
2728
.library(name: "InMemoryExporter", type: .static, targets: ["InMemoryExporter"]),
2829
.library(name: "DatadogExporter", type: .static, targets: ["DatadogExporter"]),
@@ -37,6 +38,8 @@ let package = Package(
3738
.package(name: "Thrift", url: "https://github.com/undefinedlabs/Thrift-Swift", from: "1.1.1"),
3839
.package(name: "swift-nio", url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
3940
.package(name: "grpc-swift", url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0"),
41+
.package(name: "swift-protobuf", url: "https://github.com/apple/swift-protobuf.git", from: "1.20.2"),
42+
.package(name: "swift-log", url: "https://github.com/apple/swift-log.git", from: "1.4.4"),
4043
.package(name: "swift-metrics", url: "https://github.com/apple/swift-metrics.git", from: "2.1.1"),
4144
.package(name: "Reachability.swift", url: "https://github.com/ashleymills/Reachability.swift", from: "5.1.0")
4245
],
@@ -86,10 +89,20 @@ let package = Package(
8689
.product(name: "NIO", package: "swift-nio"),
8790
.product(name: "NIOHTTP1", package: "swift-nio")],
8891
path: "Sources/Exporters/Prometheus"),
89-
.target(name: "OpenTelemetryProtocolExporter",
92+
.target(name: "OpenTelemetryProtocolExporterCommon",
9093
dependencies: ["OpenTelemetrySdk",
94+
.product(name: "Logging", package: "swift-log"),
95+
.product(name: "SwiftProtobuf", package: "swift-protobuf")],
96+
path: "Sources/Exporters/OpenTelemetryProtocolCommon"),
97+
.target(name: "OpenTelemetryProtocolExporterHttp",
98+
dependencies: ["OpenTelemetrySdk",
99+
"OpenTelemetryProtocolExporterCommon"],
100+
path: "Sources/Exporters/OpenTelemetryProtocolHttp"),
101+
.target(name: "OpenTelemetryProtocolExporterGrpc",
102+
dependencies: ["OpenTelemetrySdk",
103+
"OpenTelemetryProtocolExporterCommon",
91104
.product(name: "GRPC", package: "grpc-swift")],
92-
path: "Sources/Exporters/OpenTelemetryProtocol"),
105+
path: "Sources/Exporters/OpenTelemetryProtocolGrpc"),
93106
.target(name: "StdoutExporter",
94107
dependencies: ["OpenTelemetrySdk"],
95108
path: "Sources/Exporters/Stdout"),
@@ -139,10 +152,11 @@ let package = Package(
139152
dependencies: ["PrometheusExporter"],
140153
path: "Tests/ExportersTests/Prometheus"),
141154
.testTarget(name: "OpenTelemetryProtocolExporterTests",
142-
dependencies: ["OpenTelemetryProtocolExporter",
143-
.product(name: "NIO", package: "swift-nio"),
144-
.product(name: "NIOHTTP1", package: "swift-nio"),
145-
.product(name: "NIOTestUtils", package: "swift-nio")],
155+
dependencies: ["OpenTelemetryProtocolExporterGrpc",
156+
"OpenTelemetryProtocolExporterHttp",
157+
.product(name: "NIO", package: "swift-nio"),
158+
.product(name: "NIOHTTP1", package: "swift-nio"),
159+
.product(name: "NIOTestUtils", package: "swift-nio")],
146160
path: "Tests/ExportersTests/OpenTelemetryProtocol"),
147161
.testTarget(name: "InMemoryExporterTests",
148162
dependencies: ["InMemoryExporter"],
@@ -163,11 +177,11 @@ let package = Package(
163177
path: "Examples/Simple Exporter",
164178
exclude: ["README.md"]),
165179
.target(name: "OTLPExporter",
166-
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporter", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
180+
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporterGrpc", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
167181
path: "Examples/OTLP Exporter",
168182
exclude: ["README.md"]),
169183
.target(name: "OTLPHTTPExporter",
170-
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporter", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
184+
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporterHttp", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
171185
path: "Examples/OTLP HTTP Exporter",
172186
exclude: ["README.md"]),
173187
.target(name: "PrometheusSample",

[email protected]

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ let package = Package(
2323
.library(name: "ZipkinExporter", type: .static, targets: ["ZipkinExporter"]),
2424
.library(name: "StdoutExporter", type: .static, targets: ["StdoutExporter"]),
2525
.library(name: "PrometheusExporter", type: .static, targets: ["PrometheusExporter"]),
26-
.library(name: "OpenTelemetryProtocolExporter", type: .static, targets: ["OpenTelemetryProtocolExporter"]),
26+
.library(name: "OpenTelemetryProtocolExporter", type: .static, targets: ["OpenTelemetryProtocolExporterGrpc"]),
27+
.library(name: "OpenTelemetryProtocolExporterHTTP", type: .static, targets: ["OpenTelemetryProtocolExporterHttp"]),
2728
.library(name: "PersistenceExporter", type: .static, targets: ["PersistenceExporter"]),
2829
.library(name: "InMemoryExporter", type: .static, targets: ["InMemoryExporter"]),
2930
.library(name: "DatadogExporter", type: .static, targets: ["DatadogExporter"]),
@@ -38,6 +39,8 @@ let package = Package(
3839
.package(url: "https://github.com/undefinedlabs/Thrift-Swift", from: "1.1.1"),
3940
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
4041
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0"),
42+
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.20.2"),
43+
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.4"),
4144
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.1.1"),
4245
.package(url: "https://github.com/ashleymills/Reachability.swift", from: "5.1.0")
4346
],
@@ -91,10 +94,20 @@ let package = Package(
9194
.product(name: "NIO", package: "swift-nio"),
9295
.product(name: "NIOHTTP1", package: "swift-nio")],
9396
path: "Sources/Exporters/Prometheus"),
94-
.target(name: "OpenTelemetryProtocolExporter",
97+
.target(name: "OpenTelemetryProtocolExporterCommon",
9598
dependencies: ["OpenTelemetrySdk",
99+
.product(name: "Logging", package: "swift-log"),
100+
.product(name: "SwiftProtobuf", package: "swift-protobuf")],
101+
path: "Sources/Exporters/OpenTelemetryProtocolCommon"),
102+
.target(name: "OpenTelemetryProtocolExporterHttp",
103+
dependencies: ["OpenTelemetrySdk",
104+
"OpenTelemetryProtocolExporterCommon"],
105+
path: "Sources/Exporters/OpenTelemetryProtocolHttp"),
106+
.target(name: "OpenTelemetryProtocolExporterGrpc",
107+
dependencies: ["OpenTelemetrySdk",
108+
"OpenTelemetryProtocolExporterCommon",
96109
.product(name: "GRPC", package: "grpc-swift")],
97-
path: "Sources/Exporters/OpenTelemetryProtocol"),
110+
path: "Sources/Exporters/OpenTelemetryProtocolGrpc"),
98111
.target(name: "StdoutExporter",
99112
dependencies: ["OpenTelemetrySdk"],
100113
path: "Sources/Exporters/Stdout"),
@@ -147,10 +160,11 @@ let package = Package(
147160
dependencies: ["PrometheusExporter"],
148161
path: "Tests/ExportersTests/Prometheus"),
149162
.testTarget(name: "OpenTelemetryProtocolExporterTests",
150-
dependencies: ["OpenTelemetryProtocolExporter",
151-
.product(name: "NIO", package: "swift-nio"),
152-
.product(name: "NIOHTTP1", package: "swift-nio"),
153-
.product(name: "NIOTestUtils", package: "swift-nio")],
163+
dependencies: ["OpenTelemetryProtocolExporterGrpc",
164+
"OpenTelemetryProtocolExporterHttp",
165+
.product(name: "NIO", package: "swift-nio"),
166+
.product(name: "NIOHTTP1", package: "swift-nio"),
167+
.product(name: "NIOTestUtils", package: "swift-nio")],
154168
path: "Tests/ExportersTests/OpenTelemetryProtocol"),
155169
.testTarget(name: "InMemoryExporterTests",
156170
dependencies: ["InMemoryExporter"],
@@ -176,13 +190,13 @@ let package = Package(
176190
),
177191
.executableTarget(
178192
name: "OTLPExporter",
179-
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporter", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
193+
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporterGrpc", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
180194
path: "Examples/OTLP Exporter",
181195
exclude: ["README.md"]
182196
),
183197
.executableTarget(
184198
name: "OTLPHTTPExporter",
185-
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporter", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
199+
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporterHttp", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
186200
path: "Examples/OTLP HTTP Exporter",
187201
exclude: ["README.md"]
188202
),

Sources/Exporters/OpenTelemetryProtocol/common/CommonAdapter.swift renamed to Sources/Exporters/OpenTelemetryProtocolCommon/common/CommonAdapter.swift

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

10-
struct CommonAdapter {
11-
static func toProtoAttribute(key: String, attributeValue: AttributeValue) -> Opentelemetry_Proto_Common_V1_KeyValue {
10+
public struct CommonAdapter {
11+
public static func toProtoAttribute(key: String, attributeValue: AttributeValue) -> Opentelemetry_Proto_Common_V1_KeyValue {
1212
var keyValue = Opentelemetry_Proto_Common_V1_KeyValue()
1313
keyValue.key = key
1414
switch attributeValue {
@@ -48,7 +48,7 @@ struct CommonAdapter {
4848
return keyValue
4949
}
5050

51-
static func toProtoInstrumentationScope(instrumentationScopeInfo: InstrumentationScopeInfo) -> Opentelemetry_Proto_Common_V1_InstrumentationScope {
51+
public static func toProtoInstrumentationScope(instrumentationScopeInfo: InstrumentationScopeInfo) -> Opentelemetry_Proto_Common_V1_InstrumentationScope {
5252

5353
var instrumentationScope = Opentelemetry_Proto_Common_V1_InstrumentationScope()
5454
instrumentationScope.name = instrumentationScopeInfo.name

Sources/Exporters/OpenTelemetryProtocol/common/Constants.swift renamed to Sources/Exporters/OpenTelemetryProtocolCommon/common/Constants.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import Foundation
77

88
public enum Constants {
9-
enum HTTP {
10-
static let userAgent = "User-Agent"
9+
public enum HTTP {
10+
public static let userAgent = "User-Agent"
1111
}
1212
}

Sources/Exporters/OpenTelemetryProtocol/common/OtlpConfiguration.swift renamed to Sources/Exporters/OpenTelemetryProtocolCommon/common/OtlpConfiguration.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
import Foundation
77

8-
9-
108
public struct OtlpConfiguration {
119
public static let DefaultTimeoutInterval : TimeInterval = TimeInterval(10)
1210

@@ -23,11 +21,11 @@ public struct OtlpConfiguration {
2321
// let endpoint : URL? = URL(string: "https://localhost:4317")
2422
// let certificateFile
2523
// let compression
26-
let headers : [(String,String)]?
27-
let timeout : TimeInterval
24+
public let headers : [(String,String)]?
25+
public let timeout : TimeInterval
2826

2927
public init(timeout : TimeInterval = OtlpConfiguration.DefaultTimeoutInterval, headers: [(String,String)]? = nil) {
3028
self.headers = headers
3129
self.timeout = timeout
3230
}
33-
}
31+
}

Sources/Exporters/OpenTelemetryProtocol/common/ResourceAdapter.swift renamed to Sources/Exporters/OpenTelemetryProtocolCommon/common/ResourceAdapter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import Foundation
77
import OpenTelemetrySdk
88

9-
struct ResourceAdapter {
10-
static func toProtoResource(resource: Resource) -> Opentelemetry_Proto_Resource_V1_Resource {
9+
public struct ResourceAdapter {
10+
public static func toProtoResource(resource: Resource) -> Opentelemetry_Proto_Resource_V1_Resource {
1111
var outputResource = Opentelemetry_Proto_Resource_V1_Resource()
1212
resource.attributes.forEach {
1313
let protoAttribute = CommonAdapter.toProtoAttribute(key: $0.key, attributeValue: $0.value)

0 commit comments

Comments
 (0)