fly-log-shipper

repository·main·Indexed 43 days ago

https://github.com/superfly/fly-log-shipper

A tool for shipping logs from Fly.io applications to external providers such as Datadog, AWS S3, AWS CloudWatch, SigNoz, and Axiom. It uses NATS as the transport layer and Vector as the processing engine to receive, transform, and sink logs.

Tokens
1.4K
Snippets
4
Records
11
Agent score
6%

What's inside fly-log-shipper

  1. How fly-log-shipper uses Vector for log processing

    main

    The fly-log-shipper utilizes Vector as its underlying engine. The nats source component in Vector receives logs and passes them through downstream transforms and sinks.

    Configuration is managed via a shell wrapper script that evaluates environment variables to dynamically generate the final Vector configuration file. This allows you to enable or disable specific Vector sinks (providers) by toggling the corresponding environment variables.

  2. How to manually connect to the NATS log stream

    main

    While the log shipper handles connections automatically, you can manually connect your own Fly apps to the NATS server to publish or subscribe to logs.

    Connection Details:

    • Server: nats://[fdaa::3]:4223 (IPv6)
    • User: Your Fly organization slug (get via fly orgs list)
    • Password: Your Fly personal access token (get via fly tokens create readonly personal)

    Subject Schema: The subject follows the pattern logs.<app_name>.<region>.<instance_id>. You can use standard NATS wildcards to subscribe to specific subsets of logs.

  3. Configure NATS subscription queues for high availability

    main

    To run multiple instances of fly-log-shipper for high availability and ensure that logs are only processed by one instance, use NATS subscription queues. You can configure a specific queue name by setting the QUEUE environment variable (or secret). This ensures that messages are distributed across subscribers of the named queue rather than being sent to all of them.

    # Example: Setting the QUEUE secret/env var
    export QUEUE="my-log-shipper-queue"
  4. Quick start: Deploy fly-log-shipper

    main

    To deploy a new log shipper application on Fly.io that automatically reads your organization's logs and sends them to an external provider, follow these steps:

    1. Launch the app: Use the official Docker image. Ensure you use --no-public-ips for security.
      fly launch --image flyio/log-shipper:latest --no-public-ips
    2. Configure NATS source: Set the required NATS secrets (see NATS source configuration).
    3. Configure Provider: Set the secrets for your chosen log destination (see Provider configuration).

    Important: After generating your fly.toml, you must update the internal_port in the [[services]] section to match the Vector internal port defined in vector-configs/vector.toml (typically 8686). Failure to do this will cause health checks to fail during deployment.

    fly launch --image flyio/log-shipper:latest --no-public-ips
  5. Configure SigNoz provider

    main

    To ship logs to SigNoz, set the following secrets:

    SecretDescription
    SIGNOZ_INGESTION_KEYSigNoz Ingestion Key (Required for SigNoz Cloud)
    SIGNOZ_INGESTION_URLSigNoz Ingestion URL (defaults to https://ingest.us.signoz.cloud/logs/vector)

    Self-hosted SigNoz: Set SIGNOZ_INGESTION_URL to your own endpoint. SIGNOZ_INGESTION_KEY is not required for self-hosted deployments.

  6. Configure AWS CloudWatch provider

    main

    To ship logs to AWS CloudWatch, set the following secrets:

    SecretDescription
    AWS_ACCESS_KEY_IDAWS Access key with access to the log bucket
    AWS_SECRET_ACCESS_KEYAWS secret access key
    AWS_REGIONRegion for CloudWatch
    CLOUDWATCH_LOG_GROUP_NAMELog Group name
    CLOUDWATCH_ENCODING_CODECCloudWatch codec (defaults to json)
  7. Configure Slack alerts (experimental)

    main

    You can use the HTTP sink to send log alerts to Slack by setting these secrets:

    SecretDescription
    SLACK_WEBHOOK_URLSlack WebHook URL
    SLACK_ALERT_KEYWORDSKeywords to alert on

    Example for setting keywords:

    fly secrets set SLACK_ALERT_KEYWORDS="[r'SIGTERM', r'reboot']"
  8. Configure AWS S3 provider

    main

    To ship logs to an AWS S3 bucket (or S3-compatible stores like Cloudflare R2 or Wasabi), set the following secrets:

    SecretDescription
    AWS_ACCESS_KEY_IDAWS Access key with access to the log bucket
    AWS_SECRET_ACCESS_KEYAWS secret access key
    AWS_BUCKETAWS S3 bucket name
    AWS_REGIONRegion for the bucket
    S3_ENDPOINT(Optional) Endpoint URL for S3 compatible stores
  9. Configure NATS source secrets

    main

    The log shipper uses NATS to subscribe to Fly.io logs. Configure the following secrets in your Fly app to define the source:

    SecretDescription
    ORGOrganisation slug (defaults to personal)
    ACCESS_TOKENFly personal access token (Required). Set this using fly secrets set ACCESS_TOKEN=$(fly tokens create readonly personal)
    SUBJECTNATS subject to subscribe to (defaults to logs.>)
    QUEUEArbitrary queue name for High Availability (HA) to avoid duplicate messages
    NETWORK6PN network for WireGuard connections (defaults to fdaa:0:0)
  10. Example: Using the NATS client to publish logs

    main

    To test the NATS stream, you can launch a temporary NATS client on Fly.io, SSH into it, and publish a message.

    1. Launch client:
      fly launch --image="synadia/nats-server:nightly" --name="nats-client"
    2. SSH into app:
      fly -a nats-client ssh console
    3. Add NATS context:
      nats context add nats --server [fdaa::3]:4223 --description "NATS Demo" --select \
        --user <YOUR FLY ORG SLUG> \
        --password <YOUR PAT>
    4. Publish a test message:
      nats pub "logs.test" "hello world"
    nats context add nats --server [fdaa::3]:4223 --description "NATS Demo" --select \
      --user <YOUR FLY ORG SLUG> \
      --password <YOUR PAT>
    
    nats pub "logs.test" "hello world"