Skip to content

Commit

Permalink
updated otlp method visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
bryce-b committed Jul 3, 2023
1 parent ab5fe92 commit c0531b5
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 55 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,15 +28,15 @@ 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))
}
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
Expand All @@ -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]()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit c0531b5

Please sign in to comment.