Skip to content

Commit

Permalink
Merge pull request #399 from Sherlouk/separate-http-grpc
Browse files Browse the repository at this point in the history
Separate OTLP HTTP and GRPC Exporters
  • Loading branch information
Ignacio Bonafonte authored Apr 30, 2023
2 parents a7004d0 + d1155cc commit a85c8c9
Show file tree
Hide file tree
Showing 48 changed files with 97 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Examples/OTLP Exporter/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import GRPC
import NIO
import NIOSSL
import OpenTelemetryApi
import OpenTelemetryProtocolExporter
import OpenTelemetryProtocolExporterGrpc
import OpenTelemetrySdk
import ResourceExtension
import SignPostIntegration
Expand Down
5 changes: 1 addition & 4 deletions Examples/OTLP HTTP Exporter/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
#if os(macOS)

import Foundation
import GRPC
import NIO
import NIOSSL
import OpenTelemetryApi
import OpenTelemetryProtocolExporter
import OpenTelemetryProtocolExporterHttp
import OpenTelemetrySdk
import ResourceExtension
import SignPostIntegration
Expand Down
32 changes: 23 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ let package = Package(
.library(name: "ZipkinExporter", type: .static, targets: ["ZipkinExporter"]),
.library(name: "StdoutExporter", type: .static, targets: ["StdoutExporter"]),
.library(name: "PrometheusExporter", type: .static, targets: ["PrometheusExporter"]),
.library(name: "OpenTelemetryProtocolExporter", type: .static, targets: ["OpenTelemetryProtocolExporter"]),
.library(name: "OpenTelemetryProtocolExporter", type: .static, targets: ["OpenTelemetryProtocolExporterGrpc"]),
.library(name: "OpenTelemetryProtocolExporterHTTP", type: .static, targets: ["OpenTelemetryProtocolExporterHttp"]),
.library(name: "PersistenceExporter", type: .static, targets: ["PersistenceExporter"]),
.library(name: "InMemoryExporter", type: .static, targets: ["InMemoryExporter"]),
.library(name: "DatadogExporter", type: .static, targets: ["DatadogExporter"]),
Expand All @@ -37,6 +38,8 @@ let package = Package(
.package(name: "Thrift", url: "https://github.com/undefinedlabs/Thrift-Swift", from: "1.1.1"),
.package(name: "swift-nio", url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
.package(name: "grpc-swift", url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0"),
.package(name: "swift-protobuf", url: "https://github.com/apple/swift-protobuf.git", from: "1.20.2"),
.package(name: "swift-log", url: "https://github.com/apple/swift-log.git", from: "1.4.4"),
.package(name: "swift-metrics", url: "https://github.com/apple/swift-metrics.git", from: "2.1.1"),
.package(name: "Reachability.swift", url: "https://github.com/ashleymills/Reachability.swift", from: "5.1.0")
],
Expand Down Expand Up @@ -86,10 +89,20 @@ let package = Package(
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOHTTP1", package: "swift-nio")],
path: "Sources/Exporters/Prometheus"),
.target(name: "OpenTelemetryProtocolExporter",
.target(name: "OpenTelemetryProtocolExporterCommon",
dependencies: ["OpenTelemetrySdk",
.product(name: "Logging", package: "swift-log"),
.product(name: "SwiftProtobuf", package: "swift-protobuf")],
path: "Sources/Exporters/OpenTelemetryProtocolCommon"),
.target(name: "OpenTelemetryProtocolExporterHttp",
dependencies: ["OpenTelemetrySdk",
"OpenTelemetryProtocolExporterCommon"],
path: "Sources/Exporters/OpenTelemetryProtocolHttp"),
.target(name: "OpenTelemetryProtocolExporterGrpc",
dependencies: ["OpenTelemetrySdk",
"OpenTelemetryProtocolExporterCommon",
.product(name: "GRPC", package: "grpc-swift")],
path: "Sources/Exporters/OpenTelemetryProtocol"),
path: "Sources/Exporters/OpenTelemetryProtocolGrpc"),
.target(name: "StdoutExporter",
dependencies: ["OpenTelemetrySdk"],
path: "Sources/Exporters/Stdout"),
Expand Down Expand Up @@ -139,10 +152,11 @@ let package = Package(
dependencies: ["PrometheusExporter"],
path: "Tests/ExportersTests/Prometheus"),
.testTarget(name: "OpenTelemetryProtocolExporterTests",
dependencies: ["OpenTelemetryProtocolExporter",
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOTestUtils", package: "swift-nio")],
dependencies: ["OpenTelemetryProtocolExporterGrpc",
"OpenTelemetryProtocolExporterHttp",
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOTestUtils", package: "swift-nio")],
path: "Tests/ExportersTests/OpenTelemetryProtocol"),
.testTarget(name: "InMemoryExporterTests",
dependencies: ["InMemoryExporter"],
Expand All @@ -163,11 +177,11 @@ let package = Package(
path: "Examples/Simple Exporter",
exclude: ["README.md"]),
.target(name: "OTLPExporter",
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporter", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporterGrpc", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
path: "Examples/OTLP Exporter",
exclude: ["README.md"]),
.target(name: "OTLPHTTPExporter",
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporter", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporterHttp", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
path: "Examples/OTLP HTTP Exporter",
exclude: ["README.md"]),
.target(name: "PrometheusSample",
Expand Down
32 changes: 23 additions & 9 deletions Package@swift-5.6.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ let package = Package(
.library(name: "ZipkinExporter", type: .static, targets: ["ZipkinExporter"]),
.library(name: "StdoutExporter", type: .static, targets: ["StdoutExporter"]),
.library(name: "PrometheusExporter", type: .static, targets: ["PrometheusExporter"]),
.library(name: "OpenTelemetryProtocolExporter", type: .static, targets: ["OpenTelemetryProtocolExporter"]),
.library(name: "OpenTelemetryProtocolExporter", type: .static, targets: ["OpenTelemetryProtocolExporterGrpc"]),
.library(name: "OpenTelemetryProtocolExporterHTTP", type: .static, targets: ["OpenTelemetryProtocolExporterHttp"]),
.library(name: "PersistenceExporter", type: .static, targets: ["PersistenceExporter"]),
.library(name: "InMemoryExporter", type: .static, targets: ["InMemoryExporter"]),
.library(name: "DatadogExporter", type: .static, targets: ["DatadogExporter"]),
Expand All @@ -38,6 +39,8 @@ let package = Package(
.package(url: "https://github.com/undefinedlabs/Thrift-Swift", from: "1.1.1"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.20.2"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.4"),
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.1.1"),
.package(url: "https://github.com/ashleymills/Reachability.swift", from: "5.1.0")
],
Expand Down Expand Up @@ -91,10 +94,20 @@ let package = Package(
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOHTTP1", package: "swift-nio")],
path: "Sources/Exporters/Prometheus"),
.target(name: "OpenTelemetryProtocolExporter",
.target(name: "OpenTelemetryProtocolExporterCommon",
dependencies: ["OpenTelemetrySdk",
.product(name: "Logging", package: "swift-log"),
.product(name: "SwiftProtobuf", package: "swift-protobuf")],
path: "Sources/Exporters/OpenTelemetryProtocolCommon"),
.target(name: "OpenTelemetryProtocolExporterHttp",
dependencies: ["OpenTelemetrySdk",
"OpenTelemetryProtocolExporterCommon"],
path: "Sources/Exporters/OpenTelemetryProtocolHttp"),
.target(name: "OpenTelemetryProtocolExporterGrpc",
dependencies: ["OpenTelemetrySdk",
"OpenTelemetryProtocolExporterCommon",
.product(name: "GRPC", package: "grpc-swift")],
path: "Sources/Exporters/OpenTelemetryProtocol"),
path: "Sources/Exporters/OpenTelemetryProtocolGrpc"),
.target(name: "StdoutExporter",
dependencies: ["OpenTelemetrySdk"],
path: "Sources/Exporters/Stdout"),
Expand Down Expand Up @@ -147,10 +160,11 @@ let package = Package(
dependencies: ["PrometheusExporter"],
path: "Tests/ExportersTests/Prometheus"),
.testTarget(name: "OpenTelemetryProtocolExporterTests",
dependencies: ["OpenTelemetryProtocolExporter",
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOTestUtils", package: "swift-nio")],
dependencies: ["OpenTelemetryProtocolExporterGrpc",
"OpenTelemetryProtocolExporterHttp",
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOTestUtils", package: "swift-nio")],
path: "Tests/ExportersTests/OpenTelemetryProtocol"),
.testTarget(name: "InMemoryExporterTests",
dependencies: ["InMemoryExporter"],
Expand All @@ -176,13 +190,13 @@ let package = Package(
),
.executableTarget(
name: "OTLPExporter",
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporter", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporterGrpc", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
path: "Examples/OTLP Exporter",
exclude: ["README.md"]
),
.executableTarget(
name: "OTLPHTTPExporter",
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporter", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
dependencies: ["OpenTelemetrySdk", "OpenTelemetryProtocolExporterHttp", "StdoutExporter", "ZipkinExporter", "ResourceExtension", "SignPostIntegration"],
path: "Examples/OTLP HTTP Exporter",
exclude: ["README.md"]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Foundation
import OpenTelemetryApi
import OpenTelemetrySdk

struct CommonAdapter {
static func toProtoAttribute(key: String, attributeValue: AttributeValue) -> Opentelemetry_Proto_Common_V1_KeyValue {
public struct CommonAdapter {
public static func toProtoAttribute(key: String, attributeValue: AttributeValue) -> Opentelemetry_Proto_Common_V1_KeyValue {
var keyValue = Opentelemetry_Proto_Common_V1_KeyValue()
keyValue.key = key
switch attributeValue {
Expand Down Expand Up @@ -48,7 +48,7 @@ struct CommonAdapter {
return keyValue
}

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

var instrumentationScope = Opentelemetry_Proto_Common_V1_InstrumentationScope()
instrumentationScope.name = instrumentationScopeInfo.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Foundation

public enum Constants {
enum HTTP {
static let userAgent = "User-Agent"
public enum HTTP {
public static let userAgent = "User-Agent"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import Foundation



public struct OtlpConfiguration {
public static let DefaultTimeoutInterval : TimeInterval = TimeInterval(10)

Expand All @@ -23,11 +21,11 @@ public struct OtlpConfiguration {
// let endpoint : URL? = URL(string: "https://localhost:4317")
// let certificateFile
// let compression
let headers : [(String,String)]?
let timeout : TimeInterval
public let headers : [(String,String)]?
public let timeout : TimeInterval

public init(timeout : TimeInterval = OtlpConfiguration.DefaultTimeoutInterval, headers: [(String,String)]? = nil) {
self.headers = headers
self.timeout = timeout
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import Foundation
import OpenTelemetrySdk

struct ResourceAdapter {
static func toProtoResource(resource: Resource) -> Opentelemetry_Proto_Resource_V1_Resource {
public struct ResourceAdapter {
public static func toProtoResource(resource: Resource) -> Opentelemetry_Proto_Resource_V1_Resource {
var outputResource = Opentelemetry_Proto_Resource_V1_Resource()
resource.attributes.forEach {
let protoAttribute = CommonAdapter.toProtoAttribute(key: $0.key, attributeValue: $0.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Foundation
import OpenTelemetryApi
import OpenTelemetrySdk

struct MetricsAdapter {
static func toProtoResourceMetrics(metricDataList: [Metric]) -> [Opentelemetry_Proto_Metrics_V1_ResourceMetrics] {
public struct MetricsAdapter {
public static func toProtoResourceMetrics(metricDataList: [Metric]) -> [Opentelemetry_Proto_Metrics_V1_ResourceMetrics] {
let resourceAndScopeMap = groupByResouceAndScope(metricDataList: metricDataList)
var resourceMetrics = [Opentelemetry_Proto_Metrics_V1_ResourceMetrics]()

Expand Down Expand Up @@ -45,7 +45,7 @@ struct MetricsAdapter {
return results
}

static func toProtoMetric(metric: Metric) -> Opentelemetry_Proto_Metrics_V1_Metric? {
public static func toProtoMetric(metric: Metric) -> Opentelemetry_Proto_Metrics_V1_Metric? {
var protoMetric = Opentelemetry_Proto_Metrics_V1_Metric()
protoMetric.name = metric.name
protoMetric.unit = "unit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Foundation

// Model class
struct OtlpSpan: Codable {
public struct OtlpSpan: Codable {
var resourceSpans: [ResourceSpan]?

struct ResourceSpan: Codable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Foundation
import OpenTelemetryApi
import OpenTelemetrySdk

struct SpanAdapter {
static func toProtoResourceSpans(spanDataList: [SpanData]) -> [Opentelemetry_Proto_Trace_V1_ResourceSpans] {
public struct SpanAdapter {
public static func toProtoResourceSpans(spanDataList: [SpanData]) -> [Opentelemetry_Proto_Trace_V1_ResourceSpans] {
let resourceAndScopeMap = groupByResourceAndScope(spanDataList: spanDataList)
var resourceSpans = [Opentelemetry_Proto_Trace_V1_ResourceSpans]()
resourceAndScopeMap.forEach { resMap in
Expand Down Expand Up @@ -39,7 +39,7 @@ struct SpanAdapter {
return result
}

static func toProtoSpan(spanData: SpanData) -> Opentelemetry_Proto_Trace_V1_Span {
public static func toProtoSpan(spanData: SpanData) -> Opentelemetry_Proto_Trace_V1_Span {
var protoSpan = Opentelemetry_Proto_Trace_V1_Span()
protoSpan.traceID = TraceProtoUtils.toProtoTraceId(traceId: spanData.traceId)
protoSpan.spanID = TraceProtoUtils.toProtoSpanId(spanId: spanData.spanId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import NIO
import NIOHPACK
import OpenTelemetryApi
import OpenTelemetrySdk
import OpenTelemetryProtocolExporterCommon

public class OtlpLogExporter : LogRecordExporter {
let channel : GRPCChannel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import NIO
import NIOHPACK
import OpenTelemetryApi
import OpenTelemetrySdk
import OpenTelemetryProtocolExporterCommon

public class OtlpMetricExporter: MetricExporter {
let channel: GRPCChannel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import GRPC
import NIO
import NIOConcurrencyHelpers
import SwiftProtobuf

import OpenTelemetryProtocolExporterCommon

/// Service that can be used to push logs between one Application instrumented with
/// OpenTelemetry and an collector, or between an collector and a central collector (in this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import GRPC
import NIO
import NIOConcurrencyHelpers
import SwiftProtobuf

import OpenTelemetryProtocolExporterCommon

/// Service that can be used to push metrics between one Application
/// instrumented with OpenTelemetry and a collector, or between a collector and a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import GRPC
import NIO
import NIOConcurrencyHelpers
import SwiftProtobuf

import OpenTelemetryProtocolExporterCommon

/// Service that can be used to push spans between one Application instrumented with
/// OpenTelemetry and a collector, or between a collector and a central collector (in this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import NIO
import NIOHPACK
import OpenTelemetryApi
import OpenTelemetrySdk
import OpenTelemetryProtocolExporterCommon

public class OtlpTraceExporter: SpanExporter {
let channel: GRPCChannel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import Foundation
import OpenTelemetrySdk
import OpenTelemetryProtocolExporterCommon

public class OtlpTraceJsonExporter: SpanExporter {

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

import Foundation
import SwiftProtobuf
import OpenTelemetryProtocolExporterCommon

public class OtlpHttpExporterBase {
let endpoint: URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import Foundation
import OpenTelemetrySdk
import OpenTelemetryProtocolExporterCommon

public func defaultOltpHttpLoggingEndpoint() -> URL {
URL(string: "http://localhost:4318/v1/logs")!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//

import OpenTelemetrySdk
import OpenTelemetryProtocolExporterCommon
import Foundation

public func defaultOltpHTTPMetricsEndpoint() -> URL {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import Foundation
import OpenTelemetrySdk
import OpenTelemetryProtocolExporterCommon

public func defaultOltpHttpTracesEndpoint() -> URL {
URL(string: "http://localhost:4318/v1/traces")!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation
import OpenTelemetryApi
@testable import OpenTelemetryProtocolExporter
@testable import OpenTelemetryProtocolExporterCommon
import OpenTelemetrySdk
import XCTest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import Foundation
import OpenTelemetryProtocolExporter
import OpenTelemetryProtocolExporterCommon
import XCTest

class EnvVarHeadersTests: XCTestCase {
Expand Down
Loading

0 comments on commit a85c8c9

Please # to comment.