Logs
KubeSense FireLens Log Router Setup
KubeSense provides a custom FireLens log router image that collects logs from your application containers and ships them to KubeSense. The solution supports both single shipping (KubeSense only) and dual shipping (KubeSense + CloudWatch).
What This Provides
- Centralized log collection for ECS Serverless workloads
- Single shipping → KubeSense only
- Dual shipping → KubeSense + CloudWatch simultaneously
- Multiline log handling (stack traces, large logs)
- JSON log lines parsed into fields, with the original
logline retained - ECS metadata enrichment (cluster, task ARN, task definition, container)
- Optional custom tags on every log record (
KUBESENSE_TAGS) - Bounded retries and connection recycling to the KubeSense endpoint
- No agent installation on host
- No code changes in application
Architecture
Application Container
│
│ (stdout / stderr)
▼
FireLens (Fluent Bit)
│
├──▶ KubeSense HTTP Endpoint
└──▶ CloudWatch Logs (optional)Image
public.ecr.aws/p8w3i6u3/kubesense/log-router:1.0.1-0810ec1- Multi-arch (
linux/amd64andlinux/arm64) - Public image, so pulling it needs no registry credentials
note: Pin the exact version tag shown above instead of latest, so your tasks don't change unexpectedly. KUBESENSE_TAGS and host.name require 1.0.1-0810ec1 or newer.
Step 1: Add Log Router as Sidecar
Add the KubeSense log-router container to your ECS task definition. Choose single or dual shipping configuration below.
Single Shipping (KubeSense Only)
{
"name": "log-router",
"image": "public.ecr.aws/p8w3i6u3/kubesense/log-router:1.0.1-0810ec1",
"essential": true,
"firelensConfiguration": {
"type": "fluentbit",
"options": {
"config-file-type": "file",
"config-file-value": "/logDestinations.http.conf",
"enable-ecs-log-metadata": "true"
}
},
"environment": [
{ "name": "KUBESENSE_SERVICE", "value": "<SERVICE_NAME>" },
{ "name": "KUBESENSE_CLUSTER", "value": "<YOUR_CLUSTER_NAME>" },
{ "name": "KUBESENSE_HOST", "value": "<KUBESENSE_ENDPOINT>" },
{ "name": "KUBESENSE_PORT", "value": "<KUBESENSE_PORT>" },
{ "name": "KUBESENSE_URI", "value": "<KUBESENSE_URI>" },
{ "name": "KUBESENSE_TLS", "value": "<KUBESENSE_TLS>" },
{ "name": "KUBESENSE_TAGS", "value": "<OPTIONAL_TAGS>" }
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/<SERVICE_NAME>/log-router",
"awslogs-region": "<AWS_REGION>",
"awslogs-stream-prefix": "ecs",
"awslogs-create-group": "true"
}
}
}Dual Shipping (KubeSense + CloudWatch)
{
"name": "log-router",
"image": "public.ecr.aws/p8w3i6u3/kubesense/log-router:1.0.1-0810ec1",
"essential": true,
"firelensConfiguration": {
"type": "fluentbit",
"options": {
"config-file-type": "file",
"config-file-value": "/logDestinations.http+cloudwatch.conf",
"enable-ecs-log-metadata": "true"
}
},
"environment": [
{ "name": "KUBESENSE_SERVICE", "value": "<SERVICE_NAME>" },
{ "name": "KUBESENSE_CLUSTER", "value": "<YOUR_CLUSTER_NAME>" },
{ "name": "KUBESENSE_HOST", "value": "<KUBESENSE_ENDPOINT>" },
{ "name": "KUBESENSE_PORT", "value": "<KUBESENSE_PORT>" },
{ "name": "KUBESENSE_URI", "value": "<KUBESENSE_URI>" },
{ "name": "KUBESENSE_TLS", "value": "<KUBESENSE_TLS>" },
{ "name": "KUBESENSE_TAGS", "value": "<OPTIONAL_TAGS>" },
{ "name": "AWS_REGION", "value": "<AWS_REGION>" },
{ "name": "CW_LOG_GROUP", "value": "<LOG_GROUP_NAME>" },
{ "name": "CW_STREAM_PREFIX", "value": "<STREAM_PREFIX>" }
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/<SERVICE_NAME>/log-router",
"awslogs-region": "<AWS_REGION>",
"awslogs-stream-prefix": "ecs",
"awslogs-create-group": "true"
}
}
}The logConfiguration on the log router sends the router's own logs to CloudWatch, which is where you look when troubleshooting. It is optional but recommended.
Step 2: Configure Application Containers for Log Routing
Update your application container to use the FireLens log driver:
"logConfiguration": {
"logDriver": "awsfirelens"
}No other options are needed; the destinations come from the log router configuration.
Environment Variable Reference
All placeholder values for the KubeSense endpoint are provided by the KubeSense platform.
Required
| Variable | Description | Example |
|---|---|---|
KUBESENSE_SERVICE | Service/application name shown in KubeSense | payments-api |
KUBESENSE_CLUSTER | Cluster identifier shown in KubeSense | prod-ecs-us-east-1 |
KUBESENSE_HOST | KubeSense log endpoint hostname | provided by KubeSense |
KUBESENSE_PORT | KubeSense log endpoint port | provided by KubeSense |
KUBESENSE_URI | Log endpoint URI path | / |
KUBESENSE_TLS | TLS to the endpoint: On / Off | Off |
Optional
| Variable | Description | Example |
|---|---|---|
KUBESENSE_TAGS | Custom tags added to every log record. Omit it or leave it empty to send no tags | env:prod,team:platform |
Dual Shipping Only
| Variable | Description | Example |
|---|---|---|
AWS_REGION | Region of the CloudWatch log group | us-east-1 |
CW_LOG_GROUP | CloudWatch log group (created automatically if missing) | /ecs/payments-api/app |
CW_STREAM_PREFIX | Prefix for log stream names | payments-api- |
CloudWatch log streams are named <CW_STREAM_PREFIX><container-name>-firelens-<task-id>.
warning: Every variable in the Required table must be set. If one is missing, the log router fails to start (for example Invalid operation Add : kubesense.service).
Custom Tags (KUBESENSE_TAGS)
Use tags to attach your own identifiers, such as environment, team, business unit or cost center, to every log record, so you can filter on them in KubeSense.
- Format: comma-separated
key:valuepairs, without spaces:env:prod,team:platform,bu:payments,costcenter:cc-1042 - Tags are sent in the
kubesense_tagsfield of every record. - Tags are fixed per task definition. To tag services differently, set a different value in each task definition.
- If
KUBESENSE_TAGSis unset or empty, records are sent without akubesense_tagsfield.
Fields Added Automatically
| Field | Source |
|---|---|
host.name | Container hostname (HOSTNAME, set by ECS) |
ecs_cluster | ECS metadata |
ecs_task_arn | ECS metadata |
ecs_task_definition | ECS metadata (family:revision) |
container_name, container_id | ECS metadata |
source | stdout or stderr |
log | Original log line, always retained |
The ecs_* and container_* fields require "enable-ecs-log-metadata": "true", which is included in the examples above.
IAM Permissions
| Role | Needs |
|---|---|
| Task execution role | The standard AmazonECSTaskExecutionRolePolicy, which also covers the router's own awslogs output |
| Task role (single shipping) | Nothing extra |
| Task role (dual shipping) | Write access to the CloudWatch log group (policy below) |
Policy for dual shipping, attached to the task role:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStreams"
],
"Resource": "arn:aws:logs:<AWS_REGION>:<ACCOUNT_ID>:log-group:<LOG_GROUP_NAME>:*"
}
]
}If the log group already exists, you can drop logs:CreateLogGroup.
Verify
- The task is running and all its containers are
RUNNING. - The router's own logs (
/ecs/<SERVICE_NAME>/log-router) show the outputs started and successful sends:[output:http:http.0] worker #0 started [output:http:http.0] <KUBESENSE_ENDPOINT>:<KUBESENSE_PORT>, HTTP status=200 [output:cloudwatch_logs:cloudwatch_logs.1] Created log stream ... # dual shipping only - In KubeSense, search logs for your
KUBESENSE_CLUSTER/KUBESENSE_SERVICE. - For dual shipping, open
CW_LOG_GROUPin CloudWatch and look for streams starting withCW_STREAM_PREFIX.
Troubleshooting
| Symptom | Cause / fix |
|---|---|
Router exits at start with Invalid operation Add : <field> | A required variable is missing. Set every variable in the Required table. |
HTTP status=200 never appears; connection timeouts | No network path to the KubeSense endpoint. Check security group egress, NAT and the host/port values. |
| TLS handshake errors | KUBESENSE_TLS does not match the endpoint. Use On only if KubeSense provided a TLS endpoint. |
CloudWatch AccessDeniedException in the router logs | The task role is missing the IAM policy above, or CW_LOG_GROUP does not match the policy's resource. |