swift-influxdb-telemetry

main

InfluxDB logging and metrics
dankinsoid/swift-influxdb-telemetry

swift-influxdb-telemetry

This library provides Swift-based tools for integrating InfluxDB with your application for metrics, logging, analytics and tracing purposes.

Features

  • Metrics Collection: Efficiently collects and batches metrics data to be written to InfluxDB.
  • Logging: Configurable logging that writes directly to InfluxDB, using metadata tags for enhanced query performance.
  • Analytics: Sends analytics data to InfluxDB for analysis and visualization.
  • Tracing: Supports distributed tracing for monitoring and troubleshooting.
  • Batching and Throttling: Supports batching and throttling to optimize data writing to InfluxDB.
  • Customizable Tagging: Allows for flexible tagging to support diverse querying needs.

Usage

Setting Up Metrics Factory

import InfluxDBMetrics

MetricsSystem.bootstrap(
    InfluxDBMetricsFactory(
        url: "http://localhost:8086",
        token: "your-token",
        org: "your-org-name",
        bucket: "your-bucket-name",
        precision: .ms, // Optional
        batchSize: 5000, // Optional
        throttleInterval: 5, // Optional
        dimensionsLabelsAsTags: .all // Optional
    )
)

Setting Up Log Handler

import InfluxDBLogs

LoggingSystem.bootstrap { name in
    InfluxDBLogHandler(
        name: name,
        url: "http://localhost:8086",
        token: "your-token",
        org: "your-org-name",
        bucket: "your-bucket-name",
        precision: .ms, // Optional
        batchSize: 5000, // Optional
        throttleInterval: 5, // Optional
        metadataLabelsAsTags: .loggingDefault.union([.InfluxDBLogLabels.file]), // Optional
        logLevel: .info, // Optional
    )
}

Setting Up Analytics

import InfluxDBAnalytics

AnalyticsSystem.bootstrap(
    InfluxDBAnalyticsHandler(
        url: "http://localhost:8086",
        token: "your-token",
        org: "your-org-name",
        bucket: "your-bucket-name",
        precision: .ms, // Optional
        batchSize: 5000, // Optional
        throttleInterval: 5, // Optional
        parametersLabelsAsTags: .analyticsDefault.union([.InfluxDBAnalyticsLabels.file]), // Optional
    )
)

Setting Up Tracing

import InfluxDBTracing

InstrumentationSystem.bootstrap(
    InfluxDBTracer(
        url: "http://localhost:8086",
        token: "your-token",
        org: "your-org-name",
        bucket: "your-bucket-name",
        precision: .ms, // Optional
        batchSize: 5000, // Optional
        throttleInterval: 5, // Optional
    )
)

Writing Metrics, Logs, Analytics and Traces

// Metrics
Counter(label: "page_views", dimensions: ["type": "homepage"]).increment()

// Analytics
Analytics().send("page_view", parameters: ["type": "homepage"])

// Logs
Logger(label: "app").error("Something went wrong!")

// Traces
withSpan("operation") { span in
    // Perform operation
}

Installation

  1. Swift Package Manager

Create a Package.swift file.

// swift-tools-version:5.9
import PackageDescription

let package = Package(
  name: "SomeProject",
  dependencies: [
    .package(url: "https://github.com/dankinsoid/swift-influxdb-telemetry.git", from: "1.10.0")
  ],
  targets: [
    .target(
        name: "SomeProject",
        dependencies: [
            .product(name: "InfluxDBLogs", package: "swift-influxdb-telemetry"),
            .product(name: "InfluxDBAnalytics", package: "swift-influxdb-telemetry"),
            .product(name: "InfluxDBMetrics", package: "swift-influxdb-telemetry"),
            .product(name: "InfluxDBTracing", package: "swift-influxdb-telemetry")
       ]
    )
  ]
)
$ swift build

Author

dankinsoid, voidilov@gmail.com

License

swift-influxdb-telemetry is available under the MIT license. See the LICENSE file for more info.

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Fri Nov 01 2024 18:48:05 GMT-0900 (Hawaii-Aleutian Daylight Time)