Skip to content

Commit

Permalink
Maintenance Updates (#8)
Browse files Browse the repository at this point in the history
* add devcontainer config

* manifest version updates

* general maintenance

* refactor to use AHC on linux

* use datadog’s Site terminology

* add docs
  • Loading branch information
jagreenwood authored Feb 3, 2024
1 parent e47aa09 commit 9bd7987
Show file tree
Hide file tree
Showing 25 changed files with 508 additions and 233 deletions.
44 changes: 44 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "Swift",
"image": "swift:5.9.1",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": "false",
"username": "vscode",
"userUid": "1000",
"userGid": "1000",
"upgradePackages": "false"
},
"ghcr.io/devcontainers/features/git:1": {
"version": "os-provided",
"ppa": "false"
}
},
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"lldb.library": "/usr/lib/liblldb.so"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"sswg.swift-lang"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "swift --version",

// Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
9 changes: 4 additions & 5 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ name: Unit Test

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
build:

runs-on: ubuntu-18.04

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Build
run: swift build -v
- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
xcuserdata/
/.swiftpm
/Package.resolved
.vscode
4 changes: 4 additions & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: [DataDogLog]
18 changes: 13 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
// swift-tools-version:5.9

import PackageDescription

let package = Package(
name: "swift-log-datadog",
platforms: [
.iOS(.v13),
.watchOS(.v6),
.tvOS(.v13),
.macOS(.v11)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "DataDogLog",
targets: ["DataDogLog"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/apple/swift-log.git", from: "1.2.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.0"),
],
targets: [
.target(
Expand All @@ -24,3 +27,8 @@ let package = Package(
dependencies: ["DataDogLog"]),
]
)

#if os(Linux)
package.dependencies.append(.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.19.0"))
package.targets.first { $0.name == "DataDogLog" }?.dependencies.append(.product(name: "AsyncHTTPClient", package: "async-http-client"))
#endif
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This package implements a handler for [swift-log](https://github.com/apple/swift
Integrate the `DataDogLog` package as a dependency with Swift Package Manager. Add the following to `Package.swift`:

```swift
.package(url: "[email protected]:jagreenwood/swift-log-datadog.git", from: "0.0.1")
.package(url: "[email protected]:jagreenwood/swift-log-datadog.git", from: "1.0.0")
```

Add `DataDogLog` to your target dependencies:
Expand Down
18 changes: 18 additions & 0 deletions Sources/DataDogLog/DataDogLog.docc/DataDogLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ``DataDogLog``

A Datadog logging backend for Swift

## Overview

This package implements a logging backend for [swift-log](https://github.com/apple/swift-log) which will send log messages to the [Datadog's](https://www.datadoghq.com) Log Management service.

## Topics

### Getting Started

- <doc:GettingStarted>

### Essentials

- ``DataDogLogHandler``
- ``Site``
68 changes: 68 additions & 0 deletions Sources/DataDogLog/DataDogLog.docc/GettingStarted.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Getting Started

## Overview

### Add Package
Integrate the `DataDogLog` package as a dependency with Swift Package Manager. Add the following to `Package.swift`:

```swift
.package(url: "[email protected]:jagreenwood/swift-log-datadog.git", from: "1.0.0")
```

Add `DataDogLog` to your target dependencies:

```swift
.product(name: "DataDogLog", package: "swift-log-datadog")
```

### Configure

Configure the logger by bootstrapping a `DataDogLogHandler` instance.

```swift
import DataDogLog

// add handler to logging system
LoggingSystem.bootstrap {
// initialize handler instance
var handler = DataDogLogHandler(label: $0, key: "xxx", hostname: "hostname")
// global metadata (optional)
handler.metadata = ["foo":"bar"]

return handler
}
```

### Logging

To send logs to Datadog, initialize a `Logger` instance and send a message with optional additional metadata:

```swift
import DataDogLog

let logger = Logger(label: "com.swift-log.awesome-app")
logger.error("unfortunate error", metadata: ["request-id": "abc-123"], source: "module-name")
```

This call will send the following payload to Datadog:

```json
{
"message": "2020-05-27T06:37:17-0400 ERROR: unfortunate error",
"hostname": "hostname",
"ddsource": "module-name",
"ddtags": "callsite:testLog():39,foo:bar,request-id:abc-123",
"status": "error"
"service": "com.swift-log.awesome-app"
}
```

### Select Site

The Datadog API runs on multiple regions (e.g. US, EU, US3, US5, US1FED), with different API endpoints. If your account was not created in the default **US** region, you need to set the `region` option when initializing `DataDogLogHandler`:

```swift
DataDogLogHandler(label: $0, key: "xxx", hostname: "hostname", region: .EU)
```


64 changes: 0 additions & 64 deletions Sources/DataDogLog/DataDogLogHandler.swift

This file was deleted.

43 changes: 0 additions & 43 deletions Sources/DataDogLog/DataDogSession.swift

This file was deleted.

7 changes: 0 additions & 7 deletions Sources/DataDogLog/Extensions/Metadata+Format.swift

This file was deleted.

9 changes: 9 additions & 0 deletions Sources/DataDogLog/Internal/Extensions/Metadata+Format.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Logging

extension Logger.Metadata {
var prettified: String? {
!isEmpty ? map { "\($0):\($1)" }
.sorted(by: <)
.joined(separator: ",") : nil
}
}
14 changes: 14 additions & 0 deletions Sources/DataDogLog/Internal/Extensions/Site+URL.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation

extension Site {
var url: URL {
switch (self) {
case .AP1: URL(string: "https://http-intake.logs.ap1.datadoghq.com/api/v2/logs")!
case .EU: URL(string: "https://http-intake.logs.datadoghq.eu/api/v2/logs")!
case .US: URL(string: "https://http-intake.logs.datadoghq.com/api/v2/logs")!
case .US3: URL(string: "https://http-intake.logs.us3.datadoghq.com/api/v2/logs")!
case .US5: URL(string: "https://http-intake.logs.us5.datadoghq.com/api/v2/logs")!
case .US1FED: URL(string: "https://http-intake.logs.ddog-gov.com/api/v2/logs")!
}
}
}
Loading

0 comments on commit 9bd7987

Please sign in to comment.