Skip to content

Commit

Permalink
Merge branch 'main' into codeql-scan-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoBonafonte authored Jan 23, 2025
2 parents d8ffe7c + d61ab07 commit b0cbbfa
Show file tree
Hide file tree
Showing 283 changed files with 6,940 additions and 6,523 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/BuildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ name: Build and Test
on: [push, pull_request, workflow_dispatch]

jobs:
SwiftLint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: GitHub Action for SwiftLint (Only files changed in the PR)
uses: norio-nomura/action-swiftlint@3.2.1
env:
args: --strict
DIFF_BASE: ${{ github.base_ref }}
macOS:
runs-on: macos-15
steps:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/Tag-And-Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ jobs:
tag: ${{ steps.check-release.outputs.version }}
prerelease: true
generateReleaseNotes: true
- name: push cocoapods
env:
COCOAPODS_TRUNK_TOKEN=${{ secrets.COCOAPODS_TRUNK_TOKEN }}
id: cocoapod_trunk_push
run: |
pod trunk push OpenTelemetry-Swift-Api.podspec --allow-warnings
pod trunk push OpenTelemetry-Swift-Sdk.podspec --allow-warnings --synchronous
18 changes: 18 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
included:
- "Sources"
excluded:
- "Sources/Exporters/OpenTelemetryProtocolCommon/proto"
- ".build"
disabled_rules:
- nesting
- line_length
- type_body_length
- identifier_name
- file_length
- force_cast
- type_name
- large_tuple
- function_body_length
- function_parameter_count
- cyclomatic_complexity
- force_try
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ To test from the command line you need `swift` version `5.0+`.
swift test
```

### SwiftLint
the SwiftLint Xcode plugin can be optionally enabled during development by using an environmental variable when opening the project from the commandline.
```
OTEL_ENABLE_SWIFTLINT=1 open Package.swift
```
Note: Xcode must be completely closed before running the above command, close Xcode using `⌘Q` or running `killall xcode` in the commandline.

### Make your modifications

Always work in a branch from your fork:
Expand Down
2 changes: 1 addition & 1 deletion Examples/Datadog Sample/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ sleep(10)

func testTraces() {
let spanProcessor = SimpleSpanProcessor(spanExporter: datadogExporter)

OpenTelemetry.registerTracerProvider(tracerProvider:
TracerProviderBuilder()
.add(spanProcessor: spanProcessor)
Expand Down
16 changes: 6 additions & 10 deletions Examples/Logs Sample/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ import Logging
import GRPC
import NIO


func configure() {
let configuration = ClientConnection.Configuration.default(
target: .hostAndPort("localhost", 4317),
eventLoopGroup: MultiThreadedEventLoopGroup(numberOfThreads: 1))
target: .hostAndPort("localhost", 4317),
eventLoopGroup: MultiThreadedEventLoopGroup(numberOfThreads: 1))

OpenTelemetry.registerLoggerProvider(loggerProvider: LoggerProviderBuilder().with(processors: [
BatchLogRecordProcessor(logRecordExporter:OtlpLogExporter(channel: ClientConnection(configuration: configuration)))]).build())

}
OpenTelemetry.registerLoggerProvider(loggerProvider: LoggerProviderBuilder().with(processors: [
BatchLogRecordProcessor(logRecordExporter: OtlpLogExporter(channel: ClientConnection(configuration: configuration)))]).build())
}

configure()

let eventProvider = OpenTelemetry.instance.loggerProvider.loggerBuilder(instrumentationScopeName: "myScope").setEventDomain("device").build()


9 changes: 3 additions & 6 deletions Examples/Network Sample/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import OpenTelemetrySdk
import StdoutExporter
import URLSessionInstrumentation


func simpleNetworkCall() {
let url = URL(string: "http://httpbin.org/get")!
let request = URLRequest(url: url)
let semaphore = DispatchSemaphore(value: 0)

let task = URLSession.shared.dataTask(with: request) { data, _, _ in
if let data = data {
let string = String(decoding: data, as: UTF8.self)
print(string)
let string = String(bytes: data, encoding: .utf8)
print(string as Any)
}
semaphore.signal()
}
Expand All @@ -27,7 +26,6 @@ func simpleNetworkCall() {
semaphore.wait()
}


class SessionDelegate: NSObject, URLSessionDataDelegate, URLSessionTaskDelegate {
let semaphore = DispatchSemaphore(value: 0)

Expand All @@ -39,7 +37,7 @@ let delegate = SessionDelegate()

func simpleNetworkCallWithDelegate() {

let session = URLSession(configuration: .default, delegate: delegate, delegateQueue:nil)
let session = URLSession(configuration: .default, delegate: delegate, delegateQueue: nil)

let url = URL(string: "http://httpbin.org/get")!
let request = URLRequest(url: url)
Expand All @@ -50,7 +48,6 @@ func simpleNetworkCallWithDelegate() {
delegate.semaphore.wait()
}


let spanProcessor = SimpleSpanProcessor(spanExporter: StdoutSpanExporter(isDebug: true))
OpenTelemetry.registerTracerProvider(tracerProvider:
TracerProviderBuilder()
Expand Down
2 changes: 0 additions & 2 deletions Examples/OTLP Exporter/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ OpenTelemetry.registerTracerProvider(tracerProvider:

let tracer = OpenTelemetry.instance.tracerProvider.get(instrumentationName: instrumentationScopeName, instrumentationVersion: instrumentationScopeVersion)


if #available(macOS 10.14, *), #available(iOS 12.0, *) {
let tracerProviderSDK = OpenTelemetry.instance.tracerProvider as? TracerProviderSdk
tracerProviderSDK?.addSpanProcessor(SignPostIntegration())
Expand Down Expand Up @@ -88,7 +87,6 @@ let meterProvider = MeterProviderSdk(metricProcessor: processor, metricExporter:

OpenTelemetry.registerMeterProvider(meterProvider: meterProvider)


let labels1 = ["dim1": "value1"]

var meter = meterProvider.get(instrumentationName: "otlp_example_meter'")
Expand Down
5 changes: 2 additions & 3 deletions Examples/OTLP HTTP Exporter/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ func createSpans() {
doWork()
}
Thread.sleep(forTimeInterval: 0.5)

let parentSpan2 = tracer.spanBuilder(spanName: "Another").setSpanKind(spanKind: .client).setActive(true).startSpan()
parentSpan2.setAttribute(key: sampleKey, value: sampleValue)
// do more Work
for _ in 1...3 {
doWork()
}
Thread.sleep(forTimeInterval: 0.5)

parentSpan2.end()
parentSpan1.end()
}
Expand All @@ -78,7 +78,6 @@ let meterProvider = MeterProviderSdk(metricProcessor: processor, metricExporter:

OpenTelemetry.registerMeterProvider(meterProvider: meterProvider)


var meter = meterProvider.get(instrumentationName: "otlp_example_meter'")
var exampleCounter = meter.createIntCounter(name: "otlp_example_counter")
var exampleMeasure = meter.createIntMeasure(name: "otlp_example_measure")
Expand Down
5 changes: 2 additions & 3 deletions Examples/Prometheus Sample/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import PrometheusExporter
print("Hello Prometheus")

//
//You should use here your real local address, change it also in the prometheus.yml file
// You should use here your real local address, change it also in the prometheus.yml file
let localAddress = "192.168.1.28"
//

Expand All @@ -30,7 +30,6 @@ DispatchQueue.global(qos: .default).async {

let processor = MetricProcessorSdk()


let meterProvider = MeterProviderSdk(metricProcessor: processor, metricExporter: promExporter, metricPushInterval: 0.1)
OpenTelemetry.registerMeterProvider(meterProvider: meterProvider)

Expand All @@ -39,7 +38,7 @@ var meter = meterProvider.get(instrumentationName: "MyMeter")
var testCounter = meter.createIntCounter(name: "MyCounter")
var testMeasure = meter.createIntMeasure(name: "MyMeasure")

let boundaries: Array<Int> = [5, 10, 25]
let boundaries: [Int] = [5, 10, 25]
var testHistogram = meter.createIntHistogram(name: "MyHistogram", explicitBoundaries: boundaries, absolute: true)

var testObserver = meter.createIntObserver(name: "MyObservation") { observer in
Expand Down
20 changes: 10 additions & 10 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/grpc/grpc-swift.git",
"state" : {
"revision" : "6a90b7e77e29f9bda6c2b3a4165a40d6c02cfda1",
"version" : "1.23.0"
"revision" : "8c5e99d0255c373e0330730d191a3423c57373fb",
"version" : "1.24.2"
}
},
{
Expand Down Expand Up @@ -68,17 +68,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "9428f62793696d9a0cc1f26a63f63bb31da0516d",
"version" : "2.66.0"
"revision" : "dca6594f65308c761a9c409e09fbf35f48d50d34",
"version" : "2.77.0"
}
},
{
"identity" : "swift-nio-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "a3b640d7dc567225db7c94386a6e71aded1bfa63",
"version" : "1.22.0"
"revision" : "2e9746cfc57554f70b650b021b6ae4738abef3e6",
"version" : "1.24.1"
}
},
{
Expand Down Expand Up @@ -113,17 +113,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "9f0c76544701845ad98716f3f6a774a892152bcb",
"version" : "1.26.0"
"revision" : "ebc7251dd5b37f627c93698e4374084d98409633",
"version" : "1.28.2"
}
},
{
"identity" : "swift-system",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system.git",
"state" : {
"revision" : "f9266c85189c2751589a50ea5aec72799797e471",
"version" : "1.3.0"
"revision" : "c8a44d836fe7913603e246acab7c528c2e780168",
"version" : "1.4.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let package = Package(
.package(url: "https://github.com/undefinedlabs/opentracing-objc", exact: "0.5.2"),
.package(url: "https://github.com/undefinedlabs/Thrift-Swift", exact: "1.1.1"),
.package(url: "https://github.com/apple/swift-nio.git", exact: "2.0.0"),
.package(url: "https://github.com/grpc/grpc-swift.git", exact: "1.0.0"),
.package(url: "https://github.com/grpc/grpc-swift.git", exact: "1.24.2"),
.package(url: "https://github.com/apple/swift-protobuf.git", exact: "1.20.2"),
.package(url: "https://github.com/apple/swift-log.git", exact: "1.4.4"),
.package(url: "https://github.com/apple/swift-metrics.git", exact: "2.1.1"),
Expand Down
2 changes: 1 addition & 1 deletion Package@swift-5.6.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let package = Package(
.package(url: "https://github.com/undefinedlabs/opentracing-objc", from: "0.5.2"),
.package(url: "https://github.com/undefinedlabs/Thrift-Swift", from: "1.1.1"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0"),
.package(url: "https://github.com/grpc/grpc-swift.git", exact: "1.24.2"),
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.20.2"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.4"),
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.1.1"),
Expand Down
17 changes: 15 additions & 2 deletions Package@swift-5.9.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
import Foundation

let package = Package(
name: "opentelemetry-swift",
platforms: [
.macOS(.v10_15),
.macOS(.v12),
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v6),
Expand All @@ -29,7 +30,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0"),
.package(url: "https://github.com/grpc/grpc-swift.git", exact: "1.24.2"),
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.20.2"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.4"),
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.1.1"),
Expand Down Expand Up @@ -289,3 +290,15 @@ extension Package {
return self
}
}

if ProcessInfo.processInfo.environment["OTEL_ENABLE_SWIFTLINT"] != nil {
package.dependencies.append(contentsOf: [
.package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", from: "0.57.1")
])

for target in package.targets {
target.plugins = [
.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins"),
]
}
}
9 changes: 9 additions & 0 deletions Scripts/hooks/install-precommit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

HOOK_DIR=${SCRIPT_DIR}/../../.git/hooks

cp "${SCRIPT_DIR}/precommit-script.sh" "${HOOK_DIR}/precommit"

chmod 0755 "${HOOK_DIR}/precommit"
32 changes: 32 additions & 0 deletions Scripts/hooks/precommit-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

if ! command -v swiftlint 2>&1 >/dev/null
then

echo "install swiftlint \(v0.0.57\) for pre-commit linting."
exit 0
fi

if [ "$(swiftlint --version)" != "0.57.1" ]
then
echo "swiftlint installed with incorrect version (`swiftlint --version`). Please use version 0.57.1 for pre-commit linting."
exit 0
fi
OIFS="$IFS"
IFS=$'\n'
FILE_LIST=($(git diff --cached --name-only | grep "\.swift$"))
IFS="$OIFS"

if [ -z "${FILE_LIST}" ]; then
exit 0
fi

swiftlint lint --config .swiftlint.yml --strict "${FILE_LIST[@]}"
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo -e "Swiftlint failed!\n Fix issues above or run:\n\tswiftlint lint --fix $(printf "\"%s\" " "${FILE_LIST[@]}")"
echo "Skip linting with '--no-verify'."
exit 1
fi
echo "Swiftlint passed!"
exit 1
Loading

0 comments on commit b0cbbfa

Please sign in to comment.