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!

Index This | What did the zero say to the eight?

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

Splunk Observability Cloud's AI Assistant in Action Series: Onboarding New Hires & ...

This is the fifth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Now Playing: Splunk Education Summer Learning Premieres

It’s premiere season, and Splunk Education is rolling out new releases you won’t want to miss. Whether you’re ...