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

feat: create XRayInstrument #16

Open
wants to merge 52 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
0fd427c
Chore: bump AnyCodable to 0.3.0
Jul 20, 2020
50c5da1
feat: create XRayInstrument
Jul 20, 2020
a27628d
Merge remote-tracking branch 'origin/master' into feature/instrument
Jul 20, 2020
b26c5f0
feat: expose Segment name
Jul 20, 2020
3ae1d29
refactor: rename TraceHeader to TraceContext, expose in Segment
Jul 21, 2020
ac2d5ac
feat: expose annotation and metadata values, allow to remove them
Jul 21, 2020
38f9a63
refactor: expose segment id
Jul 21, 2020
3d4d004
refactor: expose segment startTime and endTime
Jul 21, 2020
0f5d415
Merge branch 'develop' into feature/instrument
Jul 21, 2020
29ff160
Merge remote-tracking branch 'origin/master' into feature/instrument
Jul 21, 2020
6c1d3c9
WIP
Jul 21, 2020
80ed11f
WIP
Jul 23, 2020
e43ed86
Fixed XRayREcorder dependencies
Jul 23, 2020
e50851c
Do not limit extracting and injecting to HTTPHeaders, fixed testInjec…
Jul 23, 2020
a807dcc
Move dependency on HTTP injector/extractor to AWSXRayInstrumentTests
Jul 23, 2020
1a35ffa
Move dependency on HTTP injector/extractor to AWSXRayInstrumentTests
Jul 23, 2020
d749d4c
Merge branch 'develop' into feature/instrument
Jul 23, 2020
ec93186
Merge branch 'master' into feature/instrument
Jul 23, 2020
cf7d6fe
XRayInstrument - set attributes and status, append links and events
Jul 23, 2020
c5e7d2a
Generate TraceId in XRayInstrument tests
Jul 23, 2020
94c313e
feat: create AWSXRayInstrumentExample
Jul 23, 2020
e8aeb31
Create instrumented HTTP client
Jul 24, 2020
c7a1bbd
Fixed setting HTTP attributes
Jul 24, 2020
d8a597d
refactor: store events and links as string description (for now?)
Jul 24, 2020
b12b94b
fix: fix serialization of "appended" metadata
Jul 24, 2020
8e606f2
Merge branch 'develop' into feature/instrument
Jul 24, 2020
8bcb386
fix: testAppendingMetadata
Jul 24, 2020
393963a
Merge branch 'develop' into feature/instrument
Jul 24, 2020
924d164
Merge branch 'master' into feature/instrument
Jul 24, 2020
7a1e106
docs: add license headers
Jul 24, 2020
4ef2173
Merge branch 'master' into feature/instrument
Jul 25, 2020
d27ba09
Pull changes from swift-tracing
Jul 25, 2020
868aad2
Update XRayInstrument example to generate trace and query instrumente…
Jul 25, 2020
5b2d789
Store links and events separately
Jul 25, 2020
189a3aa
Merge branch 'master' into feature/instrument
Aug 1, 2020
0c634c7
Pull changes from swift-tracing
Aug 1, 2020
1af7dee
Merge branch 'master' into feature/instrument
Aug 1, 2020
d6cdd15
Fix compilation of AWSXRayInstrumentExample
Aug 1, 2020
93e39f7
Merge branch 'emitter' into feature/instrument
pokryfka Aug 4, 2020
de28605
Merge branch 'master' into feature/instrument
pokryfka Aug 15, 2020
683ff26
chore: pull changes from swift-tracing
pokryfka Aug 15, 2020
97c63f9
Merge branch 'master' into feature/instrument
pokryfka Aug 15, 2020
bb72833
test: create bootstrapping tests
pokryfka Aug 15, 2020
e317cdd
fix: expose span name
pokryfka Aug 15, 2020
0ac2849
test: test creating span attributes
pokryfka Aug 15, 2020
096b12e
test: update span tests
pokryfka Aug 15, 2020
99bd603
refactor: use instrumented ahc WIP
pokryfka Aug 15, 2020
e09bc8e
Merge branch 'master' into feature/instrument
pokryfka Aug 17, 2020
a0e2109
Bump tracing-instrument to fe80d76
pokryfka Aug 27, 2020
ed287b8
Update AWSXRaySDKExampleAWS to use instrumented AWS SDK
pokryfka Aug 28, 2020
7e93fd8
fix: fix nio convenience method
pokryfka Aug 28, 2020
857c1c3
Merge branch 'fix/nio_future' into feature/instrument
pokryfka Aug 28, 2020
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
20 changes: 16 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.17.0")),
.package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.0.0")),
.package(url: "https://github.com/Flight-School/AnyCodable.git", .upToNextMajor(from: "0.3.0")),
.package(url: "https://github.com/slashmo/gsoc-swift-tracing.git", .branch("main")),
.package(url: "https://github.com/swift-aws/aws-sdk-swift-core.git", .upToNextMinor(from: "5.0.0-alpha.5")),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", .upToNextMajor(from: "0.2.0")),
],
Expand All @@ -28,6 +29,21 @@ let package = Package(
.product(name: "AnyCodable", package: "AnyCodable"),
]
),
.testTarget(
name: "AWSXRayRecorderTests",
dependencies: ["AWSXRayRecorder"]
),
.target(
name: "AWSXRayInstrument",
dependencies: [
.byName(name: "AWSXRayRecorder"),
.product(name: "Instrumentation", package: "gsoc-swift-tracing"),
]
),
.testTarget(
name: "AWSXRayInstrumentTests",
dependencies: ["AWSXRayInstrument"]
),
.target(
name: "AWSXRayRecorderLambda",
dependencies: [
Expand All @@ -42,9 +58,5 @@ let package = Package(
.product(name: "AWSSDKSwiftCore", package: "aws-sdk-swift-core"),
]
),
.testTarget(
name: "AWSXRayRecorderTests",
dependencies: ["AWSXRayRecorder"]
),
]
)
26 changes: 26 additions & 0 deletions Sources/AWSXRayInstrument/Instrument.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import AWSXRayRecorder
import Baggage
import Dispatch
import Instrumentation

extension XRayRecorder: TracingInstrument {
public func extract<Carrier, Extractor>(_ carrier: Carrier, into baggage: inout BaggageContext, using extractor: Extractor) where Carrier == Extractor.Carrier, Extractor: ExtractorProtocol {
// TODO: impl
}

public func inject<Carrier, Injector>(_ baggage: BaggageContext, into carrier: inout Carrier, using injector: Injector) where Carrier == Injector.Carrier, Injector: InjectorProtocol {
// TODO: impl
pokryfka marked this conversation as resolved.
Show resolved Hide resolved
}

public func startSpan(
named operationName: String,
context: BaggageContext,
ofKind kind: SpanKind,
at timestamp: DispatchTime?
) -> Span {
// TODO: parse context, extend existing recorder/segment to use `Baggage`?
pokryfka marked this conversation as resolved.
Show resolved Hide resolved
// TODO: map DispatchTime to Timestamp
pokryfka marked this conversation as resolved.
Show resolved Hide resolved
// TODO: does kind has any meaning?
beginSegment(name: operationName)
}
}
72 changes: 72 additions & 0 deletions Sources/AWSXRayInstrument/Span.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import AWSXRayRecorder
import Baggage
import Dispatch
import Instrumentation

extension XRayRecorder.Segment: Instrumentation.Span {
public var operationName: String {
// TODO: impl
"test"
}

public var kind: SpanKind {
// TODO: impl
.internal
}

public var status: SpanStatus? {
// TODO: impl
get {
nil
}
set(newValue) {}
}

public var startTimestamp: DispatchTime {
// TODO: impl
DispatchTime.now()
}

public var endTimestamp: DispatchTime? {
// TODO: impl
nil
}

public func end(at timestamp: DispatchTime) {
// TODO: impl
}

public var baggage: BaggageContext {
// TODO: impl
BaggageContext()
pokryfka marked this conversation as resolved.
Show resolved Hide resolved
}

public var events: [SpanEvent] {
// TODO: impl
[SpanEvent]()
}

public func addEvent(_: SpanEvent) {
// TODO: impl
}

public var attributes: SpanAttributes {
pokryfka marked this conversation as resolved.
Show resolved Hide resolved
// TODO: impl
get {
SpanAttributes()
}
set(newValue) {}
}

public var isRecording: Bool {
// TODO: impl
true
}

public var links: [SpanLink] {
// not supported
[SpanLink]()
pokryfka marked this conversation as resolved.
Show resolved Hide resolved
}

public func addLink(_: SpanLink) {}
}
29 changes: 29 additions & 0 deletions Tests/AWSXRayInstrumentTests/InstrumentTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import XCTest

import AWSXRayInstrument
import AWSXRayRecorder
import Baggage
import Dispatch
import Instrumentation

final class InstrumentTests: XCTestCase {
func testRecordingOneSegment() {
let emitter = TestEmitter()
let instrument: TracingInstrument = XRayRecorder(emitter: emitter)

XCTAssertEqual(0, emitter.segments.count)

let name: String = UUID().uuidString
let context = BaggageContext()
let kind = SpanKind.internal
let now = DispatchTime.now()

var span: Span = instrument.startSpan(named: name, context: context, ofKind: kind, at: now)

// TODO: test attributes

span.end()

XCTAssertEqual(1, emitter.segments.count)
}
}
23 changes: 23 additions & 0 deletions Tests/AWSXRayInstrumentTests/SpanTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import XCTest

import AWSXRayInstrument
import AWSXRayRecorder
import Instrumentation

final class SpanTests: XCTestCase {
func testRecordingOneSegment() {
let recorder = XRayRecorder(emitter: XRayNoOpEmitter())

let name: String = UUID().uuidString

// use existing "segment" API, make sure the segment is a proper span
var span: Span = recorder.beginSegment(name: name)

XCTAssertEqual(name, span.operationName)
// TODO: more tests

span.end()

// TODO: test end time
}
}
12 changes: 12 additions & 0 deletions Tests/AWSXRayInstrumentTests/TestEmitter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@testable import AWSXRayRecorder

class TestEmitter: XRayEmitter {
var segments = [XRayRecorder.Segment]()

func send(_ segment: XRayRecorder.Segment) {
// TODO: flatten, append subsegments separately
segments.append(segment)
}

func flush(_: @escaping (Error?) -> Void) {}
}