https://signoz.io logo
#support
Title
# support
t

Tarek Esmail

08/16/2023, 11:27 AM
Hi, I want to add labels to logs in signoz, i have JSON body logs and i want to catch key from this JSON to be label like container_name and cluster_name, i'm using kubernetes signoz
n

nitya-signoz

08/16/2023, 11:30 AM
t

Tarek Esmail

08/16/2023, 11:47 AM
i'm using this file https://github.com/SigNoz/charts/blob/main/charts/k8s-infra/values.yaml to ship the logs to signoz I have key under body json called
Copy code
tenantId
how i can use this one as label Can you help me on that ?
t

Tarek Esmail

08/16/2023, 11:48 AM
I will modify the default one, but what's the change should be in this case
Copy code
logstransform/internal:
        operators:
        - if: '"trace_id" in attributes or "span_id" in attributes'
          output: remove_trace_id
          span_id:
            parse_from: attributes.span_id
          trace_id:
            parse_from: attributes.trace_id
          type: trace_parser
        - if: '"traceId" in attributes or "spanId" in attributes'
          output: remove_traceId
          span_id:
            parse_from: attributes.spanId
          trace_id:
            parse_from: attributes.traceId
          type: trace_parser
        - field: attributes.traceId
          id: remove_traceId
          if: '"traceId" in attributes'
          output: remove_spanId
          type: remove
        - field: attributes.spanId
          id: remove_spanId
          if: '"spanId" in attributes'
          type: remove
        - field: attributes.trace_id
          id: remove_trace_id
          if: '"trace_id" in attributes'
          output: remove_span_id
          type: remove
        - field: attributes.span_id
          id: remove_span_id
          if: '"span_id" in attributes'
          type: remove
the content of logstransform/internal
n

nitya-signoz

08/16/2023, 11:50 AM
It’s better to create a new one for parsing your logs. If you need help in that you will have to share your logs you see in UI.
t

Tarek Esmail

08/16/2023, 11:51 AM
this is the log json
i want to make tenantId as label
what i should do in this case
@nitya-signoz
n

nitya-signoz

08/16/2023, 12:02 PM
Copy code
otelCollector:
  config:
    processors:
      logstransform/parse_tid:
        operators:
          - default: noop
            id: router_signoz
            type: router
            routes:
              - expr: 'body matches ".*\\\"tenantId\\\":\\\"(?P<tenantId>\\w+)\\\""'
                output: extract_tenantId
          - id: extract_tenantId
            type: regex_parser
            regex: '.*\"tenantId\":\"(?P<tenantId>\w+)\"'
            parse_from: body
            output: noop
          - id: noop
            type: noop
    service:
      pipelines:
        logs:
          receivers: [otlp]
          processors: [logstransform/parse_tid, logstransform/internal, batch]
          exporters: [clickhouselogsexporter]
t

Tarek Esmail

08/16/2023, 12:03 PM
testing it, thank you
i tested it but it's still not appeared in the new logs
even this is not appeared in INTERESTING FIELDS
i'm sorry i found something, it's body inside body
how i can do it in this case
the key tenant id is
body > body > tenant id
s

Shivanshu Raj Shrivastava

08/16/2023, 12:14 PM
can you share a complete json log?
t

Tarek Esmail

08/16/2023, 12:14 PM
one moment
Copy code
{
  "timestamp": 1692187765868840000,
  "id": "2U48JQCA8Ob7k3tYQZZouyDNA6A",
  "trace_id": "",
  "span_id": "",
  "trace_flags": 0,
  "severity_text": "",
  "severity_number": 0,
  "body": "{\"name\":\"xxx\",\"hostname\":\"xxx-xxx-644d656d99-c24x5\",\"pid\":17,\"component\":\"nodeWorkerSQS\",\"level\":\"INFO\",\"messageType\":\"integration_process\",\"body\":{\"type\":\"integration_process\",\"integrationType\":\"twitter\",\"tenantId\":\"xxxx\",\"onboarding\":false,\"integrationId\":\"xxxx\",\"retryStreams\":[{\"id\":\"xxxxx\",\"retryCount\":1,\"stream\":{\"value\":\"mentions\",\"metadata\":{\"page\":\"\"}}}],\"remainingStreams\":[{\"value\":\"followers\",\"metadata\":{\"page\":\"\"}}]},\"msg\":\"Sending xxx sqs message!\",\"time\":\"2023-08-16T12:09:25.868Z\",\"v\":0}",
  "resources_string": {
    "k8s_cluster_name": "xxxx",
    "k8s_container_name": "xxx",
    "k8s_container_restart_count": "0",
    "k8s_deployment_name": "xxx-xxx",
    "k8s_namespace_name": "default",
    "k8s_node_name": "xxxxx",
    "k8s_pod_name": "xxxx",
    "k8s_pod_start_time": "2023-08-14 10:08:54 +0000 UTC",
    "k8s_pod_uid": "b1e86f6d-42b6-46f9-903c-d5269a6b44a9"
  },
  "attributes_string": {
    "log_file_path": "/var/log/pods/default_xxx-xxx-644d656d99-c24x5_b1e86f6d-42b6-46f9-903c-d5269a6b44a9/xxx/0.log",
    "log_iostream": "stdout",
    "logtag": "F",
    "time": "2023-08-16T12:09:25.868839814Z"
  },
  "attributes_int": {},
  "attributes_float": {}
}
this is the complete log f
s

Shivanshu Raj Shrivastava

08/16/2023, 12:17 PM
Okay, if I look at body, it is
Copy code
{
  "name": "xxx",
  "hostname": "xxx-xxx-644d656d99-c24x5",
  "pid": 17,
  "component": "nodeWorkerSQS",
  "level": "INFO",
  "messageType": "integration_process",
  "body": {
    "type": "integration_process",
    "integrationType": "twitter",
    "tenantId": "xxxx",
    "onboarding": false,
    "integrationId": "xxxx",
    "retryStreams": [
      {
        "id": "xxxxx",
        "retryCount": 1,
        "stream": {
          "value": "mentions",
          "metadata": {
            "page": ""
          }
        }
      }
    ],
    "remainingStreams": [
      {
        "value": "followers",
        "metadata": {
          "page": ""
        }
      }
    ]
  },
  "msg": "Sending xxx sqs message!",
  "time": "2023-08-16T12:09:25.868Z",
  "v": 0
}
t

Tarek Esmail

08/16/2023, 12:18 PM
Yes
t

Tarek Esmail

08/16/2023, 12:21 PM
@nitya-signoz can you edit the example to shared above
s

Shivanshu Raj Shrivastava

08/16/2023, 12:30 PM
Copy code
otelCollector:
  config:
    processors:
      logstransform/parse_tid:
        operators:
          - type: json_parser
            id: parser-docker
            output: extract_metadata_from_filepath
            timestamp:
              parse_from: body.time
              layout: '%%Y-%%m-%%dT%%H:%%M:%%S.%%LZ'
    service:
      pipelines:
        logs:
          receivers: [otlp]
          processors: [logstransform/parse_tid, logstransform/internal, batch]
          exporters: [clickhouselogsexporter]
With this, you should see be able to see an attribute
body.body.tenantId
with value as your tanantId
if you want to rename the attribute, you can use
Copy code
otelCollector:
  config:
    processors:
      logstransform/parse_tid:
        operators:
          - type: json_parser
            id: parser-docker
            output: extract_metadata_from_filepath
            timestamp:
              parse_from: body.time
              layout: '%%Y-%%m-%%dT%%H:%%M:%%S.%%LZ'
          - type: move
            from: body.body.tenantId
            to: attributes["k8s.tenantId"]
    service:
      pipelines:
        logs:
          receivers: [otlp]
          processors: [logstransform/parse_tid, logstransform/internal, batch]
          exporters: [clickhouselogsexporter]
t

Tarek Esmail

08/16/2023, 8:47 PM
Copy code
2023/08/16 12:37:40 application run finished with error: failed to build pipelines: failed to create "logstransform/parse_tid" processor, in pipeline "logs": operator 'extract_metadata_from_filepath' does not exist: {"operator_id":"parser-docker"}
n

nitya-signoz

08/17/2023, 3:35 AM
Copy code
otelCollector:
  config:
    processors:
      logstransform/parse_tid:
        operators:
          - default: noop
            id: router_signoz
            routes:
              - expr: 'body matches "^{.*}$"'
                output: parse_json
            type: router
          # json parser
          - id: parse_json
            type: json_parser
            parse_from: body
            parse_to: attributes.temp
            output: move_tenantId
          - type: move
            id: move_tenantId
            from: attributes.temp.body.tenantId
            to: attributes.tenantId
            if: '"body" in attributes.temp and "tenantId" in attributes.temp.body'
            output: remove_temp
          - type: remove
            id: remove_temp
            field: attributes.temp
            output: noop
          - id: noop
            type: noop
    service:
      pipelines:
        logs:
          receivers: [otlp]
          processors: [logstransform/parse_tid, logstransform/internal, batch]
          exporters: [clickhouselogsexporter]
t

Tarek Esmail

08/17/2023, 6:52 AM
working like charm, thank you, i have another question what if i want to add another field, should i add new processor or can one processor do both
n

nitya-signoz

08/17/2023, 7:03 AM
Add one more operator like this in the above config.
Copy code
- type: move
            id: move_tenantId
            from: attributes.temp.body.tenantId
            to: attributes.tenantId
            if: '"body" in attributes.temp and "tenantId" in attributes.temp.body'
            output: remove_temp
4 Views