Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM fluent/fluentd:latest

ENV DEBIAN_FRONTEND=noninteractive
USER root

RUN apt-get update && apt-get install -y \
build-essential \
git \
curl

WORKDIR /workspaces

21 changes: 21 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// .devcontainer/devcontainer.json
{
"name": "Fluent Plugin Datadog Dev",
"build": {
"dockerfile": "Dockerfile"
},
"workspaceFolder": "/workspaces/fluent-plugin-datadog",
"postCreateCommand": "bundle install --jobs 4 --retry 3",
"customizations": {
"vscode": {
"extensions": [
"shopify.ruby-lsp",
"ms-azuretools.vscode-docker"
],
"settings": {
"rubyLsp.bundleExec": true,
"rubyLsp.useBundler": true
}
}
}
}
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "ruby_lsp",
"request": "launch",
"name": "Run Tests",
"program": "bundle exec ruby -Itest test/plugin/test_out_datadog.rb",
}
]
}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,11 @@ To build a new version of this plugin and push it to RubyGems:

`curl -u <USERNAME> https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials`, it will ask for your password.

## Development Environment

This repository includes the files to run it in a dev container in VS Code. To use it:

1. Install VS Code and Docker.
2. Open the project in VS Code with the Dev Containers extension.

VS Code will build and start the container automatically.
3 changes: 2 additions & 1 deletion fluent-plugin-datadog.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 2.1"
spec.add_development_dependency "test-unit", '~> 3.1'
spec.add_development_dependency "rake", "~> 12.0"
spec.add_development_dependency 'webmock', "~> 3.6.0"
spec.add_development_dependency "ruby-debug-ide"
spec.add_development_dependency "rake", "~> 12.0"

spec.metadata = {
'bug_tracker_uri' => 'https://github.com/DataDog/fluent-plugin-datadog/issues',
Expand Down
47 changes: 47 additions & 0 deletions test/TestApp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# TestApp - Typical Fluentd Usage Example

This directory demonstrates an example of fluentd usage with the Datadog plugin - using configuration files and running Fluentd as a service.

## Files

- **`fluent.conf`** - Fluentd configuration file
- **`start_fluentd.sh`** - Script to start Fluentd with the configuration
- **`send_test_logs.sh`** - Script to send test logs via HTTP (bash)

## Quick Start

### 1. Set your Datadog API Key

```bash
export DD_API_KEY=your_api_key_here
```

### 2. Start Fluentd

```bash
./start_fluentd.sh
```

This starts Fluentd as a service with the configuration file. Fluentd will:
- Listen on HTTP port 8888 for log ingestion
- Listen on Forward port 24224 for Fluentd protocol
- Route logs matching `test.**` to Datadog

### 3. Send Test Logs

In another terminal:

```bash
# Using bash script
./send_test_logs.sh

# Or manually with curl
curl -X POST -d 'json={"message":"Hello from Fluentd"}' \
http://localhost:8888/test.app
```

### 4. Verify Logs

Check your Datadog dashboard to see the logs appear. They should include:
- Original log fields
- Datadog metadata: `ddsource`, `ddtags`, `service`, `hostname`, `tag`, `@timestamp`
38 changes: 38 additions & 0 deletions test/TestApp/fluent.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Typical Fluentd configuration file for Datadog plugin
# This is how Fluentd is typically configured in production

# HTTP input - allows sending logs via HTTP POST
<source>
@type http
port 8888
bind 0.0.0.0
</source>

# Forward input - allows sending logs via Fluentd forward protocol
<source>
@type forward
port 24224
bind 0.0.0.0
</source>

# Match events and send them to Datadog
<match test.**>
@type datadog
@id datadog_output
api_key YOUR_API_KEY_HERE

# Optional configuration
include_tag_key true
tag_key 'tag'
service 'fluentd-test-app'
dd_source 'ruby'
dd_tags 'env:test,app:testapp'

<buffer>
@type memory
flush_interval 3s
chunk_limit_size 5m
chunk_limit_records 500
</buffer>
</match>

41 changes: 41 additions & 0 deletions test/TestApp/send_test_logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
# Unless explicitly stated otherwise all files in this repository are licensed
# under the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2018 Datadog, Inc.

# Script to send test logs to Fluentd via HTTP
# This demonstrates typical usage - sending logs to Fluentd's HTTP endpoint

FLUENTD_URL="${FLUENTD_URL:-http://localhost:8888}"
TAG="${TAG:-test.app}"

echo "Sending test logs to Fluentd at ${FLUENTD_URL}"
echo "Tag: ${TAG}"
echo ""

# Send test log 1
echo "Sending log 1: Test message"
curl -X POST -d 'json={"message":"Test log message from TestApp","level":"info","user":"test_user","action":"test_action"}' \
"${FLUENTD_URL}/${TAG}"

echo ""
echo ""

# Send test log 2
echo "Sending log 2: Debug message"
curl -X POST -d 'json={"message":"Another test message","level":"debug","component":"test_component","status":"success"}' \
"${FLUENTD_URL}/${TAG}"

echo ""
echo ""

# Send test log 3
echo "Sending log 3: Error simulation"
curl -X POST -d 'json={"message":"Error simulation","level":"error","error_code":"TEST_ERROR","stack_trace":"test_stack_trace"}' \
"${FLUENTD_URL}/${TAG}"

echo ""
echo ""
echo "Check Fluentd output or Datadog dashboard to verify logs were received."

50 changes: 50 additions & 0 deletions test/TestApp/start_fluentd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
# Unless explicitly stated otherwise all files in this repository are licensed
# under the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2018 Datadog, Inc.

# Script to start Fluentd with the Datadog plugin configuration
# This demonstrates typical Fluentd usage - running as a service with a config file

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_FILE="${SCRIPT_DIR}/fluent.conf"

# Check if API key is set
if [ -z "$DD_API_KEY" ]; then
echo "Warning: DD_API_KEY environment variable is not set."
echo "Please set it before starting Fluentd:"
echo " export DD_API_KEY=your_api_key_here"
echo ""
echo "Or edit fluent.conf and replace YOUR_API_KEY_HERE with your actual API key"
echo ""
if [ -t 0 ]; then
# Only prompt if running interactively
read -p "Continue anyway? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
else
echo "Non-interactive mode: Continuing with placeholder API key"
fi
fi

# Replace API key in config if DD_API_KEY is set
if [ -n "$DD_API_KEY" ]; then
TEMP_CONFIG=$(mktemp)
sed "s/YOUR_API_KEY_HERE/$DD_API_KEY/g" "$CONFIG_FILE" > "$TEMP_CONFIG"
CONFIG_FILE="$TEMP_CONFIG"
trap "rm -f $TEMP_CONFIG" EXIT
fi

echo "Starting Fluentd with configuration: ${SCRIPT_DIR}/fluent.conf"
echo "HTTP endpoint: http://localhost:8888"
echo "Forward endpoint: localhost:24224"
echo ""
echo "Press Ctrl+C to stop Fluentd"
echo ""

# Start Fluentd
bundle exec fluentd -c "$CONFIG_FILE" -v

Loading