# Custom Log ingestion Dynatrace

**URL:** <https://community.dynatrace.com/t/custom-log-ingestion-dynatrace/46155>\
**Category:** DQL\
**Tags:** dql, dpl, dynatrace-api, logs\
**Created:** [June 17, 2024, 2:59pm UTC](https://community.dynatrace.com/t/custom-log-ingestion-dynatrace/46155 "2024-06-17T14:59:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piermarco](https://avatars.discourse-cdn.com/v4/letter/p/8c91f0/32.png) [@Piermarco](https://community.dynatrace.com/u/Piermarco)\
**Post date:** [June 17, 2024, 2:59pm UTC](https://community.dynatrace.com/t/custom-log-ingestion-dynatrace/46155/1 "2024-06-17T14:59:37Z")

</div>

Hi all,

My team and I have successfully processed a custom JSON and sent it to Dynatrace using the log ingestion POST API. We need this data for offline monitoring of an application.

We are now starting to use GRAIL to create dashboards. However, we’ve encountered a problem: when the data is input into log monitoring, even the numbers in the JSON are recognized as strings.

 ![Captured POST ingestion only string detection](https://global.discourse-cdn.com/dynatrace/original/2X/c/cbc8221ebd9b8c022f0992ce90821d0422d03893.png)

This is the passed json example:

```markup
{
        "userAgent": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "language": "it-IT",
        "cookieEnabled": true,
        "name": "xxxxxxx",
        "timestamp": 1718614669096,
        "session": "1718614523449",
        "userName": "xxxxxx",
        "online": false,
        "deviceMemory": 8,
        "hardwareConcurrency": 8,
        "connectionDownlink": 0,
        "connectionType": "4g",
        "connectionRoundTripTime": 0,
        "duration": 1017
    }

```

To address this problem, we could either:

1. Modify the data during processing by using built-in Dynatrace functions like `toLong(…)` or `toDuration(…)`.
2. Or parse it using DPL with the parse syntax `JSON:ingest`. And do not seems also to work correctly as we expected (only recognise duration).  
 ![parsing using parse commad for json](https://global.discourse-cdn.com/dynatrace/original/2X/2/25d0a57a4139a551aeee3ecd4b9448e9f74a9e21.png)

Our question concerns performance. Each time we use these commands to change the field type or parse our JSON with DPL, it impacts performance. Is there a way to have our JSON data directly arrive with the correct field types, so we don’t have to modify them later and just use them?

Thank you for your help.

Piermarco

---

<div class="post-metadata">

**Author:** ![jaume\_reverte](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/jaume_reverte/32/1479_2.png) [@jaume\_reverte](https://community.dynatrace.com/u/jaume_reverte)\
**Post date:** [June 18, 2024, 7:50am UTC](https://community.dynatrace.com/t/custom-log-ingestion-dynatrace/46155/2 "2024-06-18T07:50:06Z")

</div>

Hello,

My recommendation is to create a log processing rule. There is no better way to ensure that the data is captured in the form you want.

This way, the data inside Dynatrace is already the correct one, so you don’t need to make changes later.

Hope this helps. Wish you good monitoring!

---

<div class="post-metadata">

**Author:** ![Piermarco](https://avatars.discourse-cdn.com/v4/letter/p/8c91f0/32.png) [@Piermarco](https://community.dynatrace.com/u/Piermarco)\
**Post date:** [June 18, 2024, 8:18am UTC](https://community.dynatrace.com/t/custom-log-ingestion-dynatrace/46155/3 "2024-06-18T08:18:20Z")

</div>

Hi,

Where I can find it ?

Thanks for the replay.

---

<div class="post-metadata">

**Author:** ![jaume\_reverte](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/jaume_reverte/32/1479_2.png) [@jaume\_reverte](https://community.dynatrace.com/u/jaume_reverte)\
**Post date:** [June 18, 2024, 8:23am UTC](https://community.dynatrace.com/t/custom-log-ingestion-dynatrace/46155/4 "2024-06-18T08:23:58Z")

</div>

Hello,

[Here](https://docs.dynatrace.com/docs/shortlink/lma-log-processing-examples#lpexample3) is an example of what you want to perform and the [documentation](https://docs.dynatrace.com/docs/observe-and-explore/logs/lma-log-processing#log-processing) page.

---

<div class="post-metadata">

**Author:** ![Piermarco](https://avatars.discourse-cdn.com/v4/letter/p/8c91f0/32.png) [@Piermarco](https://community.dynatrace.com/u/Piermarco)\
**Post date:** [June 18, 2024, 1:31pm UTC](https://community.dynatrace.com/t/custom-log-ingestion-dynatrace/46155/5 "2024-06-18T13:31:32Z")

</div>

Hi,&nbsp;  
As you suggested to me I have create a custom rule to capture the logs in&nbsp;Settings&nbsp;\>&nbsp;Log Monitoring&nbsp;\> Processing.  
This is the fetch log:

 ![fetch log](https://global.discourse-cdn.com/dynatrace/original/2X/6/630ff8d9568af94758d8eaa9f7687a3d85af7cc3.png)

So I have created a new processig rule:

1. I have use the same matcher in the log ingester

```javascript
matchesValue(TagDynatarce, "Offline_log_ingestion")​

```

2. And use this rule to pass my parameter with the correct type as I want:

```javascript
USING(
    IN userAgent: STRING?,
    IN language: STRING?, 
    IN cookieEnabled: BOOLEAN?,
    INOUT timestampX: TIMESTAMP,
    IN session: STRING,
    IN online: BOOLEAN?,
    IN deviceMemory: INTEGER?,
    IN hardwareConcurrency: INTEGER?,
    IN connectionDownlink: INTEGER?,
    IN connectionType: STRING,
    IN connectionRoundTripTime: INTEGER?,
    INOUT durations: INTEGER,
    INOUT name:STRING,
    INOUT userName:STRING, 
    INOUT TagDynatarce:STRING
)
| FIELDS_RENAME(
    duration: durations,
    actionName: name,
    timestamp: timestampX
)
| FIELDS_REMOVE(durations, name, timestampX, TagDynatarce)​

```

3. After I test it and it is able to find and change the content.&nbsp;

 ![Test the rule](https://global.discourse-cdn.com/dynatrace/original/3X/a/2/a203310150538a188334104e040b080b6ee392cc.png)

Now what I expect after I have defined this rule that in GRAL the json is correctly ingest and with the correct type of field, but it does not work.

 ![GRAIL](https://global.discourse-cdn.com/dynatrace/original/3X/6/f/6f9e7a85cf3139831244f047fa3d702fe38a7d48.png)

Am I doing something wrong ?

Thanks for the time

---

<div class="post-metadata">

**Author:** ![jaume\_reverte](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/jaume_reverte/32/1479_2.png) [@jaume\_reverte](https://community.dynatrace.com/u/jaume_reverte)\
**Post date:** [June 19, 2024, 6:18am UTC](https://community.dynatrace.com/t/custom-log-ingestion-dynatrace/46155/6 "2024-06-19T06:18:58Z")

</div>

Hello,

I don’t see any error.

I see in the last photo that you have one new entry with the correct values. This rule only applies to new ingested logs, not to old logs.
