Skip to content

Commit

Permalink
Update CI to match swift-otel (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
slashmo authored Jan 10, 2024
1 parent 2a15f21 commit 36efa25
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 39 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
reviewers:
- "slashmo"
22 changes: 0 additions & 22 deletions .github/workflows/ci.yaml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI
on: [push, pull_request]
jobs:
soundness:
name: Soundness Check
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4.1.0

- name: Bootstrap Mint
uses: irgaly/setup-mint@v1

- name: Run soundness
run: |
scripts/soundness.sh
exit $(git status --porcelain | wc -l)
unit-test:
name: Unit Test
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
swift: [5.9, latest]

steps:
- name: Checkout
uses: actions/checkout@v4.1.0

- name: Cache Swift PM
uses: actions/cache@v3.3.2
with:
path: .build
key: ${{ runner.os }}-${{ matrix.swift }}-spm-${{ hashFiles('Package.swift') }}
restore-keys: ${{ runner.os }}-${{ matrix.swift }}-spm-

- name: Resolve Swift dependencies
run: swift package resolve

- name: Run Unit Tests
run: swift test --parallel
11 changes: 6 additions & 5 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# file options

--swiftversion 5.3
--exclude **/.build
--swiftversion 5.9
--exclude .build
--exclude **/*.pb.swift
--exclude **/*.grpc.swift

# format options

--ifdef no-indent
--extensionacl on-declarations
--indent 4
--patternlet inline
--self remove
--stripunusedargs closure-only
--wraparguments before-first
--extensionacl on-declarations
2 changes: 1 addition & 1 deletion Mintfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nicklockwood/SwiftFormat@0.47.13
nicklockwood/SwiftFormat@0.51.12
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# X-Ray Support for OpenTelemetry Swift

[![CI](https://github.com/slashmo/opentelemetry-swift-xray/actions/workflows/ci.yaml/badge.svg)](https://github.com/slashmo/opentelemetry-swift-xray/actions/workflows/ci.yaml)
[![Swift support](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fslashmo%2Fswift-otel%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/slashmo/swift-otel)
[![CI](https://github.com/slashmo/opentelemetry-swift-xray/actions/workflows/ci.yml/badge.svg)](https://github.com/slashmo/opentelemetry-swift-xray/actions/workflows/ci.yml)
[![Swift support](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fslashmo%2Fswift-otel%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/slashmo/swift-otel-xray)
[![Made for Swift Distributed Tracing](https://img.shields.io/badge/Made%20for-Swift%20Distributed%20Tracing-%23f05137)](https://github.com/apple/swift-distributed-tracing)

This library adds support for [AWS X-Ray](https://aws.amazon.com/xray/) to [OpenTelemetry Swift](https://github.com/slashmo/opentelemetry-swift).
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenTelemetryXRay/MetadataProvider+OTelXRay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ extension Logger.MetadataProvider {
public static func otelXRay(traceIDKey: String = "trace-id", spanIDKey: String = "span-id") -> Logger.MetadataProvider {
.init {
guard let spanContext = ServiceContext.current?.spanContext else { return [:] }

let traceIDBytes = spanContext.traceID.hexBytes
let timestampBytes = traceIDBytes[0 ..< 8]
let randomBytes = traceIDBytes[8...]

return [
traceIDKey: "1-\(String(decoding: timestampBytes, as: UTF8.self))-\(String(decoding: randomBytes, as: UTF8.self))",
spanIDKey: "\(spanContext.spanID)",
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenTelemetryXRay/Propagator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public struct XRayPropagator: OTelPropagator {
)
}

private func extractTraceID<S: StringProtocol>(_ string: S) throws -> OTel.TraceID {
private func extractTraceID(_ string: some StringProtocol) throws -> OTel.TraceID {
let result = try string.utf8.withContiguousStorageIfAvailable { traceIDBytes -> OTel.TraceID in
guard traceIDBytes.count == 35 else {
throw TraceHeaderParsingError(value: String(string), reason: .invalidTraceIDLength(string.count))
Expand Down Expand Up @@ -114,7 +114,7 @@ public struct XRayPropagator: OTelPropagator {
return try result ?? extractTraceID(String(string))
}

private func extractSpanID<S: StringProtocol>(_ string: S) throws -> OTel.SpanID {
private func extractSpanID(_ string: some StringProtocol) throws -> OTel.SpanID {
let result = try string.utf8.withContiguousStorageIfAvailable { spanIDBytes -> OTel.SpanID in
guard spanIDBytes.count == 16 else {
throw TraceHeaderParsingError(value: String(string), reason: .invalidSpanIDLength(spanIDBytes.count))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//===----------------------------------------------------------------------===//
import XCTest

public func XCTAssertThrowsError<E: Error & Equatable, T>(_ expression: @autoclosure () throws -> T, _ error: E) {
public func XCTAssertThrowsError<E: Error & Equatable>(_ expression: @autoclosure () throws -> some Any, _ error: E) {
do {
let value = try expression()
XCTFail("Expected error but received value: \(value)")
Expand Down
8 changes: 4 additions & 4 deletions Tests/OpenTelemetryXRayTests/MetadataProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
//===----------------------------------------------------------------------===//

@testable import Logging
@testable import OpenTelemetryXRay
@testable import OpenTelemetry
@testable import OpenTelemetryXRay
import ServiceContextModule
import XCTest

Expand All @@ -26,7 +26,7 @@ final class MetadataProviderTests: XCTestCase {
let stream = InterceptingStream()
var logger = Logger(label: "test")
logger.handler = StreamLogHandler(label: "test", stream: stream, metadataProvider: .otelXRay)

var generator = XRayIDGenerator()

let spanContext = OTel.SpanContext(
Expand All @@ -44,7 +44,7 @@ final class MetadataProviderTests: XCTestCase {

XCTAssertEqual(stream.strings.count, 1)
let message = try XCTUnwrap(stream.strings.first)

let traceIDBytes = spanContext.traceID.hexBytes
let timestampBytes = traceIDBytes[0 ..< 8]
let randomBytes = traceIDBytes[8...]
Expand Down Expand Up @@ -83,7 +83,7 @@ final class MetadataProviderTests: XCTestCase {

XCTAssertEqual(stream.strings.count, 1)
let message = try XCTUnwrap(stream.strings.first)

let traceIDBytes = spanContext.traceID.hexBytes
let timestampBytes = traceIDBytes[0 ..< 8]
let randomBytes = traceIDBytes[8...]
Expand Down

0 comments on commit 36efa25

Please sign in to comment.