Hi, I am running micro-services using docker compose on a Ubuntu box. Here is example docker compose...
p
Hi, I am running micro-services using docker compose on a Ubuntu box. Here is example docker compose.
Copy code
version: '3.8'
services:
  foo:
    image: ...
    ...

  bar:
    image: ...
    ...
I want to collect logs without changing any micro-service service code. I am using
logspout
to forward log with following command. This is successfully forwarding logs.
Copy code
docker run --net=host --rm --name="logspout" \
        --volume=/var/run/docker.sock:/var/run/docker.sock \
        -e PORT=90 \
        gliderlabs/logspout \
        syslog+tcp://<host>:2255
What is missing is logs are not categorised in SigNoz under their respective service names. How to configure
logspout
to send
service
name along with logs. Or is there any other log collector other than
logsspout
which can send more metadata along with logs.
n
Logspout will give you container name and container.id. You can map container.name to
service.name
or extract it from the body if possible. You can use SigNoz pipelines for that https://signoz.io/docs/logs-pipelines/introduction/ Even vector has support for similar attributes https://vector.dev/docs/reference/configuration/sources/docker_logs/#output-data
p
Thanks @nitya-signoz to point me to pipeline. It solves the problem. I am wondering, is there a way to do it without touching pipeline. For example, datadog agent sends the service name and env automatically without any configuration in datadog pipelines. Perhaps, is there, some other software like
logspout
which sends logs in OTel format directly to SigNoz with appropriate service name and env attribute?
n
For that, you will have to instrument your application, Some have support for autoinstrumentation while others don’t . Here is example for python https://signoz.io/docs/userguide/python-logs-auto-instrumentation/
p
In my case I cannot change app code. Given that it's third party app, like freeswitch server.
n
I dont’ think it’s automatic you have to add labels right ? https://docs.datadoghq.com/containers/docker/log/?tab=containerinstallation#examples
p
It works automatically. Following is the command which we use in production. I have only specified
env
explicitly. The
service
is automatically picked up.
Copy code
docker run -d --name datadog-agent \
  --cgroupns host --pid host \
  -e DD_LOGS_ENABLED=true \
  -e DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true \
  -e DD_ENV=prod \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  -v /var/lib/docker/containers:/var/lib/docker/containers:ro \
  -v /proc/:/host/proc/:ro \
  -v /opt/datadog-agent/run:/opt/datadog-agent/run:rw \
  -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro <http://gcr.io/datadoghq/agent:latest|gcr.io/datadoghq/agent:latest>
Interestingly, service name picked up by datadog is name specified in compose file,
not
the container name. For instance, in following example compose file we are running service
foo
with
replica
of 2. Each container name might be
foo-foo-1
and
foo-foo-2
. But datadog picks up service name as
foo
which makes filtering log easy.
Copy code
version: '3.8'
services:
  foo:
    image: ...
    deploy:
      replica: 2
@nitya-signoz I found out I can write custom adaptor for logspout. I am planing to write adaptor which can directly post to SigNoz HTTP receiver, instead of syslog endpoint as in the doc https://signoz.io/docs/userguide/send-logs-http/ Question: Is the above docs of sending log via http is specific to SigNoz or is it OpenTelemetry standard? The answer will help me to name the custome logspout adaptor appropriately, either as
logspout-signoz
or
logspout-otel
n
Yeah, that is a custom receiver for our distro and not an Otel standard. You can try experimenting with labels ? i.e add labels to and then see how they can be mapped to attributes, it will be simpler I guess.
p
Sure, will try that. I like the philosophy of DRY. If name is already there on docker-compose.yaml repeating it again as label is extra configuration to maintain and remember. I feel auto-configuration will be elegant solution.
@nitya-signoz What payload will populate "Environment" in signoz dashboard? Following is the payload i am using without any luck.
Copy code
[
    {
        "trace_id": "000000000000000018c51935df0b93b9",
        "span_id": "18c51935df0b93b9",
        "trace_flags": 0,
        "severity_text": "error",
        "severity_number": 5,
        "attributes": {
            "method": "GET",
            "path": "/api/users",
            "service": "bar",
            "environment": "env.att"
        },
        "resources": {
            "service.name": "name.with.dot",
            "environment": "res1",
            "namespace": "prod"
        },
        "message": "This is a log line error",
        "environment":"TopE"
    }
]
n
it’s
deployment.environment
, you can use it instead of
environment
p
Just "environment" is getting filtered out and not appearing in log attribute.
n
That shouldn’t happen unless you have added a pipeline or something remove it.
p
Looks like top level "environment" gets added to "attributes". Still its not appearing in environment filters.
n
the sidebar is fixed to
deployment.environment
and not
environment
. Also please make sure that ``deployment.environment` is added to resource attribute and not attribute. Here you have added env to both https://signoz-community.slack.com/archives/C01HWQ1R0BC/p1728024791870019?thread_ts=1727875092.767829&amp;cid=C01HWQ1R0BC
p
Hey @nitya-signoz I have created
logspout-signoz
extension which can collect logs and send it to signoz endpoints. Following are the new features added on top of
logspout
. 1. Direct post to
signoz http
endpoint. So this extension can send more detailed logs. 2. Auto detect service name, so no special configuration needed. a. For JSON logs, picks name from JSON
service
field. b. Otherwise pick service name from
docker-compose
service name. c. Otherwise use docker
image name
as service name 3. Auto detect env name, so no special configuration needed a. For JSON logs, picks name from JSON
env
field. b. Otherwise pick
env
from
logspout-signoz
env variable
ENV
. 4. Auto parse JSON logs. a. Map well known JSON log attribute to appropriate Signoz log payload fields. e.g
level
to
SeverityText
, etc b. Pack other JSON attribute to into
attributes
key of Signoz log payload. I hope this
logspout-signoz
extension will be helpful for others as well, given it provides zero configuration log collection from docker/docker-compose environment. So could you please also add following command to your documentation present at this link so that people could start using it?
Copy code
docker run -d \
        --volume=/var/run/docker.sock:/var/run/docker.sock \
        -e 'SIGNOZ_LOG_ENDPOINT=<http://192.168.0.104:8082>' \
        -e 'ENV=prod' \
        pavanputhra/logspout-signoz \
        <signoz://localhost:8082>
Link to GitHub code: https://github.com/pavanputhra/logspout-signoz.
n
Awesome @Pavan Kumar, I will have a look at this and get back. cc @Ashu
p
Any updates on this @nitya-signoz @Ashu
n
Hey sorry, I will get back on this, was occupied in some other issue.
Hi @pva
Hi @Pavan Kumar would you like to work on a blog post for this, I think it will help others as well as to what was your use case and why you built this and how this helps you out with a tutorial and demo ? @Ashu will help you out
p
Sure @nitya-signoz . Where to host this blog. You have your own site or should I create somewhere. Like Dev.to
n
It will be on the signoz site and then maybe to other places as well. @Ashu will share more details.
p
Cool 🙏🏻
y
Hey @Pavan Kumar, will share the notion space with you to write the blog.
p
Okay 👍 @Yuvraj Singh
y
@Pavan Kumar you can start writing here - https://www.notion.so/signoz/Article-Content-131fcc6bcd198127a898f7f05cc1b973?pvs=4 As discussed, if this looks good then we can publish and continue the collaboration further after a quick onboarding call and agreement. Let me know if any questions. Thanks.
p
Hey @Yuvraj Singh, I have written the blog. Please give your feedback. Thanks.
y
Will revert.
p
Any updates? @Yuvraj Singh
y
p
Thank you for posting! The introduction has a much different style than my usual writing 😄.
n
We have also linked it to our main docs for logs collection from docker https://signoz.io/docs/userguide/collect_docker_log. Thanks for writing this 🙂