Compare commits

...

No commits in common. "main" and "gh-pages" have entirely different histories.

23 changed files with 705 additions and 1099 deletions

View File

@ -1,22 +0,0 @@
name: CI
on: [push, pull_request]
jobs:
unit-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
images:
- swift:5.7
- swift:5.8
- swiftlang/swift:nightly-main-focal
container: ${{ matrix.images }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Resolve Swift dependencies
run: swift package resolve
- name: Build & Test
run: swift test --parallel

5
.gitignore vendored
View File

@ -1,5 +0,0 @@
.DS_Store
.build/
.swiftpm/
Documentation/
Package.resolved

View File

@ -1,4 +0,0 @@
version: 1
builder:
configs:
- documentation_targets: [OpenTelemetryXRay]

View File

@ -1,13 +0,0 @@
# file options
--swiftversion 5.3
--exclude **/.build
# format options
--ifdef no-indent
--patternlet inline
--self remove
--stripunusedargs closure-only
--wraparguments before-first
--extensionacl on-declarations

View File

@ -1,76 +0,0 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [swifttracing@slashmo.codes](mailto:swifttracing@slashmo.codes).
All complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

View File

@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1 +0,0 @@
nicklockwood/SwiftFormat@0.47.13

View File

@ -1,21 +0,0 @@
// swift-tools-version:5.7
import PackageDescription
let package = Package(
name: "swift-otel-xray",
platforms: [.macOS(.v13)],
products: [
.library(name: "OpenTelemetryXRay", targets: ["OpenTelemetryXRay"]),
],
dependencies: [
.package(url: "https://github.com/slashmo/swift-otel.git", .upToNextMinor(from: "0.8.0")),
],
targets: [
.target(name: "OpenTelemetryXRay", dependencies: [
.product(name: "OpenTelemetry", package: "swift-otel"),
]),
.testTarget(name: "OpenTelemetryXRayTests", dependencies: [
.target(name: "OpenTelemetryXRay"),
]),
]
)

View File

@ -1,20 +0,0 @@
# 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)
[![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).
## Development
### Formatting
To ensure a consitent code style we use [SwiftFormat](https://github.com/nicklockwood/SwiftFormat).
To automatically run it before you push to GitHub, you may define a `pre-push` Git hook executing
the *soundness* script:
```sh
echo './scripts/soundness.sh' > .git/hooks/pre-push
chmod +x .git/hooks/pre-push
```

View File

@ -1,73 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift OpenTelemetry open source project
//
// Copyright (c) 2021 Moritz Lang and the Swift OpenTelemetry project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import struct Dispatch.DispatchWallTime
@_exported import OpenTelemetry
/// Generates trace and span ids using a `RandomNumberGenerator` in an X-Ray compatible format.
///
/// - SeeAlso: [AWS X-Ray: Tracing header](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader)
public struct XRayIDGenerator: OTelIDGenerator {
private let getCurrentSecondsSinceEpoch: () -> UInt32
private var randomNumberGenerator: RandomNumberGenerator
/// Initialize an X-Ray compatible `OTelIDGenerator` backed by the given `RandomNumberGenerator`.
///
/// - Parameter randomNumberGenerator: The `RandomNumberGenerator` to use, defaults to a `SystemRandomNumberGenerator`.
public init(randomNumberGenerator: RandomNumberGenerator = SystemRandomNumberGenerator()) {
self.init(
randomNumberGenerator: randomNumberGenerator,
getCurrentSecondsSinceEpoch: {
DispatchWallTime.now().secondsSinceEpoch
}
)
}
init(randomNumberGenerator: RandomNumberGenerator, getCurrentSecondsSinceEpoch: @escaping () -> UInt32) {
self.randomNumberGenerator = randomNumberGenerator
self.getCurrentSecondsSinceEpoch = getCurrentSecondsSinceEpoch
}
public mutating func generateTraceID() -> OTel.TraceID {
var traceIDBytes: OTel.TraceID.Bytes = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
withUnsafeMutableBytes(of: &traceIDBytes) { ptr in
ptr.storeBytes(of: self.getCurrentSecondsSinceEpoch().bigEndian, as: UInt32.self)
ptr.storeBytes(
of: randomNumberGenerator.next(upperBound: UInt32.max).bigEndian,
toByteOffset: 4,
as: UInt32.self
)
ptr.storeBytes(
of: randomNumberGenerator.next(upperBound: UInt64.max).bigEndian,
toByteOffset: 8,
as: UInt64.self
)
}
return OTel.TraceID(bytes: traceIDBytes)
}
public mutating func generateSpanID() -> OTel.SpanID {
var spanIDBytes: OTel.SpanID.Bytes = (0, 0, 0, 0, 0, 0, 0, 0)
withUnsafeMutableBytes(of: &spanIDBytes) { ptr in
ptr.storeBytes(of: randomNumberGenerator.next().bigEndian, as: UInt64.self)
}
return OTel.SpanID(bytes: spanIDBytes)
}
}
extension DispatchWallTime {
fileprivate var secondsSinceEpoch: UInt32 {
let seconds = Int64(bitPattern: self.rawValue) / -1_000_000_000
return UInt32(seconds)
}
}

View File

@ -1,149 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift OpenTelemetry open source project
//
// Copyright (c) 2021 Moritz Lang and the Swift OpenTelemetry project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import Instrumentation
@_exported import OpenTelemetry
/// An `OTelPropagator` that propagates span context through the `X-Amzn-Trace-Id` header.
///
/// - SeeAlso: [AWS X-Ray: Tracing Header](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader)
public struct XRayPropagator: OTelPropagator {
private static let tracingHeader = "X-Amzn-Trace-Id"
/// Initialize an X-Ray compatible propagator.
public init() {}
public func inject<Carrier, Inject>(
_ spanContext: OTel.SpanContext,
into carrier: inout Carrier,
using injector: Inject
) where Inject: Injector, Carrier == Inject.Carrier {
let traceIDBytes = spanContext.traceID.hexBytes
let timestampBytes = traceIDBytes[0 ..< 8]
let randomBytes = traceIDBytes[8...]
let tracingHeader = [
"Root=1-\(String(decoding: timestampBytes, as: UTF8.self))-\(String(decoding: randomBytes, as: UTF8.self))",
"Parent=\(spanContext.spanID)",
"Sampled=\(spanContext.traceFlags.contains(.sampled) ? "1" : "0")",
].joined(separator: ";")
injector.inject(tracingHeader, forKey: Self.tracingHeader, into: &carrier)
}
public func extractSpanContext<Carrier, Extract>(
from carrier: Carrier,
using extractor: Extract
) throws -> OTel.SpanContext? where Extract: Extractor, Carrier == Extract.Carrier {
guard let tracingHeader = extractor.extract(key: Self.tracingHeader, from: carrier) else {
return nil
}
var extractedTraceID: OTel.TraceID?
var spanID: OTel.SpanID?
var extractedTraceFlags: OTel.TraceFlags?
let parts = tracingHeader.split(separator: ";")
var iterator = parts.makeIterator()
while let part = iterator.next() {
if part.starts(with: "Root=") {
let startIndex = part.index(part.startIndex, offsetBy: 5)
extractedTraceID = try extractTraceID(part[startIndex...])
} else if part.starts(with: "Parent=") {
let startIndex = part.index(part.startIndex, offsetBy: 7)
spanID = try extractSpanID(part[startIndex...])
} else if part.starts(with: "Sampled=") {
let startIndex = part.index(part.startIndex, offsetBy: 8)
let sampledString = part[startIndex...]
extractedTraceFlags = sampledString == "1" ? .sampled : []
}
}
guard let traceID = extractedTraceID else {
throw TraceHeaderParsingError(value: tracingHeader, reason: .missingTraceID)
}
return OTel.SpanContext(
traceID: traceID,
spanID: spanID ?? OTel.SpanID(bytes: (0, 0, 0, 0, 0, 0, 0, 0)),
traceFlags: extractedTraceFlags ?? [],
isRemote: true
)
}
private func extractTraceID<S: StringProtocol>(_ string: S) 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))
}
guard traceIDBytes[0] == UInt8(ascii: "1") else {
throw TraceHeaderParsingError(
value: String(string),
reason: .unsupportedTraceIDVersion(String(string[string.startIndex]))
)
}
guard traceIDBytes[1] == UInt8(ascii: "-"), traceIDBytes[10] == UInt8(ascii: "-") else {
throw TraceHeaderParsingError(value: String(string), reason: .invalidTraceIDDelimiters)
}
var traceIDStorage: OTel.TraceID.Bytes = (
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
)
withUnsafeMutableBytes(of: &traceIDStorage) { ptr in
let timestampRegion = UnsafeMutableRawBufferPointer(rebasing: ptr[0 ..< 4])
let randomRegion = UnsafeMutableRawBufferPointer(rebasing: ptr[4...])
OTel.Hex.convert(traceIDBytes[2 ..< 10], toBytes: timestampRegion)
OTel.Hex.convert(traceIDBytes[11 ..< 35], toBytes: randomRegion)
}
return OTel.TraceID(bytes: traceIDStorage)
}
return try result ?? extractTraceID(String(string))
}
private func extractSpanID<S: StringProtocol>(_ string: S) 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))
}
var bytes: OTel.SpanID.Bytes = (0, 0, 0, 0, 0, 0, 0, 0)
withUnsafeMutableBytes(of: &bytes) { ptr in
OTel.Hex.convert(spanIDBytes, toBytes: ptr)
}
return OTel.SpanID(bytes: bytes)
}
return try result ?? extractSpanID(String(string))
}
}
extension XRayPropagator {
public struct TraceHeaderParsingError: Error, Equatable {
public let value: String
public let reason: Reason
}
}
extension XRayPropagator.TraceHeaderParsingError {
public enum Reason: Equatable {
case missingTraceID
case invalidTraceIDLength(Int)
case unsupportedTraceIDVersion(String)
case invalidTraceIDDelimiters
case invalidSpanIDLength(Int)
}
}

View File

@ -1,26 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift OpenTelemetry open source project
//
// Copyright (c) 2021 Moritz Lang and the Swift OpenTelemetry project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import XCTest
public func XCTAssertThrowsError<E: Error & Equatable, T>(_ expression: @autoclosure () throws -> T, _ error: E) {
do {
let value = try expression()
XCTFail("Expected error but received value: \(value)")
} catch let actualError {
guard let e = actualError as? E else {
XCTFail("Expected \(type(of: E.self)), but received \(type(of: actualError))")
return
}
XCTAssertEqual(e, error)
}
}

View File

@ -1,97 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift OpenTelemetry open source project
//
// Copyright (c) 2021 Moritz Lang and the Swift OpenTelemetry project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
@testable import OpenTelemetryXRay
import XCTest
final class XRayIDGeneratorTests: XCTestCase {
func test_generatesRandomTraceID() {
var idGenerator = XRayIDGenerator(
randomNumberGenerator: ConstantNumberGenerator(value: .max),
getCurrentSecondsSinceEpoch: { 1_616_064_590 }
)
let maxTraceID = idGenerator.generateTraceID()
XCTAssertEqual(
maxTraceID,
OTel.TraceID(bytes: (96, 83, 48, 78, 255, 255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 254))
)
}
func test_generatesRandomTraceID_withRandomNumberGenerator() {
var idGenerator = XRayIDGenerator(
randomNumberGenerator: ConstantNumberGenerator(value: .random(in: 0 ..< .max)),
getCurrentSecondsSinceEpoch: { 1_616_064_590 }
)
let randomTraceID = idGenerator.generateTraceID()
XCTAssertTrue(
randomTraceID.description.starts(with: "6053304e"),
"X-Ray trace ids must start with the current timestamp."
)
}
func test_generatesUniqueTraceIDs() {
var idGenerator = XRayIDGenerator()
var traceIDs = Set<OTel.TraceID>()
for _ in 0 ..< 1000 {
traceIDs.insert(idGenerator.generateTraceID())
}
XCTAssertEqual(traceIDs.count, 1000, "Generating 1000 X-Ray trace ids should result in 1000 unique trace ids.")
}
func test_generatesRandomSpanID() {
var idGenerator = XRayIDGenerator(randomNumberGenerator: ConstantNumberGenerator(value: .max))
let maxSpanID = idGenerator.generateSpanID()
XCTAssertEqual(
maxSpanID,
OTel.SpanID(bytes: (255, 255, 255, 255, 255, 255, 255, 255))
)
}
func test_generatesRandomSpanID_withRandomNumberGenerator() {
let randomValue = UInt64.random(in: 0 ..< .max)
let randomHexString = String(randomValue, radix: 16, uppercase: false)
let hexString = randomHexString.count == 16 ? randomHexString : "0\(randomHexString)"
var idGenerator = XRayIDGenerator(randomNumberGenerator: ConstantNumberGenerator(value: randomValue))
let randomSpanID = idGenerator.generateSpanID()
XCTAssertEqual(randomSpanID.description, hexString)
}
func test_generatesUniqueSpanIDs() {
var idGenerator = XRayIDGenerator()
var spanIDs = Set<OTel.SpanID>()
for _ in 0 ..< 1000 {
spanIDs.insert(idGenerator.generateSpanID())
}
XCTAssertEqual(spanIDs.count, 1000, "Generating 1000 span ids should result in 1000 unique span ids.")
}
}
private struct ConstantNumberGenerator: RandomNumberGenerator {
let value: UInt64
func next() -> UInt64 {
value
}
}

View File

@ -1,211 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift OpenTelemetry open source project
//
// Copyright (c) 2021 Moritz Lang and the Swift OpenTelemetry project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import Instrumentation
@testable import OpenTelemetryXRay
import XCTest
final class XRayPropagatorTests: XCTestCase {
private let propagator = XRayPropagator()
private let injector = DictionaryInjector()
private let extractor = DictionaryExtractor()
// MARK: - Inject
func test_injectsTraceparentHeader_notSampled() {
let spanContext = OTel.SpanContext(
traceID: OTel.TraceID(bytes: (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)),
spanID: OTel.SpanID(bytes: (1, 2, 3, 4, 5, 6, 7, 8)),
traceFlags: [],
isRemote: false
)
var headers = [String: String]()
propagator.inject(spanContext, into: &headers, using: injector)
XCTAssertEqual(
headers,
["X-Amzn-Trace-Id": "Root=1-01020304-05060708090a0b0c0d0e0f10;Parent=0102030405060708;Sampled=0"]
)
}
func test_injectsTraceparentHeader_sampled() {
let spanContext = OTel.SpanContext(
traceID: OTel.TraceID(bytes: (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)),
spanID: OTel.SpanID(bytes: (1, 2, 3, 4, 5, 6, 7, 8)),
traceFlags: .sampled,
isRemote: false
)
var headers = [String: String]()
propagator.inject(spanContext, into: &headers, using: injector)
XCTAssertEqual(
headers,
["X-Amzn-Trace-Id": "Root=1-01020304-05060708090a0b0c0d0e0f10;Parent=0102030405060708;Sampled=1"]
)
}
// MARK: - Extract
func test_extractsNil_withoutTracingHeader() throws {
let headers = ["Content-Type": "application/json"]
XCTAssertNil(try propagator.extractSpanContext(from: headers, using: extractor))
}
func test_extractsTracingHeader_notSampled() throws {
let headers = [
"X-Amzn-Trace-Id": "Root=1-5759e988-bd862e3fe1be46a994272793;Sampled=0",
]
let spanContext = try XCTUnwrap(propagator.extractSpanContext(from: headers, using: extractor))
XCTAssertEqual(spanContext.traceID.description, "5759e988bd862e3fe1be46a994272793")
XCTAssertEqual(spanContext.spanID.description, "0000000000000000")
XCTAssertTrue(spanContext.traceFlags.isEmpty)
XCTAssertNil(spanContext.traceState)
}
func test_extractsTracingHeader_sampled() throws {
let headers = [
"X-Amzn-Trace-Id": "Root=1-5759e988-bd862e3fe1be46a994272793;Sampled=1",
]
let spanContext = try XCTUnwrap(propagator.extractSpanContext(from: headers, using: extractor))
XCTAssertEqual(spanContext.traceID.description, "5759e988bd862e3fe1be46a994272793")
XCTAssertEqual(spanContext.spanID.description, "0000000000000000")
XCTAssertEqual(spanContext.traceFlags, .sampled)
XCTAssertNil(spanContext.traceState)
}
func test_extractsTracingHeader_notSampled_withParent() throws {
let headers = [
"X-Amzn-Trace-Id": "Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=0",
]
let spanContext = try XCTUnwrap(propagator.extractSpanContext(from: headers, using: extractor))
XCTAssertEqual(spanContext.traceID.description, "5759e988bd862e3fe1be46a994272793")
XCTAssertEqual(spanContext.spanID.description, "53995c3f42cd8ad8")
XCTAssertTrue(spanContext.traceFlags.isEmpty)
XCTAssertNil(spanContext.traceState)
}
func test_extractsTracingHeader_sampled_withParent() throws {
let headers = [
"X-Amzn-Trace-Id": "Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1",
]
let spanContext = try XCTUnwrap(propagator.extractSpanContext(from: headers, using: extractor))
XCTAssertEqual(spanContext.traceID.description, "5759e988bd862e3fe1be46a994272793")
XCTAssertEqual(spanContext.spanID.description, "53995c3f42cd8ad8")
XCTAssertEqual(spanContext.traceFlags, .sampled)
XCTAssertNil(spanContext.traceState)
}
func test_extractFails_missingTraceID() throws {
let headers = ["X-Amzn-Trace-Id": "Root=1-123-456;Sampled=1"]
XCTAssertThrowsError(
try propagator.extractSpanContext(from: headers, using: extractor),
XRayPropagator.TraceHeaderParsingError(value: "1-123-456", reason: .invalidTraceIDLength(9))
)
}
func test_extractsTracingHeader_missingSampleDecision() throws {
let tracingHeader = "Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8"
let headers = ["X-Amzn-Trace-Id": tracingHeader]
let spanContext = try XCTUnwrap(propagator.extractSpanContext(from: headers, using: extractor))
XCTAssertEqual(spanContext.traceID.description, "5759e988bd862e3fe1be46a994272793")
XCTAssertEqual(spanContext.spanID.description, "53995c3f42cd8ad8")
XCTAssertTrue(spanContext.traceFlags.isEmpty)
XCTAssertNil(spanContext.traceState)
}
func test_extractFails_invalidTraceIDLength() throws {
let tracingHeader = "Parent=53995c3f42cd8ad8;Sampled=1"
let headers = ["X-Amzn-Trace-Id": tracingHeader]
XCTAssertThrowsError(
try propagator.extractSpanContext(from: headers, using: extractor),
XRayPropagator.TraceHeaderParsingError(value: tracingHeader, reason: .missingTraceID)
)
}
func test_extractFails_unsupportedTraceIDVersion() throws {
let traceID = "2-5759e988-bd862e3fe1be46a994272793"
let headers = ["X-Amzn-Trace-Id": "Root=\(traceID);Sampled=1"]
XCTAssertThrowsError(
try propagator.extractSpanContext(from: headers, using: extractor),
XRayPropagator.TraceHeaderParsingError(value: traceID, reason: .unsupportedTraceIDVersion("2"))
)
}
func test_extractFails_invalidTraceIDDelimiters() throws {
let traceID = "1_5759e988*bd862e3fe1be46a994272793"
let headers = ["X-Amzn-Trace-Id": "Root=\(traceID);Sampled=1"]
XCTAssertThrowsError(
try propagator.extractSpanContext(from: headers, using: extractor),
XRayPropagator.TraceHeaderParsingError(value: traceID, reason: .invalidTraceIDDelimiters)
)
}
func test_extractFails_invalidSpanIDLength() throws {
let tracingHeader = "Root=1-5759e988-bd862e3fe1be46a994272793;Parent=short;Sampled=1"
let headers = ["X-Amzn-Trace-Id": tracingHeader]
XCTAssertThrowsError(
try propagator.extractSpanContext(from: headers, using: extractor),
XRayPropagator.TraceHeaderParsingError(value: "short", reason: .invalidSpanIDLength(5))
)
}
// MARK: - End To End
func test_injectExtractedSpanContext() throws {
let headers = [
"X-Amzn-Trace-Id": "Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1",
]
let extractedSpanContext = try XCTUnwrap(propagator.extractSpanContext(from: headers, using: extractor))
var injectedHeaders = [String: String]()
propagator.inject(extractedSpanContext, into: &injectedHeaders, using: injector)
XCTAssertEqual(injectedHeaders["X-Amzn-Trace-Id"], headers["X-Amzn-Trace-Id"])
}
}
private struct DictionaryInjector: Injector {
init() {}
func inject(_ value: String, forKey key: String, into carrier: inout [String: String]) {
carrier[key] = value
}
}
private struct DictionaryExtractor: Extractor {
init() {}
func extract(key: String, from carrier: [String: String]) -> String? {
carrier[key]
}
}

165
XRayIDGenerator/index.html Normal file
View File

@ -0,0 +1,165 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OpenTelemetry Swift X-Ray - XRayIDGenerator</title>
<link rel="stylesheet" type="text/css" href="/opentelemetry-swift-xray/all.css" media="all" />
</head>
<body>
<header>
<a href="/opentelemetry-swift-xray/">
<strong>
OpenTelemetry Swift X-Ray
</strong>
<span>Documentation</span>
</a>
</header>
<!--
<form class="search">
<input type="search" placeholder="Search" />
</form>
-->
<nav>
<div class="wrapper">
<h2>On This Page</h2>
<ol><li><a href="#relationships">Relationships</a><ul><li><a href="#relationships">Conforms To</a></li></ul></li><li><a href="#initializers">Initializers</a><ul><li class="initializer"><a href="#xrayidgenerator.init(randomnumbergenerator:)">init(randomNumberGenerator:)</a></li></ul></li><li><a href="#methods">Methods</a><ul><li class="function"><a href="#xrayidgenerator.generatetraceid()">generateTraceID()</a></li><li class="function"><a href="#xrayidgenerator.generatespanid()">generateSpanID()</a></li></ul></li></ol>
</div>
</nav>
<main>
<article>
<h1>
<small>Structure</small>
<code class="name">XRayIDGenerator</code>
</h1>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="keyword">struct</span> <span class="type">XRayIDGenerator</span>: <span class="type">OTelIDGenerator</span> </body></html></code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Generates trace and span ids using a <code>RandomNumberGenerator</code> in an X-Ray compatible format.</p>
</div>
<div class="discussion">
<aside class="see also" title="See Also">
<p><a href="https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader">AWS X-Ray: Tracing header</a></p>
</aside>
</div>
<section id="relationships">
<h2 hidden>Relationships</h2>
<figure>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.40.1 (20161225.0304)
-->
<!-- Title: %3 Pages: 1 -->
<svg width="872pt" height="116pt"
viewBox="0.00 0.00 872.00 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
<title>%3</title>
<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-112 868,-112 868,4 -4,4"/>
<!-- XRayIDGenerator -->
<g id="node1" class="node structure current">
<title>XRayIDGenerator</title>
<g id="a_node1"><a xlink:href="/opentelemetry-swift-xray/XRayIDGenerator" xlink:title="XRayIDGenerator">
<path fill="none" stroke="#000000" stroke-width="3" d="M528,-108C528,-108 336,-108 336,-108 330,-108 324,-102 324,-96 324,-96 324,-84 324,-84 324,-78 330,-72 336,-72 336,-72 528,-72 528,-72 534,-72 540,-78 540,-84 540,-84 540,-96 540,-96 540,-102 534,-108 528,-108"/>
<text text-anchor="middle" x="432" y="-86.3" font-family="Menlo" font-size="14.00" fill="#000000">XRayIDGenerator</text>
</a>
</g>
</g>
<!-- OTelIDGenerator -->
<g id="node2" class="node unknown">
<title>OTelIDGenerator</title>
<path fill="none" stroke="#000000" d="M528,-36C528,-36 336,-36 336,-36 330,-36 324,-30 324,-24 324,-24 324,-12 324,-12 324,-6 330,0 336,0 336,0 528,0 528,0 534,0 540,-6 540,-12 540,-12 540,-24 540,-24 540,-30 534,-36 528,-36"/>
<text text-anchor="middle" x="432" y="-14.3" font-family="Menlo" font-size="14.00" fill="#000000">OTelIDGenerator</text>
</g>
<!-- XRayIDGenerator&#45;&gt;OTelIDGenerator -->
<g id="edge1" class="edge conformsTo">
<title>XRayIDGenerator&#45;&gt;OTelIDGenerator</title>
<path fill="none" stroke="#000000" d="M432,-71.8314C432,-64.131 432,-54.9743 432,-46.4166"/>
<polygon fill="#000000" stroke="#000000" points="435.5001,-46.4132 432,-36.4133 428.5001,-46.4133 435.5001,-46.4132"/>
</g>
</g>
</svg>
<figcaption hidden>Inheritance graph for XRayIDGenerator.</figcaption>
</figure>
<h3>Conforms To</h3>
<dl>
<dt class="unknown"><code>OTelIDGenerator</code></dt>
</dl>
</section>
<section id="initializers">
<h2>Initializers</h2>
<div role="article" class="initializer" id="xrayidgenerator.init(randomnumbergenerator:)">
<h3>
<code><a href="#xrayidgenerator.init(randomnumbergenerator:)">init(randomNumberGenerator:)</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="keyword">init</span>(<span class="variable">randomNumberGenerator</span>: <span class="type">RandomNumberGenerator</span> = <span class="variable">SystemRandomNumberGenerator</span>()) </body></html></code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Initialize an X-Ray compatible <code>OTelIDGenerator</code> backed by the given <code>RandomNumberGenerator</code>.</p>
</div>
<h4>Parameters</h4>
<table class="parameters">
<thead hidden>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<th>randomNumberGenerator</th>
<td><code class="type">RandomNumberGenerator</code></td>
<td><p>The <code>RandomNumberGenerator</code> to use, defaults to a <code>SystemRandomNumberGenerator</code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="methods">
<h2>Methods</h2>
<div role="article" class="function" id="xrayidgenerator.generatetraceid()">
<h3>
<code><a href="#xrayidgenerator.generatetraceid()">generateTraceID()</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="attribute">mutating</span> <span class="keyword">func</span> <span class="function">generateTraceID</span>() -&gt; <span class="type">OTel</span>.<span class="type">TraceID</span> </body></html></code></pre>
</div>
</div>
<div role="article" class="function" id="xrayidgenerator.generatespanid()">
<h3>
<code><a href="#xrayidgenerator.generatespanid()">generateSpanID()</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="attribute">mutating</span> <span class="keyword">func</span> <span class="function">generateSpanID</span>() -&gt; <span class="type">OTel</span>.<span class="type">SpanID</span> </body></html></code></pre>
</div>
</div>
</section>
</article>
</main>
<footer>
<p>
Generated on <time datetime="2023-05-07T07:50:39+0000">May 7, 2023</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a> <span class="version">1.0.0-rc.1</span>.
</p>
</footer>
</body>
</html>

158
XRayPropagator/index.html Normal file
View File

@ -0,0 +1,158 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OpenTelemetry Swift X-Ray - XRayPropagator</title>
<link rel="stylesheet" type="text/css" href="/opentelemetry-swift-xray/all.css" media="all" />
</head>
<body>
<header>
<a href="/opentelemetry-swift-xray/">
<strong>
OpenTelemetry Swift X-Ray
</strong>
<span>Documentation</span>
</a>
</header>
<!--
<form class="search">
<input type="search" placeholder="Search" />
</form>
-->
<nav>
<div class="wrapper">
<h2>On This Page</h2>
<ol><li><a href="#relationships">Relationships</a><ul><li><a href="#relationships">Nested Types</a></li><li><a href="#relationships">Conforms To</a></li></ul></li><li><a href="#initializers">Initializers</a><ul><li class="initializer"><a href="#xraypropagator.init()">init()</a></li></ul></li><li><a href="#methods">Methods</a><ul><li class="function"><a href="#xraypropagator.inject(_:into:using:)">inject(_:into:using:)</a></li><li class="function"><a href="#xraypropagator.extractspancontext(from:using:)">extractSpanContext(from:using:)</a></li></ul></li></ol>
</div>
</nav>
<main>
<article>
<h1>
<small>Structure</small>
<code class="name">XRayPropagator</code>
</h1>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="keyword">struct</span> <span class="type">XRayPropagator</span>: <span class="type">OTelPropagator</span> </body></html></code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>An <code>OTelPropagator</code> that propagates span context through the <code>X-Amzn-Trace-Id</code> header.</p>
</div>
<div class="discussion">
<aside class="see also" title="See Also">
<p><a href="https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader">AWS X-Ray: Tracing Header</a></p>
</aside>
</div>
<section id="relationships">
<h2 hidden>Relationships</h2>
<figure>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.40.1 (20161225.0304)
-->
<!-- Title: %17 Pages: 1 -->
<svg width="872pt" height="116pt"
viewBox="0.00 0.00 872.00 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
<title>%17</title>
<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-112 868,-112 868,4 -4,4"/>
<!-- XRayPropagator -->
<g id="node1" class="node structure current">
<title>XRayPropagator</title>
<g id="a_node1"><a xlink:href="/opentelemetry-swift-xray/XRayPropagator" xlink:title="XRayPropagator">
<path fill="none" stroke="#000000" stroke-width="3" d="M528,-108C528,-108 336,-108 336,-108 330,-108 324,-102 324,-96 324,-96 324,-84 324,-84 324,-78 330,-72 336,-72 336,-72 528,-72 528,-72 534,-72 540,-78 540,-84 540,-84 540,-96 540,-96 540,-102 534,-108 528,-108"/>
<text text-anchor="middle" x="432" y="-86.3" font-family="Menlo" font-size="14.00" fill="#000000">XRayPropagator</text>
</a>
</g>
</g>
<!-- OTelPropagator -->
<g id="node2" class="node unknown">
<title>OTelPropagator</title>
<path fill="none" stroke="#000000" d="M528,-36C528,-36 336,-36 336,-36 330,-36 324,-30 324,-24 324,-24 324,-12 324,-12 324,-6 330,0 336,0 336,0 528,0 528,0 534,0 540,-6 540,-12 540,-12 540,-24 540,-24 540,-30 534,-36 528,-36"/>
<text text-anchor="middle" x="432" y="-14.3" font-family="Menlo" font-size="14.00" fill="#000000">OTelPropagator</text>
</g>
<!-- XRayPropagator&#45;&gt;OTelPropagator -->
<g id="edge1" class="edge conformsTo">
<title>XRayPropagator&#45;&gt;OTelPropagator</title>
<path fill="none" stroke="#000000" d="M432,-71.8314C432,-64.131 432,-54.9743 432,-46.4166"/>
<polygon fill="#000000" stroke="#000000" points="435.5001,-46.4132 432,-36.4133 428.5001,-46.4133 435.5001,-46.4132"/>
</g>
</g>
</svg>
<figcaption hidden>Inheritance graph for XRayPropagator.</figcaption>
</figure>
<h3>Nested Types</h3>
<dl>
<dt class="structure"><code><a href="/opentelemetry-swift-xray/XRayPropagator_TraceHeaderParsingError">XRayPropagator.TraceHeaderParsingError</a></code></dt>
<dd></dd>
</dl>
<h3>Conforms To</h3>
<dl>
<dt class="unknown"><code>OTelPropagator</code></dt>
</dl>
</section>
<section id="initializers">
<h2>Initializers</h2>
<div role="article" class="initializer" id="xraypropagator.init()">
<h3>
<code><a href="#xraypropagator.init()">init()</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="keyword">init</span>() </body></html></code></pre>
</div>
<div class="summary" role="doc-abstract">
<p>Initialize an X-Ray compatible propagator.</p>
</div>
</div>
</section>
<section id="methods">
<h2>Methods</h2>
<div role="article" class="function" id="xraypropagator.inject(_:into:using:)">
<h3>
<code><a href="#xraypropagator.inject(_:into:using:)">inject(_:into:using:)</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">inject</span>&lt;<span class="variable">Carrier</span>, <span class="variable">Inject</span>&gt;(
<span class="keyword">_</span> <span class="variable">spanContext</span>: <span class="type">OTel</span>.<span class="type">SpanContext</span>,
<span class="variable">into</span> <span class="variable">carrier</span>: <span class="keyword">inout</span> <span class="type">Carrier</span>,
<span class="variable">using</span> <span class="variable">injector</span>: <span class="type">Inject</span>
) <span class="keyword">where</span> <span class="type">Inject</span>: <span class="type">Injector</span>, <span class="type">Carrier</span> == <span class="type">Inject</span>.<span class="type">Carrier</span> </body></html></code></pre>
</div>
</div>
<div role="article" class="function" id="xraypropagator.extractspancontext(from:using:)">
<h3>
<code><a href="#xraypropagator.extractspancontext(from:using:)">extractSpanContext(from:using:)</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="keyword">func</span> <span class="function">extractSpanContext</span>&lt;<span class="variable">Carrier</span>, <span class="variable">Extract</span>&gt;(
<span class="variable">from</span> <span class="variable">carrier</span>: <span class="type">Carrier</span>,
<span class="variable">using</span> <span class="variable">extractor</span>: <span class="type">Extract</span>
) <span class="keyword">throws</span> -&gt; <span class="type">OTel</span>.<span class="type">SpanContext</span>? <span class="keyword">where</span> <span class="type">Extract</span>: <span class="type">Extractor</span>, <span class="type">Carrier</span> == <span class="type">Extract</span>.<span class="type">Carrier</span> </body></html></code></pre>
</div>
</div>
</section>
</article>
</main>
<footer>
<p>
Generated on <time datetime="2023-05-07T07:50:39+0000">May 7, 2023</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a> <span class="version">1.0.0-rc.1</span>.
</p>
</footer>
</body>
</html>

View File

@ -0,0 +1,144 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OpenTelemetry Swift X-Ray - XRayPropagator.TraceHeaderParsingError</title>
<link rel="stylesheet" type="text/css" href="/opentelemetry-swift-xray/all.css" media="all" />
</head>
<body>
<header>
<a href="/opentelemetry-swift-xray/">
<strong>
OpenTelemetry Swift X-Ray
</strong>
<span>Documentation</span>
</a>
</header>
<!--
<form class="search">
<input type="search" placeholder="Search" />
</form>
-->
<nav>
<div class="wrapper">
<h2>On This Page</h2>
<ol><li><a href="#relationships">Relationships</a><ul><li><a href="#relationships">Member Of</a></li><li><a href="#relationships">Nested Types</a></li><li><a href="#relationships">Conforms To</a></li></ul></li><li><a href="#properties">Properties</a><ul><li class="variable"><a href="#xraypropagator.traceheaderparsingerror.value">value</a></li><li class="variable"><a href="#xraypropagator.traceheaderparsingerror.reason">reason</a></li></ul></li></ol>
</div>
</nav>
<main>
<article>
<h1>
<small>Structure</small>
<code class="name">XRayPropagator.TraceHeaderParsingError</code>
</h1>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="keyword">struct</span> <span class="type">TraceHeaderParsingError</span>: <span class="type">Error</span>, <span class="type">Equatable</span> </body></html></code></pre>
</div>
<section id="relationships">
<h2 hidden>Relationships</h2>
<figure>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.40.1 (20161225.0304)
-->
<!-- Title: %7 Pages: 1 -->
<svg width="872pt" height="116pt"
viewBox="0.00 0.00 872.00 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
<title>%7</title>
<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-112 868,-112 868,4 -4,4"/>
<!-- XRayPropagator.TraceHeaderParsingError -->
<g id="node1" class="node structure current">
<title>XRayPropagator.TraceHeaderParsingError</title>
<g id="a_node1"><a xlink:href="/opentelemetry-swift-xray/XRayPropagator_TraceHeaderParsingError" xlink:title="XRayPropagator.TraceHeaderParsingError">
<path fill="none" stroke="#000000" stroke-width="3" d="M577,-108C577,-108 287,-108 287,-108 281,-108 275,-102 275,-96 275,-96 275,-84 275,-84 275,-78 281,-72 287,-72 287,-72 577,-72 577,-72 583,-72 589,-78 589,-84 589,-84 589,-96 589,-96 589,-102 583,-108 577,-108"/>
<text text-anchor="middle" x="432" y="-86.3" font-family="Menlo" font-size="14.00" fill="#000000">XRayPropagator.TraceHeaderParsingError</text>
</a>
</g>
</g>
<!-- Equatable -->
<g id="node2" class="node unknown">
<title>Equatable</title>
<path fill="none" stroke="#000000" d="M303,-36C303,-36 111,-36 111,-36 105,-36 99,-30 99,-24 99,-24 99,-12 99,-12 99,-6 105,0 111,0 111,0 303,0 303,0 309,0 315,-6 315,-12 315,-12 315,-24 315,-24 315,-30 309,-36 303,-36"/>
<text text-anchor="middle" x="207" y="-14.3" font-family="Menlo" font-size="14.00" fill="#000000">Equatable</text>
</g>
<!-- XRayPropagator.TraceHeaderParsingError&#45;&gt;Equatable -->
<g id="edge1" class="edge conformsTo">
<title>XRayPropagator.TraceHeaderParsingError&#45;&gt;Equatable</title>
<path fill="none" stroke="#000000" d="M375.5134,-71.9243C344.4871,-61.9959 305.8297,-49.6255 273.3694,-39.2382"/>
<polygon fill="#000000" stroke="#000000" points="274.1008,-35.7975 263.5098,-36.0831 271.9673,-42.4645 274.1008,-35.7975"/>
</g>
<!-- Error -->
<g id="node3" class="node unknown">
<title>Error</title>
<path fill="none" stroke="#000000" d="M753,-36C753,-36 561,-36 561,-36 555,-36 549,-30 549,-24 549,-24 549,-12 549,-12 549,-6 555,0 561,0 561,0 753,0 753,0 759,0 765,-6 765,-12 765,-12 765,-24 765,-24 765,-30 759,-36 753,-36"/>
<text text-anchor="middle" x="657" y="-14.3" font-family="Menlo" font-size="14.00" fill="#000000">Error</text>
</g>
<!-- XRayPropagator.TraceHeaderParsingError&#45;&gt;Error -->
<g id="edge2" class="edge conformsTo">
<title>XRayPropagator.TraceHeaderParsingError&#45;&gt;Error</title>
<path fill="none" stroke="#000000" d="M488.4866,-71.9243C519.5129,-61.9959 558.1703,-49.6255 590.6306,-39.2382"/>
<polygon fill="#000000" stroke="#000000" points="592.0327,-42.4645 600.4902,-36.0831 589.8992,-35.7975 592.0327,-42.4645"/>
</g>
</g>
</svg>
<figcaption hidden>Inheritance graph for XRayPropagator.TraceHeaderParsingError.</figcaption>
</figure>
<h3>Member Of</h3>
<dl>
<dt class="structure"><code><a href="/opentelemetry-swift-xray/XRayPropagator">XRayPropagator</a></code></dt>
<dd><p>An <code>OTelPropagator</code> that propagates span context through the <code>X-Amzn-Trace-Id</code> header.</p>
</dd>
</dl>
<h3>Nested Types</h3>
<dl>
<dt class="enumeration"><code><a href="/opentelemetry-swift-xray/XRayPropagator_TraceHeaderParsingError_Reason">XRayPropagator.TraceHeaderParsingError.Reason</a></code></dt>
<dd></dd>
</dl>
<h3>Conforms To</h3>
<dl>
<dt class="unknown"><code>Equatable</code></dt>
<dt class="unknown"><code>Error</code></dt>
</dl>
</section>
<section id="properties">
<h2>Properties</h2>
<div role="article" class="variable" id="xraypropagator.traceheaderparsingerror.value">
<h3>
<code><a href="#xraypropagator.traceheaderparsingerror.value">value</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="keyword">let</span> <span class="variable">value</span>: <span class="type">String</span></body></html></code></pre>
</div>
</div>
<div role="article" class="variable" id="xraypropagator.traceheaderparsingerror.reason">
<h3>
<code><a href="#xraypropagator.traceheaderparsingerror.reason">reason</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="keyword">let</span> <span class="variable">reason</span>: <span class="type">Reason</span></body></html></code></pre>
</div>
</div>
</section>
</article>
</main>
<footer>
<p>
Generated on <time datetime="2023-05-07T07:50:39+0000">May 7, 2023</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a> <span class="version">1.0.0-rc.1</span>.
</p>
</footer>
</body>
</html>

View File

@ -0,0 +1,149 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OpenTelemetry Swift X-Ray - XRayPropagator.TraceHeaderParsingError.Reason</title>
<link rel="stylesheet" type="text/css" href="/opentelemetry-swift-xray/all.css" media="all" />
</head>
<body>
<header>
<a href="/opentelemetry-swift-xray/">
<strong>
OpenTelemetry Swift X-Ray
</strong>
<span>Documentation</span>
</a>
</header>
<!--
<form class="search">
<input type="search" placeholder="Search" />
</form>
-->
<nav>
<div class="wrapper">
<h2>On This Page</h2>
<ol><li><a href="#relationships">Relationships</a><ul><li><a href="#relationships">Member Of</a></li><li><a href="#relationships">Conforms To</a></li></ul></li><li><a href="#enumeration cases">Enumeration Cases</a><ul><li class="case"><a href="#xraypropagator.traceheaderparsingerror.reason.missingtraceid">missingTraceID</a></li><li class="case"><a href="#xraypropagator.traceheaderparsingerror.reason.invalidtraceidlength">invalidTraceIDLength</a></li><li class="case"><a href="#xraypropagator.traceheaderparsingerror.reason.unsupportedtraceidversion">unsupportedTraceIDVersion</a></li><li class="case"><a href="#xraypropagator.traceheaderparsingerror.reason.invalidtraceiddelimiters">invalidTraceIDDelimiters</a></li><li class="case"><a href="#xraypropagator.traceheaderparsingerror.reason.invalidspanidlength">invalidSpanIDLength</a></li></ul></li></ol>
</div>
</nav>
<main>
<article>
<h1>
<small>Enumeration</small>
<code class="name">XRayPropagator.TraceHeaderParsingError.Reason</code>
</h1>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">public</span> <span class="keyword">enum</span> <span class="type">Reason</span>: <span class="type">Equatable</span> </body></html></code></pre>
</div>
<section id="relationships">
<h2 hidden>Relationships</h2>
<figure>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.40.1 (20161225.0304)
-->
<!-- Title: %13 Pages: 1 -->
<svg width="874pt" height="116pt"
viewBox="0.00 0.00 874.34 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
<title>%13</title>
<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-112 870.3415,-112 870.3415,4 -4,4"/>
<!-- XRayPropagator.TraceHeaderParsingError.Reason -->
<g id="node1" class="node enumeration current">
<title>XRayPropagator.TraceHeaderParsingError.Reason</title>
<g id="a_node1"><a xlink:href="/opentelemetry-swift-xray/XRayPropagator_TraceHeaderParsingError_Reason" xlink:title="XRayPropagator.TraceHeaderParsingError.Reason">
<path fill="none" stroke="#000000" stroke-width="3" d="M606.1707,-108C606.1707,-108 260.1707,-108 260.1707,-108 254.1707,-108 248.1707,-102 248.1707,-96 248.1707,-96 248.1707,-84 248.1707,-84 248.1707,-78 254.1707,-72 260.1707,-72 260.1707,-72 606.1707,-72 606.1707,-72 612.1707,-72 618.1707,-78 618.1707,-84 618.1707,-84 618.1707,-96 618.1707,-96 618.1707,-102 612.1707,-108 606.1707,-108"/>
<text text-anchor="middle" x="433.1707" y="-86.3" font-family="Menlo" font-size="14.00" fill="#000000">XRayPropagator.TraceHeaderParsingError.Reason</text>
</a>
</g>
</g>
<!-- Equatable -->
<g id="node2" class="node unknown">
<title>Equatable</title>
<path fill="none" stroke="#000000" d="M529.1707,-36C529.1707,-36 337.1707,-36 337.1707,-36 331.1707,-36 325.1707,-30 325.1707,-24 325.1707,-24 325.1707,-12 325.1707,-12 325.1707,-6 331.1707,0 337.1707,0 337.1707,0 529.1707,0 529.1707,0 535.1707,0 541.1707,-6 541.1707,-12 541.1707,-12 541.1707,-24 541.1707,-24 541.1707,-30 535.1707,-36 529.1707,-36"/>
<text text-anchor="middle" x="433.1707" y="-14.3" font-family="Menlo" font-size="14.00" fill="#000000">Equatable</text>
</g>
<!-- XRayPropagator.TraceHeaderParsingError.Reason&#45;&gt;Equatable -->
<g id="edge1" class="edge conformsTo">
<title>XRayPropagator.TraceHeaderParsingError.Reason&#45;&gt;Equatable</title>
<path fill="none" stroke="#000000" d="M433.1707,-71.8314C433.1707,-64.131 433.1707,-54.9743 433.1707,-46.4166"/>
<polygon fill="#000000" stroke="#000000" points="436.6708,-46.4132 433.1707,-36.4133 429.6708,-46.4133 436.6708,-46.4132"/>
</g>
</g>
</svg>
<figcaption hidden>Inheritance graph for XRayPropagator.TraceHeaderParsingError.Reason.</figcaption>
</figure>
<h3>Member Of</h3>
<dl>
<dt class="structure"><code><a href="/opentelemetry-swift-xray/XRayPropagator_TraceHeaderParsingError">XRayPropagator.TraceHeaderParsingError</a></code></dt>
<dd></dd>
</dl>
<h3>Conforms To</h3>
<dl>
<dt class="unknown"><code>Equatable</code></dt>
</dl>
</section>
<section id="enumeration cases">
<h2>Enumeration Cases</h2>
<div role="article" class="case" id="xraypropagator.traceheaderparsingerror.reason.missingtraceid">
<h3>
<code><a href="#xraypropagator.traceheaderparsingerror.reason.missingtraceid">missingTraceID</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">case</span> <span class="variable">missingTraceID</span></body></html></code></pre>
</div>
</div>
<div role="article" class="case" id="xraypropagator.traceheaderparsingerror.reason.invalidtraceidlength">
<h3>
<code><a href="#xraypropagator.traceheaderparsingerror.reason.invalidtraceidlength">invalidTraceIDLength</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">case</span> <span class="variable">invalidTraceIDLength</span>(<span class="type">Int</span>) </body></html></code></pre>
</div>
</div>
<div role="article" class="case" id="xraypropagator.traceheaderparsingerror.reason.unsupportedtraceidversion">
<h3>
<code><a href="#xraypropagator.traceheaderparsingerror.reason.unsupportedtraceidversion">unsupportedTraceIDVersion</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">case</span> <span class="variable">unsupportedTraceIDVersion</span>(<span class="type">String</span>) </body></html></code></pre>
</div>
</div>
<div role="article" class="case" id="xraypropagator.traceheaderparsingerror.reason.invalidtraceiddelimiters">
<h3>
<code><a href="#xraypropagator.traceheaderparsingerror.reason.invalidtraceiddelimiters">invalidTraceIDDelimiters</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">case</span> <span class="variable">invalidTraceIDDelimiters</span></body></html></code></pre>
</div>
</div>
<div role="article" class="case" id="xraypropagator.traceheaderparsingerror.reason.invalidspanidlength">
<h3>
<code><a href="#xraypropagator.traceheaderparsingerror.reason.invalidspanidlength">invalidSpanIDLength</a></code>
</h3>
<div class="declaration">
<pre class="highlight"><code><html><body><span class="keyword">case</span> <span class="variable">invalidSpanIDLength</span>(<span class="type">Int</span>) </body></html></code></pre>
</div>
</div>
</section>
</article>
</main>
<footer>
<p>
Generated on <time datetime="2023-05-07T07:50:39+0000">May 7, 2023</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a> <span class="version">1.0.0-rc.1</span>.
</p>
</footer>
</body>
</html>

1
all.css Normal file

File diff suppressed because one or more lines are too long

88
index.html Normal file
View File

@ -0,0 +1,88 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OpenTelemetry Swift X-Ray - OpenTelemetry Swift X-Ray</title>
<link rel="stylesheet" type="text/css" href="/opentelemetry-swift-xray/all.css" media="all" />
</head>
<body>
<header>
<a href="/opentelemetry-swift-xray/">
<strong>
OpenTelemetry Swift X-Ray
</strong>
<span>Documentation</span>
</a>
</header>
<!--
<form class="search">
<input type="search" placeholder="Search" />
</form>
-->
<nav>
<div class="wrapper">
<h2>On This Page</h2>
<ol><li><a href="#structures">Structures</a></li><li><a href="#enumerations">Enumerations</a></li></ol>
</div>
</nav>
<main>
<article>
<section id="structures">
<h2>Structures</h2>
<dl>
<dt class="structure">
<a href="/opentelemetry-swift-xray/XRayIDGenerator" title="structure - XRayIDGenerator">
XRayIDGenerator
</a>
</dt>
<dd>
<p>Generates trace and span ids using a <code>RandomNumberGenerator</code> in an X-Ray compatible format.</p>
</dd>
<dt class="structure">
<a href="/opentelemetry-swift-xray/XRayPropagator" title="structure - XRayPropagator">
XRayPropagator
</a>
</dt>
<dd>
<p>An <code>OTelPropagator</code> that propagates span context through the <code>X-Amzn-Trace-Id</code> header.</p>
</dd>
<dt class="structure">
<a href="/opentelemetry-swift-xray/XRayPropagator_TraceHeaderParsingError" title="structure - XRayPropagator.TraceHeaderParsingError">
XRayPropagator.TraceHeaderParsingError
</a>
</dt>
<dd>
</dd>
</dl>
</section>
<section id="enumerations">
<h2>Enumerations</h2>
<dl>
<dt class="enumeration">
<a href="/opentelemetry-swift-xray/XRayPropagator_TraceHeaderParsingError_Reason" title="enumeration - XRayPropagator.TraceHeaderParsingError.Reason">
XRayPropagator.TraceHeaderParsingError.Reason
</a>
</dt>
<dd>
</dd>
</dl>
</section>
</article>
</main>
<footer>
<p>
Generated on <time datetime="2023-05-07T07:50:39+0000">May 7, 2023</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a> <span class="version">1.0.0-rc.1</span>.
</p>
</footer>
</body>
</html>

View File

@ -1,19 +0,0 @@
#!/bin/bash
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift OpenTelemetry open source project
##
## Copyright (c) 2021 Moritz Lang and the Swift OpenTelemetry project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -eu
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bash $here/validate_license_headers.sh
bash $here/validate_format.sh

View File

@ -1,36 +0,0 @@
#!/bin/bash
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift OpenTelemetry open source project
##
## Copyright (c) 2021 Moritz Lang and the Swift OpenTelemetry project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -u
printf "=> Checking format\n"
FIRST_OUT="$(git status --porcelain)"
# swiftformat does not scale so we loop ourselves
shopt -u dotglob
find . -type d \( -name .build \) -prune -false -o -name "*.swift" | while IFS= read -r d; do
printf " * checking $d... "
out=$(mint run swiftformat $d 2>&1)
SECOND_OUT="$(git status --porcelain)"
if [[ "$out" == *"error"*] && ["$out" != "*No eligible files" ]]; then
printf "\033[0;31merror!\033[0m\n"
echo $out
exit 1
fi
if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then
printf "\033[0;31mformatting issues!\033[0m\n"
git --no-pager diff
exit 1
fi
printf "\033[0;32mokay.\033[0m\n"
done

View File

@ -1,125 +0,0 @@
#!/bin/bash
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift OpenTelemetry open source project
##
## Copyright (c) 2021 Moritz Lang and the Swift OpenTelemetry project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
##===----------------------------------------------------------------------===##
##
## This source file is part of the SwiftNIO open source project
##
## Copyright (c) 2017-2019 Apple Inc. and the SwiftNIO project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -eu
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function replace_acceptable_years() {
# this needs to replace all acceptable forms with 'YEARS'
sed -e 's/2020-2021/YEARS/' -e 's/2021/YEARS/'
}
printf "=> Checking license headers\n"
tmp=$(mktemp /tmp/.opentelemetry-swift-xray-soundness_XXXXXX)
for language in swift-or-c bash dtrace; do
printf " * $language... "
declare -a matching_files
declare -a exceptions
expections=( )
matching_files=( -name '*' )
case "$language" in
swift-or-c)
exceptions=( -name 'Package.swift' )
matching_files=( -name '*.swift' -o -name '*.c' -o -name '*.h' )
cat > "$tmp" <<"EOF"
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift OpenTelemetry open source project
//
// Copyright (c) YEARS Moritz Lang and the Swift OpenTelemetry project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
EOF
;;
bash)
matching_files=( -name '*.sh' )
cat > "$tmp" <<"EOF"
#!/bin/bash
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift OpenTelemetry open source project
##
## Copyright (c) YEARS Moritz Lang and the Swift OpenTelemetry project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
EOF
;;
dtrace)
matching_files=( -name '*.d' )
cat > "$tmp" <<"EOF"
#!/usr/sbin/dtrace -q -s
/*===----------------------------------------------------------------------===*
*
* This source file is part of the Swift OpenTelemetry open source project
*
* Copyright (c) YEARS Moritz Lang and the Swift OpenTelemetry project authors
* Licensed under Apache License v2.0
*
* See LICENSE.txt for license information
*
* SPDX-License-Identifier: Apache-2.0
*
*===----------------------------------------------------------------------===*/
EOF
;;
*)
echo >&2 "ERROR: unknown language '$language'"
;;
esac
expected_lines=$(cat "$tmp" | wc -l)
expected_sha=$(cat "$tmp" | shasum)
(
cd "$here/.."
find . \
\( \! -path '*/.build/*' -a \
\( "${matching_files[@]}" \) -a \
\( \! \( "${exceptions[@]}" \) \) \) | while read line; do
if [[ "$(cat "$line" | replace_acceptable_years | head -n $expected_lines | shasum)" != "$expected_sha" ]]; then
printf "\033[0;31mmissing headers in file '$line'!\033[0m\n"
diff -u <(cat "$line" | replace_acceptable_years | head -n $expected_lines) "$tmp"
exit 1
fi
done
printf "\033[0;32mokay.\033[0m\n"
)
done
rm "$tmp"