Skip to Content
KubeSense

Logs

There are two ways to send logs from ECS tasks on EC2 to KubeSense:

Option 1: FireLens log routerOption 2: OpenTelemetry (OTLP)
What it collectsEverything the container writes to stdout and stderrLog records your application emits through the OpenTelemetry SDK
Runs asA log-router sidecar in each taskThe daemon collector you already run for Traces & Metrics
Code changesNoneThe application must be instrumented with OpenTelemetry
Trace contextNoYes, the SDK adds the trace and span ID of the active request to each record
CloudWatch copyOptional (dual shipping)No

Use Option 1 to capture all container output without touching the application. Use Option 2 if the application is already instrumented for traces and you want its logs to carry the trace context.

Option 1: FireLens Log Router

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 EC2 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.

Option 2: OpenTelemetry (OTLP)

Your instrumented application exports its logs over OTLP to the daemon collector on the same EC2 instance, the same way it already exports traces. The collector forwards them to the KubeSense aggregator.

Application (OpenTelemetry SDK)
        │  OTLP → <INSTANCE_IP>:4318
        ▼
OpenTelemetry Collector (daemon, one per EC2 instance)
        ├──▶ Traces → <KUBESENSE_ENDPOINT>:33443
        └──▶ Logs   → <KUBESENSE_LOGS_ENDPOINT>:30055

note: This option sends only what the application logs through the OpenTelemetry SDK, not raw stdout and stderr. Output from anything else in the container, such as the runtime itself or a startup script, is not collected. Use Option 1 for that.

Prerequisites

Step 1: Add a logs pipeline to the collector

Add the exporter and the logs pipeline below to the collector configuration in Parameter Store (/ecs/kubesense/otelcol-daemon.yaml). Keep everything that is already there. The otlp receiver and the processors are the ones the Traces & Metrics configuration already defines.

exporters:
  # Logs
  otlphttp/kubesense-logs:
    logs_endpoint: http://<KUBESENSE_LOGS_ENDPOINT>:30055/v1/logs
    timeout: 30s
    tls:
      insecure: true

service:
  pipelines:
    # Logs
    logs:
      receivers: [otlp]
      processors:
        - memory_limiter
        - resourcedetection
        - resource
        - batch
      exporters: [otlphttp/kubesense-logs]
  • <KUBESENSE_LOGS_ENDPOINT>: the load balancer in front of the KubeSense aggregator (provided by the KubeSense platform). It is usually a different address from the trace endpoint.

The resource processor sets kubesense.cluster and kubesense.env_type on the logs as well as the traces. Set kubesense.env_type to ecs: the aggregator does not attribute logs whose env_type is k8s or lambda.

Then restart the daemon service (Update service → Force new deployment) so the collectors read the new configuration.

Step 2: Turn on log export in the application

Add these to the application container's environment, alongside the variables from Step 5. The OTEL_EXPORTER_OTLP_ENDPOINT set there already points at the collector, so logs go to the same place as traces.

{
  "name": "OTEL_LOGS_EXPORTER",
  "value": "otlp"
}

OTEL_SERVICE_NAME is required for logs. It becomes the workload in the log explorer.

Some languages need one more setting before the SDK picks up application logs:

LanguageSetting
Java (agent)None. Logback, Log4j and java.util.logging are captured by default
PythonOTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true (captures the standard logging module)
OthersSee your language's page under Instrumentation

Send each container's logs one way: If the same container also uses the FireLens log driver from Option 1, its logs arrive twice. Use one option per container.

Verify

  1. In the collector's CloudWatch log group (/ecs/otel-collector), check for export errors from otlphttp/kubesense-logs.
  2. In KubeSense, open the log explorer, select your cluster and filter on workload = your OTEL_SERVICE_NAME.

Troubleshooting

SymptomCause / fix
connection refused or timeouts to port 30055 in the collector logsThe aggregator's OTLP source is not enabled, or port 30055 is not reachable from the instances. Check the load balancer and security groups.
Traces arrive but logs do not, with no export errorsThe application isn't exporting logs. Check OTEL_LOGS_EXPORTER=otlp and the language-specific setting above.
Logs arrive under no cluster, or not at allkubesense.env_type is k8s or lambda, or kubesense.cluster is missing. Set them in the collector's resource processor.
Logs arrive twiceThe container also uses the FireLens log driver. See Send each container's logs one way above.

On this page