Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding EmbraceSemantics module #27

Merged
merged 6 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,34 @@
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EmbraceSemantics"
BuildableName = "EmbraceSemantics"
BlueprintName = "EmbraceSemantics"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EmbraceSemantics-Dynamic"
BuildableName = "EmbraceSemantics-Dynamic"
BlueprintName = "EmbraceSemantics-Dynamic"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down Expand Up @@ -591,6 +619,16 @@
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EmbraceSemanticsTests"
BuildableName = "EmbraceSemanticsTests"
BlueprintName = "EmbraceSemanticsTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
8 changes: 8 additions & 0 deletions EmbraceIO.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Pod::Spec.new do |spec|
io.dependency "EmbraceIO/EmbraceCore"
io.dependency "EmbraceIO/EmbraceCommonInternal"
io.dependency "EmbraceIO/EmbraceCrash"
io.dependency "EmbraceIO/EmbraceSemantics"
end

spec.subspec 'EmbraceCore' do |core|
Expand All @@ -33,12 +34,17 @@ Pod::Spec.new do |spec|
core.dependency "EmbraceIO/EmbraceStorageInternal"
core.dependency "EmbraceIO/EmbraceUploadInternal"
core.dependency "EmbraceIO/EmbraceObjCUtilsInternal"
core.dependency "EmbraceIO/EmbraceSemantics"
end

spec.subspec 'EmbraceCommonInternal' do |common|
common.vendored_frameworks = "xcframeworks/EmbraceCommonInternal.xcframework"
end

spec.subspec 'EmbraceSemantics' do |semantics|
semantics.vendored_frameworks = "xcframeworks/EmbraceSemantics.xcframework"
end

spec.subspec 'EmbraceCaptureService' do |capture|
capture.vendored_frameworks = "xcframeworks/EmbraceCaptureService.xcframework"
capture.dependency "EmbraceIO/EmbraceOTelInternal"
Expand All @@ -53,12 +59,14 @@ Pod::Spec.new do |spec|
spec.subspec 'EmbraceOTelInternal' do |otel|
otel.vendored_frameworks = "xcframeworks/EmbraceOTelInternal.xcframework"
otel.dependency "EmbraceIO/EmbraceCommonInternal"
otel.dependency "EmbraceIO/EmbraceSemantics"
otel.dependency "EmbraceIO/OpenTelemetrySdk"
end

spec.subspec 'EmbraceStorageInternal' do |storage|
storage.vendored_frameworks = "xcframeworks/EmbraceStorageInternal.xcframework"
storage.dependency "EmbraceIO/EmbraceCommonInternal"
storage.dependency "EmbraceIO/EmbraceSemantics"
storage.dependency "EmbraceIO/OpenTelemetryApi"
storage.dependency "EmbraceIO/GRDB"
end
Expand Down
20 changes: 18 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ let package = Package(
.library(name: "EmbraceCore", targets: ["EmbraceCore"]),
.library(name: "EmbraceCrash", targets: ["EmbraceCrash"]),
.library(name: "EmbraceCrashlyticsSupport", targets: ["EmbraceCrashlyticsSupport"]),
.library(name: "EmbraceSemantics", targets: ["EmbraceSemantics"]),

.library(name: "EmbraceIO-Dynamic", type: .dynamic, targets: ["EmbraceIO"]),
.library(name: "EmbraceCore-Dynamic", type: .dynamic, targets: ["EmbraceCore"]),
.library(name: "EmbraceCrash-Dynamic", type: .dynamic, targets: ["EmbraceCrash"]),
.library(name: "EmbraceCrashlyticsSupport-Dynamic", type: .dynamic, targets: ["EmbraceCrashlyticsSupport"])
.library(name: "EmbraceCrashlyticsSupport-Dynamic", type: .dynamic, targets: ["EmbraceCrashlyticsSupport"]),
.library(name: "EmbraceSemantics-Dynamic", type: .dynamic, targets: ["EmbraceSemantics"]),
],
dependencies: [
.package(
Expand Down Expand Up @@ -58,7 +61,8 @@ let package = Package(
"EmbraceCaptureService",
"EmbraceCore",
"EmbraceCommonInternal",
"EmbraceCrash"
"EmbraceCrash",
"EmbraceSemantics"
],
plugins: targetPlugins
),
Expand Down Expand Up @@ -86,6 +90,7 @@ let package = Package(
"EmbraceStorageInternal",
"EmbraceUploadInternal",
"EmbraceObjCUtilsInternal",
"EmbraceSemantics"
],
resources: [
.copy("PrivacyInfo.xcprivacy")
Expand Down Expand Up @@ -120,6 +125,15 @@ let package = Package(
plugins: targetPlugins
),

// semantics -----------------------------------------------------------------
.target(
name: "EmbraceSemantics",
dependencies: [
"EmbraceCommonInternal"
],
plugins: targetPlugins
),

// capture service -----------------------------------------------------------
.target(
name: "EmbraceCaptureService",
Expand Down Expand Up @@ -164,6 +178,7 @@ let package = Package(
name: "EmbraceOTelInternal",
dependencies: [
"EmbraceCommonInternal",
"EmbraceSemantics",
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift")
],
plugins: targetPlugins
Expand All @@ -182,6 +197,7 @@ let package = Package(
name: "EmbraceStorageInternal",
dependencies: [
"EmbraceCommonInternal",
"EmbraceSemantics",
.product(name: "GRDB", package: "GRDB.swift")
],
plugins: targetPlugins
Expand Down
17 changes: 16 additions & 1 deletion Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ let project = Project(
.target(name: "EmbraceCaptureService"),
.target(name: "EmbraceCore"),
.target(name: "EmbraceCommonInternal"),
.target(name: "EmbraceCrash")
.target(name: "EmbraceCrash"),
.target(name: "EmbraceSemantics")
],
settings: .settings(base: [
"SKIP_INSTALL": "NO",
Expand All @@ -36,6 +37,7 @@ let project = Project(
.target(name: "EmbraceStorageInternal"),
.target(name: "EmbraceUploadInternal"),
.target(name: "EmbraceObjCUtilsInternal"),
.target(name: "EmbraceSemantics")
],
settings: .settings(base: [
"HEADER_SEARCH_PATHS": ["$(SRCROOT)/Sources/EmbraceObjCUtilsInternal/include"],
Expand All @@ -56,6 +58,17 @@ let project = Project(
"BUILD_LIBRARY_FOR_DISTRIBUTION": "YES"
])
),
.target(
name: "EmbraceSemantics",
destinations: .iOS,
product: .framework,
bundleId: "com.embraceio.EmbraceSemantics",
sources: ["Sources/EmbraceSemantics/**"],
settings: .settings(base: [
"SKIP_INSTALL": "NO",
"BUILD_LIBRARY_FOR_DISTRIBUTION": "YES"
])
),
.target(
name: "EmbraceCaptureService",
destinations: .iOS,
Expand Down Expand Up @@ -93,6 +106,7 @@ let project = Project(
sources: ["Sources/EmbraceOTelInternal/**"],
dependencies: [
.target(name: "EmbraceCommonInternal"),
.target(name: "EmbraceSemantics"),
.external(name: "OpenTelemetrySdk")
],
settings: .settings(base: [
Expand All @@ -108,6 +122,7 @@ let project = Project(
sources: ["Sources/EmbraceStorageInternal/**"],
dependencies: [
.target(name: "EmbraceCommonInternal"),
.target(name: "EmbraceSemantics"),
.external(name: "OpenTelemetryApi"),
.external(name: "GRDB")
],
Expand Down
103 changes: 103 additions & 0 deletions Sources/EmbraceCommonInternal/EmbraceType/EmbraceType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// Copyright © 2024 Embrace Mobile, Inc. All rights reserved.
//

/// An EmbraceType is an Embrace specific concept to allow for better categorization of Telemetry Primitives.
/// - This struct will be serialized into an `emb.type` attribute.
/// - This struct is encoded as a String with the format `<primary>.<secondary>`.
/// - The primary category is required, but the secondary category is optional.
public protocol EmbraceType: Hashable, Codable, CustomStringConvertible, RawRepresentable where RawValue == String {

var primary: PrimaryType { get }

var secondary: String? { get }

init(primary: PrimaryType, secondary: String?)
}

/// Top level category for the EmbraceType
public enum PrimaryType: String {
/// Category for observing a logical operation
case performance = "perf"

/// Category for observing the user's interaction or behavior
case ux = "ux"

/// Category for observing the system's operation or status
case system = "sys"
}

// MARK: - EmbraceType Extensions -

extension EmbraceType {
public init(primary: PrimaryType, secondary: String? = nil) {
self.init(primary: primary, secondary: secondary)
}

public init(performance secondary: String) {
self.init(primary: .performance, secondary: secondary)
}

public init(ux secondary: String) {
self.init(primary: .ux, secondary: secondary)
}

public init(system secondary: String) {
self.init(primary: .system, secondary: secondary)
}
}

extension EmbraceType {

public static var performance: Self { .init(primary: .performance, secondary: nil) }

public static var ux: Self { .init(primary: .ux, secondary: nil) }

public static var system: Self { .init(primary: .system, secondary: nil) }
}

// MARK: RawRepresentable
extension EmbraceType {
public var rawValue: String {
[primary.rawValue, secondary]
.compactMap { $0 }
.joined(separator: ".")
}

public init?(rawValue: String) {
let components = rawValue.components(separatedBy: ".")
guard let first = components.first,
let primary = PrimaryType(rawValue: first) else {
return nil
}

let secondary = components.count > 1 ? components.dropFirst().joined(separator: ".") : nil

self.init(primary: primary, secondary: secondary)
}
}

// MARK: Codable
extension EmbraceType {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let rawValue = try container.decode(String.self)

guard let embType = Self(rawValue: rawValue) else {
throw DecodingError.dataCorruptedError(in: container,
debugDescription: "Invalid EmbraceType: '\(rawValue.prefix(20))'")
}

self = embType
}

public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(rawValue)
}
}

// MARK: CustomStringConvertible
extension EmbraceType {
public var description: String { rawValue }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// Copyright © 2024 Embrace Mobile, Inc. All rights reserved.
//

// MARK: - System
extension LogType {
public static let `default` = LogType(system: "log")
public static let `internal` = LogType(system: "internal")
}
14 changes: 14 additions & 0 deletions Sources/EmbraceCommonInternal/EmbraceType/LogType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Copyright © 2024 Embrace Mobile, Inc. All rights reserved.
//

/// The EmbraceType used in Log telemetry
public struct LogType: EmbraceType {
public let primary: PrimaryType
public let secondary: String?

public init(primary: PrimaryType, secondary: String?) {
self.primary = primary
self.secondary = secondary
}
}
14 changes: 14 additions & 0 deletions Sources/EmbraceCommonInternal/EmbraceType/SpanEventType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Copyright © 2024 Embrace Mobile, Inc. All rights reserved.
//

/// The EmbraceType used in Tracing telemetry, specifically on SpanEvent items.
public struct SpanEventType: EmbraceType {
public let primary: PrimaryType
public let secondary: String?

public init(primary: PrimaryType, secondary: String?) {
self.primary = primary
self.secondary = secondary
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Copyright © 2024 Embrace Mobile, Inc. All rights reserved.
//

// MARK: - Performance
extension SpanType {

// File Operations
public static let fileIO = SpanType(performance: "file.io")
public static let fileRead = SpanType(performance: "file.read")
public static let fileWrite = SpanType(performance: "file.write")

// Database Operations
public static let sqlSelect = SpanType(performance: "sql.select")
public static let sqlUpdate = SpanType(performance: "sql.update")
public static let sqlDelete = SpanType(performance: "sql.delete")
public static let sqlVacuum = SpanType(performance: "sql.vacuum")
}
15 changes: 15 additions & 0 deletions Sources/EmbraceCommonInternal/EmbraceType/SpanType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Copyright © 2024 Embrace Mobile, Inc. All rights reserved.
//

/// The EmbraceType used in Tracing telemetry
public struct SpanType: EmbraceType {
public let primary: PrimaryType

public let secondary: String?

public init(primary: PrimaryType, secondary: String? = nil) {
self.primary = primary
self.secondary = secondary
}
}
Loading
Loading