Logs
There are two ways to send logs from ECS tasks on EC2 to KubeSense:
| Option 1: FireLens log router | Option 2: OpenTelemetry (OTLP) | |
|---|---|---|
| What it collects | Everything the container writes to stdout and stderr | Log records your application emits through the OpenTelemetry SDK |
| Runs as | A log-router sidecar in each task | The daemon collector you already run for Traces & Metrics |
| Code changes | None | The application must be instrumented with OpenTelemetry |
| Trace context | No | Yes, the SDK adds the trace and span ID of the active request to each record |
| CloudWatch copy | Optional (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
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. |
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>:30055note: 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
- The daemon collector from Traces & Metrics running on every instance, and the application sending traces to it (Step 5: Configure Collector Endpoint).
- The aggregator's OTLP log listener turned on (
aggregator.sources.otel.enabled: true) and port30055reachable from the EC2 instances through an internal load balancer. See External Service Logs & Metrics → Expose the endpoints.
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:
| Language | Setting |
|---|---|
| Java (agent) | None. Logback, Log4j and java.util.logging are captured by default |
| Python | OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true (captures the standard logging module) |
| Others | See 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
- In the collector's CloudWatch log group (
/ecs/otel-collector), check for export errors fromotlphttp/kubesense-logs. - In KubeSense, open the log explorer, select your cluster and filter on
workload= yourOTEL_SERVICE_NAME.
Troubleshooting
| Symptom | Cause / fix |
|---|---|
connection refused or timeouts to port 30055 in the collector logs | The 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 errors | The application isn't exporting logs. Check OTEL_LOGS_EXPORTER=otlp and the language-specific setting above. |
| Logs arrive under no cluster, or not at all | kubesense.env_type is k8s or lambda, or kubesense.cluster is missing. Set them in the collector's resource processor. |
| Logs arrive twice | The container also uses the FireLens log driver. See Send each container's logs one way above. |