Guide to drop logs
Resource attributes provide contextual information about the source of your logs, such as service name, environment, hostname, and deployment details. These attributes enable better filtering, grouping, and correlation of logs in SigNoz. You can set resource attributes at different levels in your observability stack.
Setting Resource Attributes at the Collector Level
The OpenTelemetry Collector provides several processors to add or modify resource attributes for incoming log data.
Using Resource Processor
The resource processor allows you to add, modify, or delete resource attributes. This configuration adds static resource attributes to all logs processed by the collector:
processors:
resource:
attributes:
- key: service.name
value: "my-log-service"
action: upsert
- key: deployment.environment
value: "production"
action: insert
- key: host.name
from_attribute: "hostname"
action: upsert
service:
pipelines:
logs:
receivers: [otlp, filelog]
processors: [resource, batch]
exporters: [clickhouselogsexporter]
This configuration adds a service name and environment to all logs, and copies the hostname from an existing attribute. The action
parameter determines how the attribute is handled (insert, update, or upsert).
Using Resource Detection Processor
The resource detection processor automatically detects resource information from the host environment. This processor can detect attributes like hostname, OS information, cloud provider details, and Kubernetes metadata:
processors:
resourcedetection:
detectors: [env, host, system, docker, k8snode]
system:
hostname_sources: ["os"]
timeout: 5s
service:
pipelines:
logs:
receivers: [otlp]
processors: [resourcedetection, batch]
exporters: [clickhouselogsexporter]
This processor automatically adds resource attributes by detecting information from the environment, host system, Docker containers, and Kubernetes nodes. The timeout
parameter controls how long the processor waits for detection to complete.
Setting Resource Attributes at the SDK Level
You can configure resource attributes directly in your application code using OpenTelemetry SDKs. This approach gives you fine-grained control over the attributes for each service.
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { NodeSDK } from '@opentelemetry/sdk-node';
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';
// Create a resource with custom attributes
const resource = new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'my-log-service',
[SemanticResourceAttributes.SERVICE_VERSION]: '1.0.0',
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: 'production',
'custom.team': 'backend-team',
'custom.region': 'us-west-2'
});
// Initialize the SDK with the resource
const sdk = new NodeSDK({
resource: resource,
logRecordProcessor: new BatchLogRecordProcessor(
new OTLPLogExporter({
url: 'http://localhost:4318/v1/logs',
})
),
});
sdk.start();
This configuration creates a resource with both standard semantic conventions (service name, version, environment) and custom attributes (team, region). These attributes will be attached to all logs generated by this service.
Using Environment Variables
You can set resource attributes using environment variables, which is particularly useful for containerized deployments and CI/CD pipelines:
# Set multiple resource attributes in a single environment variable
export OTEL_RESOURCE_ATTRIBUTES="service.name=my-log-service,service.version=1.0.0,deployment.environment=production,custom.team=backend"
# Or set service name separately
export OTEL_SERVICE_NAME="my-log-service"
# Set service version
export OTEL_SERVICE_VERSION="1.0.0"
These environment variables are automatically picked up by OpenTelemetry SDKs and applied to all telemetry data, including logs. This approach is ideal for deployment scenarios where you want to configure resource attributes without modifying code.
Using Kubernetes with OpenTelemetry Operator
When deploying applications in Kubernetes, you can use the OpenTelemetry Operator to automatically inject resource attributes:
apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
name: my-instrumentation
namespace: default
spec:
resource:
addK8sUIDAttributes: true
resourceAttributes:
deployment.environment: "production"
custom.team: "backend-team"
env:
- name: OTEL_RESOURCE_ATTRIBUTES
value: "service.version=1.0.0"
This configuration automatically adds Kubernetes-specific resource attributes (like pod name, namespace, deployment name) and custom attributes to all instrumented applications in the cluster. The addK8sUIDAttributes
option includes unique identifiers that help correlate logs with Kubernetes resources.
To apply this instrumentation to a deployment, add the following annotation:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-application
spec:
template:
metadata:
annotations:
instrumentation.opentelemetry.io/inject-sdk: "my-instrumentation"
spec:
containers:
- name: app
image: my-app:latest
This approach ensures that all logs from your Kubernetes applications include consistent resource attributes for filtering and correlation in SigNoz.
Last updated: July 18, 2025