From c0531b551fddc01cb5cc0cabaae8a7d6eec580cf Mon Sep 17 00:00:00 2001 From: Bryce Buchanan Date: Mon, 3 Jul 2023 15:05:40 -0700 Subject: [PATCH] updated otlp method visibility --- CONTRIBUTING.md | 2 +- .../common/CommonAdapter.swift | 4 +- .../common/ResourceAdapter.swift | 2 +- .../logs/LogRecordAdapter.swift | 6 +-- .../metric/MetricsAdapter.swift | 8 ++-- .../trace/SpanAdapter.swift | 4 +- .../trace/utils/TraceProtoUtils.swift | 47 ++----------------- 7 files changed, 18 insertions(+), 55 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9d095602..18f14ddd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -140,7 +140,7 @@ From within opentelemetry-proto: ```shell # collect the proto definitions: -PROTO_FILES=($(ls ../opentelemetry/proto/*/*/*/*.proto ../opentelemetry/proto/*/*/*.proto)) +PROTO_FILES=($(ls opentelemetry/proto/*/*/*/*.proto opentelemetry/proto/*/*/*.proto)) # generate swift proto files for file in "${PROTO_FILES[@]}" do diff --git a/Sources/Exporters/OpenTelemetryProtocolCommon/common/CommonAdapter.swift b/Sources/Exporters/OpenTelemetryProtocolCommon/common/CommonAdapter.swift index 4a0abcff..780929e1 100644 --- a/Sources/Exporters/OpenTelemetryProtocolCommon/common/CommonAdapter.swift +++ b/Sources/Exporters/OpenTelemetryProtocolCommon/common/CommonAdapter.swift @@ -8,7 +8,7 @@ import OpenTelemetryApi import OpenTelemetrySdk public struct CommonAdapter { - public static func toProtoAttribute(key: String, attributeValue: AttributeValue) + static func toProtoAttribute(key: String, attributeValue: AttributeValue) -> Opentelemetry_Proto_Common_V1_KeyValue { var keyValue = Opentelemetry_Proto_Common_V1_KeyValue() @@ -54,7 +54,7 @@ public struct CommonAdapter { return keyValue } - public static func toProtoInstrumentationScope(instrumentationScopeInfo: InstrumentationScopeInfo) + static func toProtoInstrumentationScope(instrumentationScopeInfo: InstrumentationScopeInfo) -> Opentelemetry_Proto_Common_V1_InstrumentationScope { diff --git a/Sources/Exporters/OpenTelemetryProtocolCommon/common/ResourceAdapter.swift b/Sources/Exporters/OpenTelemetryProtocolCommon/common/ResourceAdapter.swift index 97c1e80a..a0ed5f43 100644 --- a/Sources/Exporters/OpenTelemetryProtocolCommon/common/ResourceAdapter.swift +++ b/Sources/Exporters/OpenTelemetryProtocolCommon/common/ResourceAdapter.swift @@ -7,7 +7,7 @@ import Foundation import OpenTelemetrySdk public struct ResourceAdapter { - public static func toProtoResource(resource: Resource) -> Opentelemetry_Proto_Resource_V1_Resource { + 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) diff --git a/Sources/Exporters/OpenTelemetryProtocolCommon/logs/LogRecordAdapter.swift b/Sources/Exporters/OpenTelemetryProtocolCommon/logs/LogRecordAdapter.swift index 7660a05b..e91f69c3 100644 --- a/Sources/Exporters/OpenTelemetryProtocolCommon/logs/LogRecordAdapter.swift +++ b/Sources/Exporters/OpenTelemetryProtocolCommon/logs/LogRecordAdapter.swift @@ -7,7 +7,7 @@ import Foundation import OpenTelemetryApi import OpenTelemetrySdk public class LogRecordAdapter { - public static func toProtoResourceRecordLog(logRecordList: [ReadableLogRecord]) -> [Opentelemetry_Proto_Logs_V1_ResourceLogs] { + static func toProtoResourceRecordLog(logRecordList: [ReadableLogRecord]) -> [Opentelemetry_Proto_Logs_V1_ResourceLogs] { let resourceAndScopeMap = groupByResourceAndScope(logRecordList: logRecordList) var resourceLogs = [Opentelemetry_Proto_Logs_V1_ResourceLogs]() resourceAndScopeMap.forEach { resMap in @@ -28,7 +28,7 @@ public class LogRecordAdapter { return resourceLogs } - public static func groupByResourceAndScope(logRecordList: [ReadableLogRecord]) -> [Resource:[InstrumentationScopeInfo:[Opentelemetry_Proto_Logs_V1_LogRecord]]] { + internal static func groupByResourceAndScope(logRecordList: [ReadableLogRecord]) -> [Resource:[InstrumentationScopeInfo:[Opentelemetry_Proto_Logs_V1_LogRecord]]] { var result = [Resource:[InstrumentationScopeInfo: [Opentelemetry_Proto_Logs_V1_LogRecord]]]() logRecordList.forEach { logRecord in result[logRecord.resource, default:[InstrumentationScopeInfo: [Opentelemetry_Proto_Logs_V1_LogRecord]]()][logRecord.instrumentationScopeInfo,default:[Opentelemetry_Proto_Logs_V1_LogRecord]()].append(toProtoLogRecord(logRecord: logRecord)) @@ -36,7 +36,7 @@ public class LogRecordAdapter { return result } - public static func toProtoLogRecord(logRecord: ReadableLogRecord) -> Opentelemetry_Proto_Logs_V1_LogRecord { + static func toProtoLogRecord(logRecord: ReadableLogRecord) -> Opentelemetry_Proto_Logs_V1_LogRecord { var protoLogRecord = Opentelemetry_Proto_Logs_V1_LogRecord() if let observedTimestamp = logRecord.observedTimestamp { diff --git a/Sources/Exporters/OpenTelemetryProtocolCommon/metric/MetricsAdapter.swift b/Sources/Exporters/OpenTelemetryProtocolCommon/metric/MetricsAdapter.swift index 262ee641..47aa37fb 100644 --- a/Sources/Exporters/OpenTelemetryProtocolCommon/metric/MetricsAdapter.swift +++ b/Sources/Exporters/OpenTelemetryProtocolCommon/metric/MetricsAdapter.swift @@ -7,7 +7,7 @@ import OpenTelemetryApi import OpenTelemetrySdk public enum MetricsAdapter { - public static func toProtoResourceMetrics(stableMetricData: [StableMetricData]) -> [Opentelemetry_Proto_Metrics_V1_ResourceMetrics] { + static func toProtoResourceMetrics(stableMetricData: [StableMetricData]) -> [Opentelemetry_Proto_Metrics_V1_ResourceMetrics] { let resourceAndScopeMap = groupByResouceAndScope(stableMetricData: stableMetricData) var resourceMetrics = [Opentelemetry_Proto_Metrics_V1_ResourceMetrics]() @@ -30,7 +30,7 @@ public enum MetricsAdapter { return resourceMetrics } - public static func toProtoResourceMetrics(metricDataList: [Metric]) -> [Opentelemetry_Proto_Metrics_V1_ResourceMetrics] { + static func toProtoResourceMetrics(metricDataList: [Metric]) -> [Opentelemetry_Proto_Metrics_V1_ResourceMetrics] { let resourceAndScopeMap = groupByResouceAndScope(metricDataList: metricDataList) var resourceMetrics = [Opentelemetry_Proto_Metrics_V1_ResourceMetrics]() @@ -79,7 +79,7 @@ public enum MetricsAdapter { return results } - public static func toProtoMetric(stableMetric: StableMetricData) -> Opentelemetry_Proto_Metrics_V1_Metric? { + static func toProtoMetric(stableMetric: StableMetricData) -> Opentelemetry_Proto_Metrics_V1_Metric? { var protoMetric = Opentelemetry_Proto_Metrics_V1_Metric() protoMetric.name = stableMetric.name protoMetric.unit = stableMetric.unit @@ -224,7 +224,7 @@ public enum MetricsAdapter { } } - public static func toProtoMetric(metric: Metric) -> Opentelemetry_Proto_Metrics_V1_Metric? { + static func toProtoMetric(metric: Metric) -> Opentelemetry_Proto_Metrics_V1_Metric? { var protoMetric = Opentelemetry_Proto_Metrics_V1_Metric() protoMetric.name = metric.name protoMetric.unit = "unit" diff --git a/Sources/Exporters/OpenTelemetryProtocolCommon/trace/SpanAdapter.swift b/Sources/Exporters/OpenTelemetryProtocolCommon/trace/SpanAdapter.swift index f375e76f..83cab421 100644 --- a/Sources/Exporters/OpenTelemetryProtocolCommon/trace/SpanAdapter.swift +++ b/Sources/Exporters/OpenTelemetryProtocolCommon/trace/SpanAdapter.swift @@ -8,7 +8,7 @@ import OpenTelemetryApi import OpenTelemetrySdk public struct SpanAdapter { - public static func toProtoResourceSpans(spanDataList: [SpanData]) -> [Opentelemetry_Proto_Trace_V1_ResourceSpans] { + 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 @@ -39,7 +39,7 @@ public struct SpanAdapter { return result } - public static func toProtoSpan(spanData: SpanData) -> Opentelemetry_Proto_Trace_V1_Span { + 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) diff --git a/Sources/Exporters/OpenTelemetryProtocolCommon/trace/utils/TraceProtoUtils.swift b/Sources/Exporters/OpenTelemetryProtocolCommon/trace/utils/TraceProtoUtils.swift index b5915eec..1fa0d1f7 100644 --- a/Sources/Exporters/OpenTelemetryProtocolCommon/trace/utils/TraceProtoUtils.swift +++ b/Sources/Exporters/OpenTelemetryProtocolCommon/trace/utils/TraceProtoUtils.swift @@ -15,46 +15,9 @@ struct TraceProtoUtils { return spanIdData } - static func toProtoTraceId(traceId: TraceId) -> Data { - var traceIdData = Data(count: TraceId.size) - traceId.copyBytesTo(dest: &traceIdData, destOffset: 0) - return traceIdData - } - - static func spanLimitsFromProto(protoTraceConfig: Opentelemetry_Proto_Trace_V1_TraceConfig) -> SpanLimits { - let spanLimits = SpanLimits() - spanLimits.settingAttributeCountLimit(UInt(protoTraceConfig.maxNumberOfAttributes)) - .settingEventCountLimit(UInt(protoTraceConfig.maxNumberOfTimedEvents)) - .settingLinkCountLimit(UInt(protoTraceConfig.maxNumberOfLinks)) - .settingAttributePerEventCountLimit(UInt(protoTraceConfig.maxNumberOfAttributesPerTimedEvent)) - .settingAttributePerLinkCountLimit(UInt(protoTraceConfig.maxNumberOfAttributesPerLink)) - return spanLimits - } - - static func fromProtoSampler(protoTraceConfig: Opentelemetry_Proto_Trace_V1_TraceConfig) -> Sampler { - guard protoTraceConfig.sampler != nil else { - return Samplers.alwaysOff - } - - switch protoTraceConfig.sampler! { - case .constantSampler(let constantSampler): - switch constantSampler.decision { - case .alwaysOff: - return Samplers.alwaysOff - case .alwaysOn: - return Samplers.alwaysOn - case .alwaysParent: - // TODO: add support for alwaysParent - break - case .UNRECOGNIZED: - break - } - case .traceIDRatioBased(let ratio): - return Samplers.traceIdRatio(ratio: ratio.samplingRatio) - case .rateLimitingSampler: - // TODO: add support for RateLimiting Sampler - break - } - return Samplers.alwaysOff - } + static func toProtoTraceId(traceId: TraceId) -> Data { + var traceIdData = Data(count: TraceId.size) + traceId.copyBytesTo(dest: &traceIdData, destOffset: 0) + return traceIdData + } }