Skip to Content
KubeSense

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 log line 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/amd64 and linux/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

VariableDescriptionExample
KUBESENSE_SERVICEService/application name shown in KubeSensepayments-api
KUBESENSE_CLUSTERCluster identifier shown in KubeSenseprod-ecs-us-east-1
KUBESENSE_HOSTKubeSense log endpoint hostnameprovided by KubeSense
KUBESENSE_PORTKubeSense log endpoint portprovided by KubeSense
KUBESENSE_URILog endpoint URI path/
KUBESENSE_TLSTLS to the endpoint: On / OffOff

Optional

VariableDescriptionExample
KUBESENSE_TAGSCustom tags added to every log record. Omit it or leave it empty to send no tagsenv:prod,team:platform

Dual Shipping Only

VariableDescriptionExample
AWS_REGIONRegion of the CloudWatch log groupus-east-1
CW_LOG_GROUPCloudWatch log group (created automatically if missing)/ecs/payments-api/app
CW_STREAM_PREFIXPrefix for log stream namespayments-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:value pairs, without spaces:
    env:prod,team:platform,bu:payments,costcenter:cc-1042
  • Tags are sent in the kubesense_tags field of every record.
  • Tags are fixed per task definition. To tag services differently, set a different value in each task definition.
  • If KUBESENSE_TAGS is unset or empty, records are sent without a kubesense_tags field.

Fields Added Automatically

FieldSource
host.nameContainer hostname (HOSTNAME, set by ECS)
ecs_clusterECS metadata
ecs_task_arnECS metadata
ecs_task_definitionECS metadata (family:revision)
container_name, container_idECS metadata
sourcestdout or stderr
logOriginal log line, always retained

The ecs_* and container_* fields require "enable-ecs-log-metadata": "true", which is included in the examples above.

IAM Permissions

RoleNeeds
Task execution roleThe 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

  1. The task is running and all its containers are RUNNING.
  2. 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
  3. In KubeSense, search logs for your KUBESENSE_CLUSTER / KUBESENSE_SERVICE.
  4. For dual shipping, open CW_LOG_GROUP in CloudWatch and look for streams starting with CW_STREAM_PREFIX.

Troubleshooting

SymptomCause / 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 timeoutsNo network path to the KubeSense endpoint. Check security group egress, NAT and the host/port values.
TLS handshake errorsKUBESENSE_TLS does not match the endpoint. Use On only if KubeSense provided a TLS endpoint.
CloudWatch AccessDeniedException in the router logsThe task role is missing the IAM policy above, or CW_LOG_GROUP does not match the policy's resource.

On this page