Skip to content

Commit 9925a62

Browse files
committed
added detectors and updated protobufs
1 parent 64bf660 commit 9925a62

18 files changed

+459
-392
lines changed

Sources/Exporters/OpenTelemetryProtocolCommon/common/ResourceAdapter.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ public enum ResourceAdapter {
1313
let protoAttribute = CommonAdapter.toProtoAttribute(key: $0.key, attributeValue: $0.value)
1414
outputResource.attributes.append(protoAttribute)
1515
}
16+
resource.entities.forEach {
17+
if $0.identifierKeys.isEmpty {
18+
return
19+
}
20+
var entityRef = Opentelemetry_Proto_Common_V1_EntityRef()
21+
entityRef.type = $0.type
22+
entityRef.idKeys = Array($0.identifierKeys)
23+
entityRef.descriptionKeys = Array($0.attributeKeys)
24+
outputResource.entityRefs.append(entityRef)
25+
}
1626
return outputResource
1727
}
1828
}

Sources/Exporters/OpenTelemetryProtocolCommon/proto/common.pb.swift

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,48 @@ public struct Opentelemetry_Proto_Common_V1_InstrumentationScope: Sendable {
206206
public init() {}
207207
}
208208

209+
/// A reference to an Entity.
210+
/// Entity represents an object of interest associated with produced telemetry: e.g spans, metrics, profiles, or logs.
211+
///
212+
/// Status: [Development]
213+
public struct Opentelemetry_Proto_Common_V1_EntityRef: Sendable {
214+
// SwiftProtobuf.Message conformance is added in an extension below. See the
215+
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
216+
// methods supported on all messages.
217+
218+
/// The Schema URL, if known. This is the identifier of the Schema that the entity data
219+
/// is recorded in. To learn more about Schema URL see
220+
/// https://opentelemetry.io/docs/specs/otel/schemas/#schema-url
221+
///
222+
/// This schema_url applies to the data in this message and to the Resource attributes
223+
/// referenced by id_keys and description_keys.
224+
/// TODO: discuss if we are happy with this somewhat complicated definition of what
225+
/// the schema_url applies to.
226+
///
227+
/// This field obsoletes the schema_url field in ResourceMetrics/ResourceSpans/ResourceLogs.
228+
public var schemaURL: String = String()
229+
230+
/// Defines the type of the entity. MUST not change during the lifetime of the entity.
231+
/// For example: "service" or "host". This field is required and MUST not be empty
232+
/// for valid entities.
233+
public var type: String = String()
234+
235+
/// Attribute Keys that identify the entity.
236+
/// MUST not change during the lifetime of the entity. The Id must contain at least one attribute.
237+
/// These keys MUST exist in the containing {message}.attributes.
238+
public var idKeys: [String] = []
239+
240+
/// Descriptive (non-identifying) attribute keys of the entity.
241+
/// MAY change over the lifetime of the entity. MAY be empty.
242+
/// These attribute keys are not part of entity's identity.
243+
/// These keys MUST exist in the containing {message}.attributes.
244+
public var descriptionKeys: [String] = []
245+
246+
public var unknownFields = SwiftProtobuf.UnknownStorage()
247+
248+
public init() {}
249+
}
250+
209251
// MARK: - Code below here is support for the SwiftProtobuf runtime.
210252

211253
fileprivate let _protobuf_package = "opentelemetry.proto.common.v1"
@@ -500,3 +542,53 @@ extension Opentelemetry_Proto_Common_V1_InstrumentationScope: SwiftProtobuf.Mess
500542
return true
501543
}
502544
}
545+
546+
extension Opentelemetry_Proto_Common_V1_EntityRef: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
547+
public static let protoMessageName: String = _protobuf_package + ".EntityRef"
548+
public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
549+
1: .standard(proto: "schema_url"),
550+
2: .same(proto: "type"),
551+
3: .standard(proto: "id_keys"),
552+
4: .standard(proto: "description_keys"),
553+
]
554+
555+
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
556+
while let fieldNumber = try decoder.nextFieldNumber() {
557+
// The use of inline closures is to circumvent an issue where the compiler
558+
// allocates stack space for every case branch when no optimizations are
559+
// enabled. https://github.com/apple/swift-protobuf/issues/1034
560+
switch fieldNumber {
561+
case 1: try { try decoder.decodeSingularStringField(value: &self.schemaURL) }()
562+
case 2: try { try decoder.decodeSingularStringField(value: &self.type) }()
563+
case 3: try { try decoder.decodeRepeatedStringField(value: &self.idKeys) }()
564+
case 4: try { try decoder.decodeRepeatedStringField(value: &self.descriptionKeys) }()
565+
default: break
566+
}
567+
}
568+
}
569+
570+
public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
571+
if !self.schemaURL.isEmpty {
572+
try visitor.visitSingularStringField(value: self.schemaURL, fieldNumber: 1)
573+
}
574+
if !self.type.isEmpty {
575+
try visitor.visitSingularStringField(value: self.type, fieldNumber: 2)
576+
}
577+
if !self.idKeys.isEmpty {
578+
try visitor.visitRepeatedStringField(value: self.idKeys, fieldNumber: 3)
579+
}
580+
if !self.descriptionKeys.isEmpty {
581+
try visitor.visitRepeatedStringField(value: self.descriptionKeys, fieldNumber: 4)
582+
}
583+
try unknownFields.traverse(visitor: &visitor)
584+
}
585+
586+
public static func ==(lhs: Opentelemetry_Proto_Common_V1_EntityRef, rhs: Opentelemetry_Proto_Common_V1_EntityRef) -> Bool {
587+
if lhs.schemaURL != rhs.schemaURL {return false}
588+
if lhs.type != rhs.type {return false}
589+
if lhs.idKeys != rhs.idKeys {return false}
590+
if lhs.descriptionKeys != rhs.descriptionKeys {return false}
591+
if lhs.unknownFields != rhs.unknownFields {return false}
592+
return true
593+
}
594+
}

Sources/Exporters/OpenTelemetryProtocolCommon/proto/logs.pb.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,6 @@ public struct Opentelemetry_Proto_Logs_V1_LogRecord: @unchecked Sendable {
407407
/// as an event.
408408
///
409409
/// [Optional].
410-
///
411-
/// Status: [Development]
412410
public var eventName: String = String()
413411

414412
public var unknownFields = SwiftProtobuf.UnknownStorage()

Sources/Exporters/OpenTelemetryProtocolCommon/proto/metrics.pb.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public struct Opentelemetry_Proto_Metrics_V1_Metric: Sendable {
397397
public var description_p: String = String()
398398

399399
/// unit in which the metric value is reported. Follows the format
400-
/// described by http://unitsofmeasure.org/ucum.html.
400+
/// described by https://unitsofmeasure.org/ucum.html.
401401
public var unit: String = String()
402402

403403
/// Data determines the aggregation type (if any) of the metric, what is the
@@ -551,7 +551,7 @@ public struct Opentelemetry_Proto_Metrics_V1_ExponentialHistogram: Sendable {
551551

552552
/// Summary metric data are used to convey quantile summaries,
553553
/// a Prometheus (see: https://prometheus.io/docs/concepts/metric_types/#summary)
554-
/// and OpenMetrics (see: https://github.com/OpenObservability/OpenMetrics/blob/4dbf6075567ab43296eed941037c12951faafb92/protos/prometheus.proto#L45)
554+
/// and OpenMetrics (see: https://github.com/prometheus/OpenMetrics/blob/4dbf6075567ab43296eed941037c12951faafb92/protos/prometheus.proto#L45)
555555
/// data type. These data points cannot always be merged in a meaningful way.
556556
/// While they can be useful in some applications, histogram data points are
557557
/// recommended for new applications.
@@ -699,7 +699,9 @@ public struct Opentelemetry_Proto_Metrics_V1_HistogramDataPoint: Sendable {
699699
/// The sum of the bucket_counts must equal the value in the count field.
700700
///
701701
/// The number of elements in bucket_counts array must be by one greater than
702-
/// the number of elements in explicit_bounds array.
702+
/// the number of elements in explicit_bounds array. The exception to this rule
703+
/// is when the length of bucket_counts is 0, then the length of explicit_bounds
704+
/// must also be 0.
703705
public var bucketCounts: [UInt64] = []
704706

705707
/// explicit_bounds specifies buckets with explicitly defined bounds for values.
@@ -715,6 +717,9 @@ public struct Opentelemetry_Proto_Metrics_V1_HistogramDataPoint: Sendable {
715717
/// Histogram buckets are inclusive of their upper boundary, except the last
716718
/// bucket where the boundary is at infinity. This format is intentionally
717719
/// compatible with the OpenMetrics histogram definition.
720+
///
721+
/// If bucket_counts length is 0 then explicit_bounds length must also be 0,
722+
/// otherwise the data point is invalid.
718723
public var explicitBounds: [Double] = []
719724

720725
/// (Optional) List of exemplars collected from
@@ -897,7 +902,7 @@ public struct Opentelemetry_Proto_Metrics_V1_ExponentialHistogramDataPoint: Send
897902
// methods supported on all messages.
898903

899904
/// Offset is the bucket index of the first entry in the bucket_counts array.
900-
///
905+
///
901906
/// Note: This uses a varint encoding as a simple form of compression.
902907
public var offset: Int32 = 0
903908

0 commit comments

Comments
 (0)