Splunk Enterprise

log different field based on sourcetype

John_Zheng
Engager

Hi, I am using splunk otel,  send log to splunk enterprise.For different sourcetype, I want to do different thing, like add field, remove fields

can you guide me, thanks a lot.

 

For below, it work.

```
      transform/istio-proxy:
        error_mode: ignore
        log_statements:
        - context: log
          statements:
          - set(attributes["johnaddkey"], "johnaddvalue")

```

 

For below, it does not work.

```
      transform/istio-proxy:
        error_mode: ignore
        log_statements:
        - context: log
          statements:
          - set(attributes["johntestwhere"], "johnvaluewhere") where attributes["sourcetype"]
            == "kube:container:istio-proxy"

```

For below, it does not work.

```
      transform/istio-proxy:
        error_mode: ignore
        log_statements:
        - context: log
          conditions:
          - attributes["sourcetype"] == "kube:container:istio-proxy"
          statements:
          - set(attributes["johnaddkeyc"], "johnaddvaluec") 

```

 

John_Zheng_0-1734993721840.png

 

Labels (1)
0 Karma
1 Solution

John_Zheng
Engager

Ok, finically I figured out by myself.

Here is correct code

```

transform/istio-proxy:
error_mode: ignore
log_statements:
- context: log
statements:
- keep_keys(resource.attributes, ["_time", "cluster_codename", "host.name", "com.splunk.index", "splunk_server", "com.splunk.source", "com.splunk.sourcetype"]) where resource.attributes["com.splunk.sourcetype"]
== "kube:container:istio-proxy"
- delete_key(attributes, "logtag") where resource.attributes["com.splunk.sourcetype"]
== "kube:container:istio-proxy"

``` 

The point is should use resource.attributes["com.splunk.sourcetype"]

instead of  attributes["sourcetype"] 

View solution in original post

0 Karma

John_Zheng
Engager

Ok, finically I figured out by myself.

Here is correct code

```

transform/istio-proxy:
error_mode: ignore
log_statements:
- context: log
statements:
- keep_keys(resource.attributes, ["_time", "cluster_codename", "host.name", "com.splunk.index", "splunk_server", "com.splunk.source", "com.splunk.sourcetype"]) where resource.attributes["com.splunk.sourcetype"]
== "kube:container:istio-proxy"
- delete_key(attributes, "logtag") where resource.attributes["com.splunk.sourcetype"]
== "kube:container:istio-proxy"

``` 

The point is should use resource.attributes["com.splunk.sourcetype"]

instead of  attributes["sourcetype"] 

0 Karma
Get Updates on the Splunk Community!

Developer Spotlight with Brett Adams

In our third Spotlight feature, we're excited to shine a light on Brett—a Splunk consultant, innovative ...

Index This | What can you do to make 55,555 equal 500?

April 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...

Say goodbye to manually analyzing phishing and malware threats with Splunk Attack ...

In today’s evolving threat landscape, we understand you’re constantly bombarded with phishing and malware ...